diff options
Diffstat (limited to 'core')
237 files changed, 0 insertions, 5751 deletions
diff --git a/core/array.cpp b/core/array.cpp index 7c0129ffde..75efe8f8ff 100644 --- a/core/array.cpp +++ b/core/array.cpp @@ -46,7 +46,6 @@ public: }; void Array::_ref(const Array &p_from) const { - ArrayPrivate *_fp = p_from._p; ERR_FAIL_COND(!_fp); // should NOT happen. @@ -64,7 +63,6 @@ void Array::_ref(const Array &p_from) const { } void Array::_unref() const { - if (!_p) return; @@ -75,46 +73,37 @@ void Array::_unref() const { } Variant &Array::operator[](int p_idx) { - return _p->array.write[p_idx]; } const Variant &Array::operator[](int p_idx) const { - return _p->array[p_idx]; } int Array::size() const { - return _p->array.size(); } bool Array::empty() const { - return _p->array.empty(); } void Array::clear() { - _p->array.clear(); } bool Array::operator==(const Array &p_array) const { - return _p == p_array._p; } uint32_t Array::hash() const { - uint32_t h = hash_djb2_one_32(0); for (int i = 0; i < _p->array.size(); i++) { - h = hash_djb2_one_32(_p->array[i].hash(), h); } return h; } void Array::_assign(const Array &p_array) { - if (_p->typed.type != Variant::OBJECT && _p->typed.type == p_array._p->typed.type) { //same type or untyped, just reference, shuold be fine _ref(p_array); @@ -163,24 +152,20 @@ void Array::operator=(const Array &p_array) { _assign(p_array); } void Array::push_back(const Variant &p_value) { - ERR_FAIL_COND(!_p->typed.validate(p_value, "push_back")); _p->array.push_back(p_value); } Error Array::resize(int p_new_size) { - return _p->array.resize(p_new_size); } void Array::insert(int p_pos, const Variant &p_value) { - ERR_FAIL_COND(!_p->typed.validate(p_value, "insert")); _p->array.insert(p_pos, p_value); } void Array::erase(const Variant &p_value) { - ERR_FAIL_COND(!_p->typed.validate(p_value, "erase")); _p->array.erase(p_value); } @@ -196,13 +181,11 @@ Variant Array::back() const { } int Array::find(const Variant &p_value, int p_from) const { - ERR_FAIL_COND_V(!_p->typed.validate(p_value, "find"), -1); return _p->array.find(p_value, p_from); } int Array::rfind(const Variant &p_value, int p_from) const { - if (_p->array.size() == 0) return -1; ERR_FAIL_COND_V(!_p->typed.validate(p_value, "rfind"), -1); @@ -217,7 +200,6 @@ int Array::rfind(const Variant &p_value, int p_from) const { } for (int i = p_from; i >= 0; i--) { - if (_p->array[i] == p_value) { return i; } @@ -227,20 +209,17 @@ int Array::rfind(const Variant &p_value, int p_from) const { } int Array::find_last(const Variant &p_value) const { - ERR_FAIL_COND_V(!_p->typed.validate(p_value, "find_last"), -1); return rfind(p_value); } int Array::count(const Variant &p_value) const { - ERR_FAIL_COND_V(!_p->typed.validate(p_value, "count"), 0); if (_p->array.size() == 0) return 0; int amount = 0; for (int i = 0; i < _p->array.size(); i++) { - if (_p->array[i] == p_value) { amount++; } @@ -256,24 +235,20 @@ bool Array::has(const Variant &p_value) const { } void Array::remove(int p_pos) { - _p->array.remove(p_pos); } void Array::set(int p_idx, const Variant &p_value) { - ERR_FAIL_COND(!_p->typed.validate(p_value, "set")); operator[](p_idx) = p_value; } const Variant &Array::get(int p_idx) const { - return operator[](p_idx); } Array Array::duplicate(bool p_deep) const { - Array new_arr; int element_count = size(); new_arr.resize(element_count); @@ -286,7 +261,6 @@ Array Array::duplicate(bool p_deep) const { } int Array::_clamp_slice_index(int p_index) const { - int arr_size = size(); int fixed_index = CLAMP(p_index, -arr_size, arr_size - 1); if (fixed_index < 0) { @@ -335,7 +309,6 @@ Array Array::slice(int p_begin, int p_end, int p_step, bool p_deep) const { // l } struct _ArrayVariantSort { - _FORCE_INLINE_ bool operator()(const Variant &p_l, const Variant &p_r) const { bool valid = false; Variant res; @@ -347,18 +320,15 @@ struct _ArrayVariantSort { }; Array &Array::sort() { - _p->array.sort_custom<_ArrayVariantSort>(); return *this; } struct _ArrayVariantSortCustom { - Object *obj; StringName func; _FORCE_INLINE_ bool operator()(const Variant &p_l, const Variant &p_r) const { - const Variant *args[2] = { &p_l, &p_r }; Callable::CallError err; bool res = obj->call(func, args, 2, err); @@ -368,7 +338,6 @@ struct _ArrayVariantSortCustom { } }; Array &Array::sort_custom(Object *p_obj, const StringName &p_function) { - ERR_FAIL_NULL_V(p_obj, *this); SortArray<Variant, _ArrayVariantSortCustom, true> avs; @@ -379,7 +348,6 @@ Array &Array::sort_custom(Object *p_obj, const StringName &p_function) { } void Array::shuffle() { - const int n = _p->array.size(); if (n < 2) return; @@ -394,7 +362,6 @@ void Array::shuffle() { template <typename Less> _FORCE_INLINE_ int bisect(const Vector<Variant> &p_array, const Variant &p_value, bool p_before, const Less &p_less) { - int lo = 0; int hi = p_array.size(); if (p_before) { @@ -420,13 +387,11 @@ _FORCE_INLINE_ int bisect(const Vector<Variant> &p_array, const Variant &p_value } int Array::bsearch(const Variant &p_value, bool p_before) { - ERR_FAIL_COND_V(!_p->typed.validate(p_value, "binary search"), -1); return bisect(_p->array, p_value, p_before, _ArrayVariantSort()); } int Array::bsearch_custom(const Variant &p_value, Object *p_obj, const StringName &p_function, bool p_before) { - ERR_FAIL_COND_V(!_p->typed.validate(p_value, "custom binary search"), -1); ERR_FAIL_NULL_V(p_obj, 0); @@ -438,19 +403,16 @@ int Array::bsearch_custom(const Variant &p_value, Object *p_obj, const StringNam } Array &Array::invert() { - _p->array.invert(); return *this; } void Array::push_front(const Variant &p_value) { - ERR_FAIL_COND(!_p->typed.validate(p_value, "push_front")); _p->array.insert(0, p_value); } Variant Array::pop_back() { - if (!_p->array.empty()) { int n = _p->array.size() - 1; Variant ret = _p->array.get(n); @@ -461,7 +423,6 @@ Variant Array::pop_back() { } Variant Array::pop_front() { - if (!_p->array.empty()) { Variant ret = _p->array.get(0); _p->array.remove(0); @@ -471,7 +432,6 @@ Variant Array::pop_front() { } Variant Array::min() const { - Variant minval; for (int i = 0; i < size(); i++) { if (i == 0) { @@ -494,7 +454,6 @@ Variant Array::min() const { } Variant Array::max() const { - Variant maxval; for (int i = 0; i < size(); i++) { if (i == 0) { @@ -542,17 +501,14 @@ void Array::set_typed(uint32_t p_type, const StringName &p_class_name, const Var } Array::Array(const Array &p_from) { - _p = nullptr; _ref(p_from); } Array::Array() { - _p = memnew(ArrayPrivate); _p->refcount.init(); } Array::~Array() { - _unref(); } diff --git a/core/array.h b/core/array.h index 14db57f15f..d2e0537ad5 100644 --- a/core/array.h +++ b/core/array.h @@ -39,7 +39,6 @@ class Object; class StringName; class Array { - mutable ArrayPrivate *_p; void _ref(const Array &p_from) const; void _unref() const; diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index ed0e7b1018..a5809d6678 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -67,7 +67,6 @@ static const unsigned int MONTH_DAYS_TABLE[2][12] = { _ResourceLoader *_ResourceLoader::singleton = nullptr; Error _ResourceLoader::load_threaded_request(const String &p_path, const String &p_type_hint, bool p_use_sub_threads) { - return ResourceLoader::load_threaded_request(p_path, p_type_hint, p_use_sub_threads); } _ResourceLoader::ThreadLoadStatus _ResourceLoader::load_threaded_get_status(const String &p_path, Array r_progress) { @@ -84,7 +83,6 @@ RES _ResourceLoader::load_threaded_get(const String &p_path) { } RES _ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache) { - Error err = OK; RES ret = ResourceLoader::load(p_path, p_type_hint, p_no_cache, &err); @@ -93,12 +91,10 @@ RES _ResourceLoader::load(const String &p_path, const String &p_type_hint, bool } Vector<String> _ResourceLoader::get_recognized_extensions_for_type(const String &p_type) { - List<String> exts; ResourceLoader::get_recognized_extensions_for_type(p_type, &exts); Vector<String> ret; for (List<String>::Element *E = exts.front(); E; E = E->next()) { - ret.push_back(E->get()); } @@ -106,12 +102,10 @@ Vector<String> _ResourceLoader::get_recognized_extensions_for_type(const String } void _ResourceLoader::set_abort_on_missing_resources(bool p_abort) { - ResourceLoader::set_abort_on_missing_resources(p_abort); } PackedStringArray _ResourceLoader::get_dependencies(const String &p_path) { - List<String> deps; ResourceLoader::get_dependencies(p_path, &deps); @@ -124,7 +118,6 @@ PackedStringArray _ResourceLoader::get_dependencies(const String &p_path) { }; bool _ResourceLoader::has_cached(const String &p_path) { - String local_path = ProjectSettings::get_singleton()->localize_path(p_path); return ResourceCache::has(local_path); } @@ -134,7 +127,6 @@ bool _ResourceLoader::exists(const String &p_path, const String &p_type_hint) { } void _ResourceLoader::_bind_methods() { - ClassDB::bind_method(D_METHOD("load_threaded_request", "path", "type_hint", "use_sub_threads"), &_ResourceLoader::load_threaded_request, DEFVAL(""), DEFVAL(false)); ClassDB::bind_method(D_METHOD("load_threaded_get_status", "path", "progress"), &_ResourceLoader::load_threaded_get_status, DEFVAL(Array())); ClassDB::bind_method(D_METHOD("load_threaded_get", "path"), &_ResourceLoader::load_threaded_get); @@ -160,13 +152,11 @@ Error _ResourceSaver::save(const String &p_path, const RES &p_resource, SaverFla } Vector<String> _ResourceSaver::get_recognized_extensions(const RES &p_resource) { - ERR_FAIL_COND_V_MSG(p_resource.is_null(), Vector<String>(), "It's not a reference to a valid Resource object."); List<String> exts; ResourceSaver::get_recognized_extensions(p_resource, &exts); Vector<String> ret; for (List<String>::Element *E = exts.front(); E; E = E->next()) { - ret.push_back(E->get()); } return ret; @@ -175,7 +165,6 @@ Vector<String> _ResourceSaver::get_recognized_extensions(const RES &p_resource) _ResourceSaver *_ResourceSaver::singleton = nullptr; void _ResourceSaver::_bind_methods() { - ClassDB::bind_method(D_METHOD("save", "path", "resource", "flags"), &_ResourceSaver::save, DEFVAL(0)); ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type"), &_ResourceSaver::get_recognized_extensions); @@ -203,36 +192,29 @@ void _OS::close_midi_inputs() { } void _OS::set_use_file_access_save_and_swap(bool p_enable) { - FileAccess::set_backup_save(p_enable); } void _OS::set_low_processor_usage_mode(bool p_enabled) { - OS::get_singleton()->set_low_processor_usage_mode(p_enabled); } bool _OS::is_in_low_processor_usage_mode() const { - return OS::get_singleton()->is_in_low_processor_usage_mode(); } void _OS::set_low_processor_usage_mode_sleep_usec(int p_usec) { - OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(p_usec); } int _OS::get_low_processor_usage_mode_sleep_usec() const { - return OS::get_singleton()->get_low_processor_usage_mode_sleep_usec(); } String _OS::get_executable_path() const { - return OS::get_singleton()->get_executable_path(); } Error _OS::shell_open(String p_uri) { - if (p_uri.begins_with("res://")) { WARN_PRINT("Attempting to open an URL with the \"res://\" protocol. Use `ProjectSettings.globalize_path()` to convert a Godot-specific path to a system path before opening it with `OS.shell_open()`."); } else if (p_uri.begins_with("user://")) { @@ -242,7 +224,6 @@ Error _OS::shell_open(String p_uri) { }; int _OS::execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking, Array p_output, bool p_read_stderr) { - OS::ProcessID pid = -2; int exitcode = 0; List<String> args; @@ -261,34 +242,27 @@ int _OS::execute(const String &p_path, const Vector<String> &p_arguments, bool p } Error _OS::kill(int p_pid) { - return OS::get_singleton()->kill(p_pid); } int _OS::get_process_id() const { - return OS::get_singleton()->get_process_id(); }; bool _OS::has_environment(const String &p_var) const { - return OS::get_singleton()->has_environment(p_var); } String _OS::get_environment(const String &p_var) const { - return OS::get_singleton()->get_environment(p_var); } String _OS::get_name() const { - return OS::get_singleton()->get_name(); } Vector<String> _OS::get_cmdline_args() { - List<String> cmdline = OS::get_singleton()->get_cmdline_args(); Vector<String> cmdlinev; for (List<String>::Element *E = cmdline.front(); E; E = E->next()) { - cmdlinev.push_back(E->get()); } @@ -296,42 +270,34 @@ Vector<String> _OS::get_cmdline_args() { } String _OS::get_locale() const { - return OS::get_singleton()->get_locale(); } String _OS::get_model_name() const { - return OS::get_singleton()->get_model_name(); } Error _OS::set_thread_name(const String &p_name) { - return Thread::set_name(p_name); }; bool _OS::has_feature(const String &p_feature) const { - return OS::get_singleton()->has_feature(p_feature); } uint64_t _OS::get_static_memory_usage() const { - return OS::get_singleton()->get_static_memory_usage(); } uint64_t _OS::get_static_memory_peak_usage() const { - return OS::get_singleton()->get_static_memory_peak_usage(); } int _OS::get_exit_code() const { - return OS::get_singleton()->get_exit_code(); } void _OS::set_exit_code(int p_code) { - if (p_code < 0 || p_code > 125) { WARN_PRINT("For portability reasons, the exit code should be set between 0 and 125 (inclusive)."); } @@ -344,7 +310,6 @@ void _OS::set_exit_code(int p_code) { * dst */ Dictionary _OS::get_datetime(bool utc) const { - Dictionary dated = get_date(utc); Dictionary timed = get_time(utc); @@ -359,7 +324,6 @@ Dictionary _OS::get_datetime(bool utc) const { } Dictionary _OS::get_date(bool utc) const { - OS::Date date = OS::get_singleton()->get_date(utc); Dictionary dated; dated[YEAR_KEY] = date.year; @@ -371,7 +335,6 @@ Dictionary _OS::get_date(bool utc) const { } Dictionary _OS::get_time(bool utc) const { - OS::Time time = OS::get_singleton()->get_time(utc); Dictionary timed; timed[HOUR_KEY] = time.hour; @@ -393,7 +356,6 @@ Dictionary _OS::get_time(bool utc) const { * @return epoch calculated */ int64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const { - // Bunch of conversion constants static const unsigned int SECONDS_PER_MINUTE = 60; static const unsigned int MINUTES_PER_HOUR = 60; @@ -466,7 +428,6 @@ int64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const { * @return dictionary of date and time values */ Dictionary _OS::get_datetime_from_unix_time(int64_t unix_time_val) const { - OS::Date date; OS::Time time; @@ -530,7 +491,6 @@ Dictionary _OS::get_time_zone_info() const { } uint64_t _OS::get_unix_time() const { - return OS::get_singleton()->get_unix_time(); } @@ -543,57 +503,46 @@ uint64_t _OS::get_system_time_msecs() const { } void _OS::delay_usec(uint32_t p_usec) const { - OS::get_singleton()->delay_usec(p_usec); } void _OS::delay_msec(uint32_t p_msec) const { - OS::get_singleton()->delay_usec(int64_t(p_msec) * 1000); } uint32_t _OS::get_ticks_msec() const { - return OS::get_singleton()->get_ticks_msec(); } uint64_t _OS::get_ticks_usec() const { - return OS::get_singleton()->get_ticks_usec(); } uint32_t _OS::get_splash_tick_msec() const { - return OS::get_singleton()->get_splash_tick_msec(); } bool _OS::can_use_threads() const { - return OS::get_singleton()->can_use_threads(); } bool _OS::is_userfs_persistent() const { - return OS::get_singleton()->is_userfs_persistent(); } int _OS::get_processor_count() const { - return OS::get_singleton()->get_processor_count(); } bool _OS::is_stdout_verbose() const { - return OS::get_singleton()->is_stdout_verbose(); } void _OS::dump_memory_to_file(const String &p_file) { - OS::get_singleton()->dump_memory_to_file(p_file.utf8().get_data()); } struct _OSCoreBindImg { - String path; Size2 size; int fmt; @@ -603,7 +552,6 @@ struct _OSCoreBindImg { }; void _OS::print_all_textures_by_size() { - List<_OSCoreBindImg> imgs; int total = 0; { @@ -611,7 +559,6 @@ void _OS::print_all_textures_by_size() { ResourceCache::get_cached_resources(&rsrc); for (List<Ref<Resource>>::Element *E = rsrc.front(); E; E = E->next()) { - if (!E->get()->is_class("ImageTexture")) continue; @@ -632,13 +579,11 @@ void _OS::print_all_textures_by_size() { imgs.sort(); for (List<_OSCoreBindImg>::Element *E = imgs.front(); E; E = E->next()) { - total -= E->get().vram; } } void _OS::print_resources_by_type(const Vector<String> &p_types) { - Map<String, int> type_count; List<Ref<Resource>> resources; @@ -648,7 +593,6 @@ void _OS::print_resources_by_type(const Vector<String> &p_types) { ResourceCache::get_cached_resources(&rsrc); for (List<Ref<Resource>>::Element *E = rsrc.front(); E; E = E->next()) { - Ref<Resource> r = E->get(); bool found = false; @@ -669,27 +613,22 @@ void _OS::print_resources_by_type(const Vector<String> &p_types) { }; void _OS::print_all_resources(const String &p_to_file) { - OS::get_singleton()->print_all_resources(p_to_file); } void _OS::print_resources_in_use(bool p_short) { - OS::get_singleton()->print_resources_in_use(p_short); } void _OS::dump_resources_to_file(const String &p_file) { - OS::get_singleton()->dump_resources_to_file(p_file.utf8().get_data()); } String _OS::get_user_data_dir() const { - return OS::get_singleton()->get_user_data_dir(); }; bool _OS::is_debug_build() const { - #ifdef DEBUG_ENABLED return true; #else @@ -698,37 +637,30 @@ bool _OS::is_debug_build() const { } String _OS::get_system_dir(SystemDir p_dir) const { - return OS::get_singleton()->get_system_dir(OS::SystemDir(p_dir)); } String _OS::get_keycode_string(uint32_t p_code) const { - return keycode_get_string(p_code); } bool _OS::is_keycode_unicode(uint32_t p_unicode) const { - return keycode_has_unicode(p_unicode); } int _OS::find_keycode_from_string(const String &p_code) const { - return find_keycode(p_code); } bool _OS::request_permission(const String &p_name) { - return OS::get_singleton()->request_permission(p_name); } bool _OS::request_permissions() { - return OS::get_singleton()->request_permissions(); } Vector<String> _OS::get_granted_permissions() const { - return OS::get_singleton()->get_granted_permissions(); } @@ -739,7 +671,6 @@ String _OS::get_unique_id() const { _OS *_OS::singleton = nullptr; void _OS::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_connected_midi_inputs"), &_OS::get_connected_midi_inputs); ClassDB::bind_method(D_METHOD("open_midi_inputs"), &_OS::open_midi_inputs); ClassDB::bind_method(D_METHOD("close_midi_inputs"), &_OS::close_midi_inputs); @@ -870,39 +801,31 @@ void _OS::_bind_methods() { _Geometry *_Geometry::singleton = nullptr; _Geometry *_Geometry::get_singleton() { - return singleton; } Vector<Plane> _Geometry::build_box_planes(const Vector3 &p_extents) { - return Geometry::build_box_planes(p_extents); } Vector<Plane> _Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) { - return Geometry::build_cylinder_planes(p_radius, p_height, p_sides, p_axis); } Vector<Plane> _Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) { - return Geometry::build_capsule_planes(p_radius, p_height, p_sides, p_lats, p_axis); } bool _Geometry::is_point_in_circle(const Vector2 &p_point, const Vector2 &p_circle_pos, real_t p_circle_radius) { - return Geometry::is_point_in_circle(p_point, p_circle_pos, p_circle_radius); } real_t _Geometry::segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius) { - return Geometry::segment_intersects_circle(p_from, p_to, p_circle_pos, p_circle_radius); } Variant _Geometry::segment_intersects_segment_2d(const Vector2 &p_from_a, const Vector2 &p_to_a, const Vector2 &p_from_b, const Vector2 &p_to_b) { - Vector2 result; if (Geometry::segment_intersects_segment_2d(p_from_a, p_to_a, p_from_b, p_to_b, &result)) { - return result; } else { return Variant(); @@ -910,7 +833,6 @@ Variant _Geometry::segment_intersects_segment_2d(const Vector2 &p_from_a, const }; Variant _Geometry::line_intersects_line_2d(const Vector2 &p_from_a, const Vector2 &p_dir_a, const Vector2 &p_from_b, const Vector2 &p_dir_b) { - Vector2 result; if (Geometry::line_intersects_line_2d(p_from_a, p_dir_a, p_from_b, p_dir_b, result)) { return result; @@ -920,7 +842,6 @@ Variant _Geometry::line_intersects_line_2d(const Vector2 &p_from_a, const Vector } Vector<Vector2> _Geometry::get_closest_points_between_segments_2d(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2) { - Vector2 r1, r2; Geometry::get_closest_points_between_segments(p1, q1, p2, q2, r1, r2); Vector<Vector2> r; @@ -931,7 +852,6 @@ Vector<Vector2> _Geometry::get_closest_points_between_segments_2d(const Vector2 } Vector<Vector3> _Geometry::get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2) { - Vector3 r1, r2; Geometry::get_closest_points_between_segments(p1, p2, q1, q2, r1, r2); Vector<Vector3> r; @@ -941,27 +861,22 @@ Vector<Vector3> _Geometry::get_closest_points_between_segments(const Vector3 &p1 return r; } Vector2 _Geometry::get_closest_point_to_segment_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) { - Vector2 s[2] = { p_a, p_b }; return Geometry::get_closest_point_to_segment_2d(p_point, s); } Vector3 _Geometry::get_closest_point_to_segment(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) { - Vector3 s[2] = { p_a, p_b }; return Geometry::get_closest_point_to_segment(p_point, s); } Vector2 _Geometry::get_closest_point_to_segment_uncapped_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) { - Vector2 s[2] = { p_a, p_b }; return Geometry::get_closest_point_to_segment_uncapped_2d(p_point, s); } Vector3 _Geometry::get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) { - Vector3 s[2] = { p_a, p_b }; return Geometry::get_closest_point_to_segment_uncapped(p_point, s); } Variant _Geometry::ray_intersects_triangle(const Vector3 &p_from, const Vector3 &p_dir, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) { - Vector3 res; if (Geometry::ray_intersects_triangle(p_from, p_dir, p_v0, p_v1, p_v2, &res)) return res; @@ -969,7 +884,6 @@ Variant _Geometry::ray_intersects_triangle(const Vector3 &p_from, const Vector3 return Variant(); } Variant _Geometry::segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) { - Vector3 res; if (Geometry::segment_intersects_triangle(p_from, p_to, p_v0, p_v1, p_v2, &res)) return res; @@ -978,12 +892,10 @@ Variant _Geometry::segment_intersects_triangle(const Vector3 &p_from, const Vect } bool _Geometry::point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const { - return Geometry::is_point_in_triangle(s, a, b, c); } Vector<Vector3> _Geometry::segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius) { - Vector<Vector3> r; Vector3 res, norm; if (!Geometry::segment_intersects_sphere(p_from, p_to, p_sphere_pos, p_sphere_radius, &res, &norm)) @@ -995,7 +907,6 @@ Vector<Vector3> _Geometry::segment_intersects_sphere(const Vector3 &p_from, cons return r; } Vector<Vector3> _Geometry::segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius) { - Vector<Vector3> r; Vector3 res, norm; if (!Geometry::segment_intersects_cylinder(p_from, p_to, p_height, p_radius, &res, &norm)) @@ -1007,7 +918,6 @@ Vector<Vector3> _Geometry::segment_intersects_cylinder(const Vector3 &p_from, co return r; } Vector<Vector3> _Geometry::segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes) { - Vector<Vector3> r; Vector3 res, norm; if (!Geometry::segment_intersects_convex(p_from, p_to, p_planes.ptr(), p_planes.size(), &res, &norm)) @@ -1020,37 +930,30 @@ Vector<Vector3> _Geometry::segment_intersects_convex(const Vector3 &p_from, cons } bool _Geometry::is_polygon_clockwise(const Vector<Vector2> &p_polygon) { - return Geometry::is_polygon_clockwise(p_polygon); } bool _Geometry::is_point_in_polygon(const Point2 &p_point, const Vector<Vector2> &p_polygon) { - return Geometry::is_point_in_polygon(p_point, p_polygon); } Vector<int> _Geometry::triangulate_polygon(const Vector<Vector2> &p_polygon) { - return Geometry::triangulate_polygon(p_polygon); } Vector<int> _Geometry::triangulate_delaunay_2d(const Vector<Vector2> &p_points) { - return Geometry::triangulate_delaunay_2d(p_points); } Vector<Point2> _Geometry::convex_hull_2d(const Vector<Point2> &p_points) { - return Geometry::convex_hull_2d(p_points); } Vector<Vector3> _Geometry::clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane) { - return Geometry::clip_polygon(p_points, p_plane); } Array _Geometry::merge_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) { - Vector<Vector<Point2>> polys = Geometry::merge_polygons_2d(p_polygon_a, p_polygon_b); Array ret; @@ -1062,7 +965,6 @@ Array _Geometry::merge_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vec } Array _Geometry::clip_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) { - Vector<Vector<Point2>> polys = Geometry::clip_polygons_2d(p_polygon_a, p_polygon_b); Array ret; @@ -1074,7 +976,6 @@ Array _Geometry::clip_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vect } Array _Geometry::intersect_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) { - Vector<Vector<Point2>> polys = Geometry::intersect_polygons_2d(p_polygon_a, p_polygon_b); Array ret; @@ -1086,7 +987,6 @@ Array _Geometry::intersect_polygons_2d(const Vector<Vector2> &p_polygon_a, const } Array _Geometry::exclude_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) { - Vector<Vector<Point2>> polys = Geometry::exclude_polygons_2d(p_polygon_a, p_polygon_b); Array ret; @@ -1098,7 +998,6 @@ Array _Geometry::exclude_polygons_2d(const Vector<Vector2> &p_polygon_a, const V } Array _Geometry::clip_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) { - Vector<Vector<Point2>> polys = Geometry::clip_polyline_with_polygon_2d(p_polyline, p_polygon); Array ret; @@ -1110,7 +1009,6 @@ Array _Geometry::clip_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline } Array _Geometry::intersect_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) { - Vector<Vector<Point2>> polys = Geometry::intersect_polyline_with_polygon_2d(p_polyline, p_polygon); Array ret; @@ -1122,7 +1020,6 @@ Array _Geometry::intersect_polyline_with_polygon_2d(const Vector<Vector2> &p_pol } Array _Geometry::offset_polygon_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type) { - Vector<Vector<Point2>> polys = Geometry::offset_polygon_2d(p_polygon, p_delta, Geometry::PolyJoinType(p_join_type)); Array ret; @@ -1134,7 +1031,6 @@ Array _Geometry::offset_polygon_2d(const Vector<Vector2> &p_polygon, real_t p_de } Array _Geometry::offset_polyline_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) { - Vector<Vector<Point2>> polys = Geometry::offset_polyline_2d(p_polygon, p_delta, Geometry::PolyJoinType(p_join_type), Geometry::PolyEndType(p_end_type)); Array ret; @@ -1146,12 +1042,10 @@ Array _Geometry::offset_polyline_2d(const Vector<Vector2> &p_polygon, real_t p_d } Dictionary _Geometry::make_atlas(const Vector<Size2> &p_rects) { - Dictionary ret; Vector<Size2i> rects; for (int i = 0; i < p_rects.size(); i++) { - rects.push_back(p_rects[i]); }; @@ -1163,7 +1057,6 @@ Dictionary _Geometry::make_atlas(const Vector<Size2> &p_rects) { Size2 r_size = size; Vector<Point2> r_result; for (int i = 0; i < result.size(); i++) { - r_result.push_back(result[i]); }; @@ -1174,12 +1067,10 @@ Dictionary _Geometry::make_atlas(const Vector<Size2> &p_rects) { }; int _Geometry::get_uv84_normal_bit(const Vector3 &p_vector) { - return Geometry::get_uv84_normal_bit(p_vector); } 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)); @@ -1245,7 +1136,6 @@ void _Geometry::_bind_methods() { ////// _File ////// Error _File::open_encrypted(const String &p_path, ModeFlags p_mode_flags, const Vector<uint8_t> &p_key) { - Error err = open(p_path, p_mode_flags); if (err) return err; @@ -1262,7 +1152,6 @@ Error _File::open_encrypted(const String &p_path, ModeFlags p_mode_flags, const } Error _File::open_encrypted_pass(const String &p_path, ModeFlags p_mode_flags, const String &p_pass) { - Error err = open(p_path, p_mode_flags); if (err) return err; @@ -1280,7 +1169,6 @@ Error _File::open_encrypted_pass(const String &p_path, ModeFlags p_mode_flags, c } Error _File::open_compressed(const String &p_path, ModeFlags p_mode_flags, CompressionMode p_compress_mode) { - FileAccessCompressed *fac = memnew(FileAccessCompressed); fac->configure("GCPF", (Compression::Mode)p_compress_mode); @@ -1297,7 +1185,6 @@ Error _File::open_compressed(const String &p_path, ModeFlags p_mode_flags, Compr } Error _File::open(const String &p_path, ModeFlags p_mode_flags) { - close(); Error err; f = FileAccess::open(p_path, p_mode_flags, &err); @@ -1307,94 +1194,77 @@ Error _File::open(const String &p_path, ModeFlags p_mode_flags) { } void _File::close() { - if (f) memdelete(f); f = nullptr; } bool _File::is_open() const { - return f != nullptr; } String _File::get_path() const { - ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use."); return f->get_path(); } String _File::get_path_absolute() const { - ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use."); return f->get_path_absolute(); } void _File::seek(int64_t p_position) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->seek(p_position); } void _File::seek_end(int64_t p_position) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->seek_end(p_position); } int64_t _File::get_position() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_position(); } int64_t _File::get_len() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_len(); } bool _File::eof_reached() const { - ERR_FAIL_COND_V_MSG(!f, false, "File must be opened before use."); return f->eof_reached(); } uint8_t _File::get_8() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_8(); } uint16_t _File::get_16() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_16(); } uint32_t _File::get_32() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_32(); } uint64_t _File::get_64() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_64(); } float _File::get_float() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_float(); } double _File::get_double() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_double(); } real_t _File::get_real() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_real(); } Vector<uint8_t> _File::get_buffer(int p_length) const { - Vector<uint8_t> data; ERR_FAIL_COND_V_MSG(!f, data, "File must be opened before use."); @@ -1416,7 +1286,6 @@ Vector<uint8_t> _File::get_buffer(int p_length) const { } String _File::get_as_text() const { - ERR_FAIL_COND_V_MSG(!f, String(), "File must be opened before use."); String text; @@ -1436,17 +1305,14 @@ String _File::get_as_text() const { } String _File::get_md5(const String &p_path) const { - return FileAccess::get_md5(p_path); } String _File::get_sha256(const String &p_path) const { - return FileAccess::get_sha256(p_path); } String _File::get_line() const { - ERR_FAIL_COND_V_MSG(!f, String(), "File must be opened before use."); return f->get_line(); } @@ -1462,90 +1328,76 @@ Vector<String> _File::get_csv_line(const String &p_delim) const { */ void _File::set_endian_swap(bool p_swap) { - eswap = p_swap; if (f) f->set_endian_swap(p_swap); } bool _File::get_endian_swap() { - return eswap; } Error _File::get_error() const { - if (!f) return ERR_UNCONFIGURED; return f->get_error(); } void _File::store_8(uint8_t p_dest) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_8(p_dest); } void _File::store_16(uint16_t p_dest) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_16(p_dest); } void _File::store_32(uint32_t p_dest) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_32(p_dest); } void _File::store_64(uint64_t p_dest) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_64(p_dest); } void _File::store_float(float p_dest) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_float(p_dest); } void _File::store_double(double p_dest) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_double(p_dest); } void _File::store_real(real_t p_real) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_real(p_real); } void _File::store_string(const String &p_string) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_string(p_string); } void _File::store_pascal_string(const String &p_string) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_pascal_string(p_string); }; String _File::get_pascal_string() { - ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use."); return f->get_pascal_string(); }; void _File::store_line(const String &p_string) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_line(p_string); } @@ -1556,7 +1408,6 @@ void _File::store_csv_line(const Vector<String> &p_values, const String &p_delim } void _File::store_buffer(const Vector<uint8_t> &p_buffer) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); int len = p_buffer.size(); @@ -1569,12 +1420,10 @@ void _File::store_buffer(const Vector<uint8_t> &p_buffer) { } bool _File::file_exists(const String &p_name) const { - return FileAccess::exists(p_name); } void _File::store_var(const Variant &p_var, bool p_full_objects) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); int len; Error err = encode_variant(p_var, nullptr, len, p_full_objects); @@ -1592,7 +1441,6 @@ void _File::store_var(const Variant &p_var, bool p_full_objects) { } Variant _File::get_var(bool p_allow_objects) const { - ERR_FAIL_COND_V_MSG(!f, Variant(), "File must be opened before use."); uint32_t len = get_32(); Vector<uint8_t> buff = get_buffer(len); @@ -1608,12 +1456,10 @@ Variant _File::get_var(bool p_allow_objects) const { } uint64_t _File::get_modified_time(const String &p_file) const { - return FileAccess::get_modified_time(p_file); } void _File::_bind_methods() { - ClassDB::bind_method(D_METHOD("open_encrypted", "path", "mode_flags", "key"), &_File::open_encrypted); ClassDB::bind_method(D_METHOD("open_encrypted_with_pass", "path", "mode_flags", "pass"), &_File::open_encrypted_pass); ClassDB::bind_method(D_METHOD("open_compressed", "path", "mode_flags", "compression_mode"), &_File::open_compressed, DEFVAL(0)); @@ -1699,7 +1545,6 @@ Error _Directory::open(const String &p_path) { } Error _Directory::list_dir_begin(bool p_skip_navigational, bool p_skip_hidden) { - ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); _list_skip_navigational = p_skip_navigational; @@ -1709,35 +1554,29 @@ Error _Directory::list_dir_begin(bool p_skip_navigational, bool p_skip_hidden) { } String _Directory::get_next() { - ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use."); String next = d->get_next(); while (next != "" && ((_list_skip_navigational && (next == "." || next == "..")) || (_list_skip_hidden && d->current_is_hidden()))) { - next = d->get_next(); } return next; } bool _Directory::current_is_dir() const { - ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use."); return d->current_is_dir(); } void _Directory::list_dir_end() { - ERR_FAIL_COND_MSG(!d, "Directory must be opened before use."); d->list_dir_end(); } int _Directory::get_drive_count() { - ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use."); return d->get_drive_count(); } String _Directory::get_drive(int p_drive) { - ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use."); return d->get_drive(p_drive); } @@ -1747,17 +1586,14 @@ int _Directory::get_current_drive() { } Error _Directory::change_dir(String p_dir) { - ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); return d->change_dir(p_dir); } String _Directory::get_current_dir() { - ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use."); return d->get_current_dir(); } Error _Directory::make_dir(String p_dir) { - ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); if (!p_dir.is_rel_path()) { DirAccess *d = DirAccess::create_for_path(p_dir); @@ -1768,7 +1604,6 @@ Error _Directory::make_dir(String p_dir) { return d->make_dir(p_dir); } Error _Directory::make_dir_recursive(String p_dir) { - ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); if (!p_dir.is_rel_path()) { DirAccess *d = DirAccess::create_for_path(p_dir); @@ -1780,7 +1615,6 @@ Error _Directory::make_dir_recursive(String p_dir) { } bool _Directory::file_exists(String p_file) { - ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use."); if (!p_file.is_rel_path()) { @@ -1793,7 +1627,6 @@ bool _Directory::file_exists(String p_file) { bool _Directory::dir_exists(String p_dir) { ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use."); if (!p_dir.is_rel_path()) { - DirAccess *d = DirAccess::create_for_path(p_dir); bool exists = d->dir_exists(p_dir); memdelete(d); @@ -1805,18 +1638,15 @@ bool _Directory::dir_exists(String p_dir) { } int _Directory::get_space_left() { - ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use."); return d->get_space_left() / 1024 * 1024; //return value in megabytes, given binding is int } Error _Directory::copy(String p_from, String p_to) { - ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); return d->copy(p_from, p_to); } Error _Directory::rename(String p_from, String p_to) { - ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); if (!p_from.is_rel_path()) { DirAccess *d = DirAccess::create_for_path(p_from); @@ -1828,7 +1658,6 @@ Error _Directory::rename(String p_from, String p_to) { return d->rename(p_from, p_to); } Error _Directory::remove(String p_name) { - ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); if (!p_name.is_rel_path()) { DirAccess *d = DirAccess::create_for_path(p_name); @@ -1841,7 +1670,6 @@ Error _Directory::remove(String p_name) { } void _Directory::_bind_methods() { - ClassDB::bind_method(D_METHOD("open", "path"), &_Directory::open); ClassDB::bind_method(D_METHOD("list_dir_begin", "skip_navigational", "skip_hidden"), &_Directory::list_dir_begin, DEFVAL(false), DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_next"), &_Directory::get_next); @@ -1881,7 +1709,6 @@ _Marshalls *_Marshalls::get_singleton() { } String _Marshalls::variant_to_base64(const Variant &p_var, bool p_full_objects) { - int len; Error err = encode_variant(p_var, nullptr, len, p_full_objects); ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant."); @@ -1900,7 +1727,6 @@ String _Marshalls::variant_to_base64(const Variant &p_var, bool p_full_objects) }; Variant _Marshalls::base64_to_variant(const String &p_str, bool p_allow_objects) { - int strlen = p_str.length(); CharString cstr = p_str.ascii(); @@ -1919,14 +1745,12 @@ Variant _Marshalls::base64_to_variant(const String &p_str, bool p_allow_objects) }; String _Marshalls::raw_to_base64(const Vector<uint8_t> &p_arr) { - String ret = CryptoCore::b64_encode_str(p_arr.ptr(), p_arr.size()); ERR_FAIL_COND_V(ret == "", ret); return ret; }; Vector<uint8_t> _Marshalls::base64_to_raw(const String &p_str) { - int strlen = p_str.length(); CharString cstr = p_str.ascii(); @@ -1944,7 +1768,6 @@ Vector<uint8_t> _Marshalls::base64_to_raw(const String &p_str) { }; String _Marshalls::utf8_to_base64(const String &p_str) { - CharString cstr = p_str.utf8(); String ret = CryptoCore::b64_encode_str((unsigned char *)cstr.get_data(), cstr.length()); ERR_FAIL_COND_V(ret == "", ret); @@ -1952,7 +1775,6 @@ String _Marshalls::utf8_to_base64(const String &p_str) { }; String _Marshalls::base64_to_utf8(const String &p_str) { - int strlen = p_str.length(); CharString cstr = p_str.ascii(); @@ -1970,7 +1792,6 @@ String _Marshalls::base64_to_utf8(const String &p_str) { }; void _Marshalls::_bind_methods() { - ClassDB::bind_method(D_METHOD("variant_to_base64", "variant", "full_objects"), &_Marshalls::variant_to_base64, DEFVAL(false)); ClassDB::bind_method(D_METHOD("base64_to_variant", "base64_str", "allow_objects"), &_Marshalls::base64_to_variant, DEFVAL(false)); @@ -1984,22 +1805,18 @@ void _Marshalls::_bind_methods() { ////// _Semaphore ////// void _Semaphore::wait() { - semaphore.wait(); } Error _Semaphore::try_wait() { - return semaphore.try_wait() ? OK : ERR_BUSY; } void _Semaphore::post() { - semaphore.post(); } void _Semaphore::_bind_methods() { - ClassDB::bind_method(D_METHOD("wait"), &_Semaphore::wait); ClassDB::bind_method(D_METHOD("try_wait"), &_Semaphore::try_wait); ClassDB::bind_method(D_METHOD("post"), &_Semaphore::post); @@ -2008,22 +1825,18 @@ void _Semaphore::_bind_methods() { ////// _Mutex ////// void _Mutex::lock() { - mutex.lock(); } Error _Mutex::try_lock() { - return mutex.try_lock(); } void _Mutex::unlock() { - mutex.unlock(); } void _Mutex::_bind_methods() { - ClassDB::bind_method(D_METHOD("lock"), &_Mutex::lock); ClassDB::bind_method(D_METHOD("try_lock"), &_Mutex::try_lock); ClassDB::bind_method(D_METHOD("unlock"), &_Mutex::unlock); @@ -2032,7 +1845,6 @@ void _Mutex::_bind_methods() { ////// _Thread ////// void _Thread::_start_func(void *ud) { - Ref<_Thread> *tud = (Ref<_Thread> *)ud; Ref<_Thread> t = *tud; memdelete(tud); @@ -2043,23 +1855,18 @@ void _Thread::_start_func(void *ud) { t->ret = t->target_instance->call(t->target_method, arg, 1, ce); if (ce.error != Callable::CallError::CALL_OK) { - String reason; switch (ce.error) { case Callable::CallError::CALL_ERROR_INVALID_ARGUMENT: { - reason = "Invalid Argument #" + itos(ce.argument); } break; case Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: { - reason = "Too Many Arguments"; } break; case Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS: { - reason = "Too Few Arguments"; } break; case Callable::CallError::CALL_ERROR_INVALID_METHOD: { - reason = "Method Not Found"; } break; default: { @@ -2071,7 +1878,6 @@ void _Thread::_start_func(void *ud) { } Error _Thread::start(Object *p_instance, const StringName &p_method, const Variant &p_userdata, Priority p_priority) { - ERR_FAIL_COND_V_MSG(active, ERR_ALREADY_IN_USE, "Thread already started."); ERR_FAIL_COND_V(!p_instance, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(p_method == StringName(), ERR_INVALID_PARAMETER); @@ -2100,7 +1906,6 @@ Error _Thread::start(Object *p_instance, const StringName &p_method, const Varia } String _Thread::get_id() const { - if (!thread) return String(); @@ -2108,11 +1913,9 @@ String _Thread::get_id() const { } bool _Thread::is_active() const { - return active; } Variant _Thread::wait_to_finish() { - ERR_FAIL_COND_V_MSG(!thread, Variant(), "Thread must exist to wait for its completion."); ERR_FAIL_COND_V_MSG(!active, Variant(), "Thread must be active to wait for its completion."); Thread::wait_to_finish(thread); @@ -2129,7 +1932,6 @@ Variant _Thread::wait_to_finish() { } void _Thread::_bind_methods() { - ClassDB::bind_method(D_METHOD("start", "instance", "method", "userdata", "priority"), &_Thread::start, DEFVAL(Variant()), DEFVAL(PRIORITY_NORMAL)); ClassDB::bind_method(D_METHOD("get_id"), &_Thread::get_id); ClassDB::bind_method(D_METHOD("is_active"), &_Thread::is_active); @@ -2147,7 +1949,6 @@ _Thread::~_Thread() { ////// _ClassDB ////// PackedStringArray _ClassDB::get_class_list() const { - List<StringName> classes; ClassDB::get_class_list(&classes); @@ -2161,7 +1962,6 @@ PackedStringArray _ClassDB::get_class_list() const { return ret; } PackedStringArray _ClassDB::get_inheriters_from_class(const StringName &p_class) const { - List<StringName> classes; ClassDB::get_inheriters_from_class(p_class, &classes); @@ -2175,23 +1975,18 @@ PackedStringArray _ClassDB::get_inheriters_from_class(const StringName &p_class) return ret; } StringName _ClassDB::get_parent_class(const StringName &p_class) const { - return ClassDB::get_parent_class(p_class); } bool _ClassDB::class_exists(const StringName &p_class) const { - return ClassDB::class_exists(p_class); } bool _ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) const { - return ClassDB::is_parent_class(p_class, p_inherits); } bool _ClassDB::can_instance(const StringName &p_class) const { - return ClassDB::can_instance(p_class); } Variant _ClassDB::instance(const StringName &p_class) const { - Object *obj = ClassDB::instance(p_class); if (!obj) return Variant(); @@ -2205,11 +2000,9 @@ Variant _ClassDB::instance(const StringName &p_class) const { } bool _ClassDB::has_signal(StringName p_class, StringName p_signal) const { - return ClassDB::has_signal(p_class, p_signal); } Dictionary _ClassDB::get_signal(StringName p_class, StringName p_signal) const { - MethodInfo signal; if (ClassDB::get_signal(p_class, p_signal, &signal)) { return signal.operator Dictionary(); @@ -2218,7 +2011,6 @@ Dictionary _ClassDB::get_signal(StringName p_class, StringName p_signal) const { } } Array _ClassDB::get_signal_list(StringName p_class, bool p_no_inheritance) const { - List<MethodInfo> signals; ClassDB::get_signal_list(p_class, &signals, p_no_inheritance); Array ret; @@ -2231,7 +2023,6 @@ Array _ClassDB::get_signal_list(StringName p_class, bool p_no_inheritance) const } Array _ClassDB::get_property_list(StringName p_class, bool p_no_inheritance) const { - List<PropertyInfo> plist; ClassDB::get_property_list(p_class, &plist, p_no_inheritance); Array ret; @@ -2260,12 +2051,10 @@ Error _ClassDB::set_property(Object *p_object, const StringName &p_property, con } bool _ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inheritance) const { - return ClassDB::has_method(p_class, p_method, p_no_inheritance); } Array _ClassDB::get_method_list(StringName p_class, bool p_no_inheritance) const { - List<MethodInfo> methods; ClassDB::get_method_list(p_class, &methods, p_no_inheritance); Array ret; @@ -2284,7 +2073,6 @@ Array _ClassDB::get_method_list(StringName p_class, bool p_no_inheritance) const } PackedStringArray _ClassDB::get_integer_constant_list(const StringName &p_class, bool p_no_inheritance) const { - List<String> constants; ClassDB::get_integer_constant_list(p_class, &constants, p_no_inheritance); @@ -2299,31 +2087,26 @@ PackedStringArray _ClassDB::get_integer_constant_list(const StringName &p_class, } bool _ClassDB::has_integer_constant(const StringName &p_class, const StringName &p_name) const { - bool success; ClassDB::get_integer_constant(p_class, p_name, &success); return success; } int _ClassDB::get_integer_constant(const StringName &p_class, const StringName &p_name) const { - bool found; int c = ClassDB::get_integer_constant(p_class, p_name, &found); ERR_FAIL_COND_V(!found, 0); return c; } StringName _ClassDB::get_category(const StringName &p_node) const { - return ClassDB::get_category(p_node); } bool _ClassDB::is_class_enabled(StringName p_class) const { - return ClassDB::is_class_enabled(p_class); } void _ClassDB::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_class_list"), &_ClassDB::get_class_list); ClassDB::bind_method(D_METHOD("get_inheriters_from_class", "class"), &_ClassDB::get_inheriters_from_class); ClassDB::bind_method(D_METHOD("get_parent_class", "class"), &_ClassDB::get_parent_class); @@ -2356,11 +2139,9 @@ void _ClassDB::_bind_methods() { ////// _Engine ////// void _Engine::set_iterations_per_second(int p_ips) { - Engine::get_singleton()->set_iterations_per_second(p_ips); } int _Engine::get_iterations_per_second() const { - return Engine::get_singleton()->get_iterations_per_second(); } @@ -2385,17 +2166,14 @@ int _Engine::get_target_fps() const { } float _Engine::get_frames_per_second() const { - return Engine::get_singleton()->get_frames_per_second(); } uint64_t _Engine::get_physics_frames() const { - return Engine::get_singleton()->get_physics_frames(); } uint64_t _Engine::get_idle_frames() const { - return Engine::get_singleton()->get_idle_frames(); } @@ -2404,23 +2182,19 @@ void _Engine::set_time_scale(float p_scale) { } float _Engine::get_time_scale() { - return Engine::get_singleton()->get_time_scale(); } int _Engine::get_frames_drawn() { - return Engine::get_singleton()->get_frames_drawn(); } MainLoop *_Engine::get_main_loop() const { - //needs to remain in OS, since it's actually OS that interacts with it, but it's better exposed here return OS::get_singleton()->get_main_loop(); } Dictionary _Engine::get_version_info() const { - return Engine::get_singleton()->get_version_info(); } @@ -2449,27 +2223,22 @@ bool _Engine::is_in_physics_frame() const { } bool _Engine::has_singleton(const String &p_name) const { - return Engine::get_singleton()->has_singleton(p_name); } Object *_Engine::get_singleton_object(const String &p_name) const { - return Engine::get_singleton()->get_singleton_object(p_name); } void _Engine::set_editor_hint(bool p_enabled) { - Engine::get_singleton()->set_editor_hint(p_enabled); } bool _Engine::is_editor_hint() const { - return Engine::get_singleton()->is_editor_hint(); } void _Engine::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_iterations_per_second", "iterations_per_second"), &_Engine::set_iterations_per_second); ClassDB::bind_method(D_METHOD("get_iterations_per_second"), &_Engine::get_iterations_per_second); ClassDB::bind_method(D_METHOD("set_physics_jitter_fix", "physics_jitter_fix"), &_Engine::set_physics_jitter_fix); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 44e573ccbe..32ddcf2c74 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -254,7 +254,6 @@ VARIANT_ENUM_CAST(_OS::Month); VARIANT_ENUM_CAST(_OS::SystemDir); class _Geometry : public Object { - GDCLASS(_Geometry, Object); static _Geometry *singleton; @@ -437,7 +436,6 @@ VARIANT_ENUM_CAST(_File::ModeFlags); VARIANT_ENUM_CAST(_File::CompressionMode); class _Directory : public Reference { - GDCLASS(_Directory, Reference); DirAccess *d; @@ -481,7 +479,6 @@ private: }; class _Marshalls : public Object { - GDCLASS(_Marshalls, Object); static _Marshalls *singleton; @@ -506,7 +503,6 @@ public: }; class _Mutex : public Reference { - GDCLASS(_Mutex, Reference); Mutex mutex; @@ -519,7 +515,6 @@ public: }; class _Semaphore : public Reference { - GDCLASS(_Semaphore, Reference); Semaphore semaphore; @@ -532,7 +527,6 @@ public: }; class _Thread : public Reference { - GDCLASS(_Thread, Reference); protected: @@ -566,7 +560,6 @@ public: VARIANT_ENUM_CAST(_Thread::Priority); class _ClassDB : public Object { - GDCLASS(_ClassDB, Object); protected: diff --git a/core/callable.cpp b/core/callable.cpp index 447cf78bea..dc2d034cc6 100644 --- a/core/callable.cpp +++ b/core/callable.cpp @@ -40,7 +40,6 @@ void Callable::call_deferred(const Variant **p_arguments, int p_argcount) const } void Callable::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, CallError &r_call_error) const { - if (is_null()) { r_call_error.error = CallError::CALL_ERROR_INSTANCE_IS_NULL; r_call_error.argument = 0; @@ -179,7 +178,6 @@ void Callable::operator=(const Callable &p_callable) { } Callable::operator String() const { - if (is_custom()) { return custom->get_as_text(); } else { @@ -192,7 +190,6 @@ Callable::operator String() const { String class_name = base->get_class(); Ref<Script> script = base->get_script(); if (script.is_valid() && script->get_path().is_resource_file()) { - class_name += "(" + script->get_path().get_file() + ")"; } return class_name + "::" + String(method); @@ -294,7 +291,6 @@ Signal::operator String() const { String class_name = base->get_class(); Ref<Script> script = base->get_script(); if (script.is_valid() && script->get_path().is_resource_file()) { - class_name += "(" + script->get_path().get_file() + ")"; } return class_name + "::[signal]" + String(name); @@ -312,7 +308,6 @@ Error Signal::emit(const Variant **p_arguments, int p_argcount) const { return obj->emit_signal(name, p_arguments, p_argcount); } Error Signal::connect(const Callable &p_callable, const Vector<Variant> &p_binds, uint32_t p_flags) { - Object *object = get_object(); ERR_FAIL_COND_V(!object, ERR_UNCONFIGURED); @@ -347,7 +342,6 @@ Array Signal::get_connections() const { } Signal::Signal(const Object *p_object, const StringName &p_name) { - ERR_FAIL_COND_MSG(p_object == nullptr, "Object argument to Signal constructor must be non-null"); object = p_object->get_instance_id(); @@ -355,7 +349,6 @@ Signal::Signal(const Object *p_object, const StringName &p_name) { } Signal::Signal(ObjectID p_object, const StringName &p_name) { - object = p_object; name = p_name; } diff --git a/core/callable.h b/core/callable.h index 1f6ff48d4f..7fd6b54cf7 100644 --- a/core/callable.h +++ b/core/callable.h @@ -45,7 +45,6 @@ class CallableCustom; // but can be optimized or customized. class Callable { - //needs to be max 16 bytes in 64 bits StringName method; union { diff --git a/core/callable_method_pointer.cpp b/core/callable_method_pointer.cpp index 8774af6add..21a917cbd7 100644 --- a/core/callable_method_pointer.cpp +++ b/core/callable_method_pointer.cpp @@ -48,7 +48,6 @@ bool CallableCustomMethodPointerBase::compare_equal(const CallableCustom *p_a, c } bool CallableCustomMethodPointerBase::compare_less(const CallableCustom *p_a, const CallableCustom *p_b) { - const CallableCustomMethodPointerBase *a = static_cast<const CallableCustomMethodPointerBase *>(p_a); const CallableCustomMethodPointerBase *b = static_cast<const CallableCustomMethodPointerBase *>(p_b); diff --git a/core/callable_method_pointer.h b/core/callable_method_pointer.h index fb809c2b44..3b0503e259 100644 --- a/core/callable_method_pointer.h +++ b/core/callable_method_pointer.h @@ -38,7 +38,6 @@ #include "core/simple_type.h" class CallableCustomMethodPointerBase : public CallableCustom { - uint32_t *comp_ptr; uint32_t comp_size; uint32_t h; @@ -74,7 +73,6 @@ public: template <class T> struct VariantCasterAndValidate { - static _FORCE_INLINE_ T cast(const Variant **p_args, uint32_t p_arg_idx, Callable::CallError &r_error) { Variant::Type argtype = GetTypeInfo<T>::VARIANT_TYPE; if (!Variant::can_convert_strict(p_args[p_arg_idx]->get_type(), argtype)) { @@ -89,7 +87,6 @@ struct VariantCasterAndValidate { template <class T> struct VariantCasterAndValidate<T &> { - static _FORCE_INLINE_ T cast(const Variant **p_args, uint32_t p_arg_idx, Callable::CallError &r_error) { Variant::Type argtype = GetTypeInfo<T>::VARIANT_TYPE; if (!Variant::can_convert_strict(p_args[p_arg_idx]->get_type(), argtype)) { @@ -104,7 +101,6 @@ struct VariantCasterAndValidate<T &> { template <class T> struct VariantCasterAndValidate<const T &> { - static _FORCE_INLINE_ T cast(const Variant **p_args, uint32_t p_arg_idx, Callable::CallError &r_error) { Variant::Type argtype = GetTypeInfo<T>::VARIANT_TYPE; if (!Variant::can_convert_strict(p_args[p_arg_idx]->get_type(), argtype)) { @@ -163,7 +159,6 @@ void call_with_variant_args(T *p_instance, void (T::*p_method)(P...), const Vari template <class T, class... P> class CallableCustomMethodPointer : public CallableCustomMethodPointerBase { - struct Data { T *instance; void (T::*method)(P...); @@ -173,7 +168,6 @@ public: virtual ObjectID get_object() const { return data.instance->get_instance_id(); } virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const { - call_with_variant_args(data.instance, data.method, p_arguments, p_argcount, r_call_error); } @@ -246,7 +240,6 @@ void call_with_variant_args_ret(T *p_instance, R (T::*p_method)(P...), const Var template <class T, class R, class... P> class CallableCustomMethodPointerRet : public CallableCustomMethodPointerBase { - struct Data { T *instance; R(T::*method) @@ -257,7 +250,6 @@ public: virtual ObjectID get_object() const { return data.instance->get_instance_id(); } virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const { - call_with_variant_args_ret(data.instance, data.method, p_arguments, p_argcount, r_return_value, r_call_error); } diff --git a/core/class_db.cpp b/core/class_db.cpp index dd9fba16d3..79e145248c 100644 --- a/core/class_db.cpp +++ b/core/class_db.cpp @@ -40,14 +40,12 @@ #ifdef DEBUG_METHODS_ENABLED MethodDefinition D_METHOD(const char *p_name) { - MethodDefinition md; md.name = StaticCString::create(p_name); return md; } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.push_back(StaticCString::create(p_arg1)); @@ -55,7 +53,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1) { } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(2); @@ -65,7 +62,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(3); @@ -76,7 +72,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(4); @@ -88,7 +83,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(5); @@ -101,7 +95,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(6); @@ -115,7 +108,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(7); @@ -130,7 +122,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(8); @@ -146,7 +137,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(9); @@ -163,7 +153,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(10); @@ -181,7 +170,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(11); @@ -200,7 +188,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(12); @@ -220,7 +207,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12, const char *p_arg13) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(13); @@ -245,12 +231,10 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ ClassDB::APIType ClassDB::current_api = API_CORE; void ClassDB::set_current_api(APIType p_api) { - current_api = p_api; } ClassDB::APIType ClassDB::get_current_api() { - return current_api; } @@ -259,13 +243,11 @@ HashMap<StringName, StringName> ClassDB::resource_base_extensions; HashMap<StringName, StringName> ClassDB::compat_classes; bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) { - OBJTYPE_RLOCK; StringName inherits = p_class; while (inherits.operator String().length()) { - if (inherits == p_inherits) return true; inherits = get_parent_class(inherits); @@ -274,13 +256,11 @@ bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inh return false; } void ClassDB::get_class_list(List<StringName> *p_classes) { - OBJTYPE_RLOCK; const StringName *k = nullptr; while ((k = classes.next(k))) { - p_classes->push_back(*k); } @@ -288,33 +268,28 @@ void ClassDB::get_class_list(List<StringName> *p_classes) { } void ClassDB::get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes) { - OBJTYPE_RLOCK; const StringName *k = nullptr; while ((k = classes.next(k))) { - if (*k != p_class && is_parent_class(*k, p_class)) p_classes->push_back(*k); } } void ClassDB::get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes) { - OBJTYPE_RLOCK; const StringName *k = nullptr; while ((k = classes.next(k))) { - if (*k != p_class && get_parent_class(*k) == p_class) p_classes->push_back(*k); } } StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) { - OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); @@ -324,7 +299,6 @@ StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) { } StringName ClassDB::get_compatibility_remapped_class(const StringName &p_class) { - if (classes.has(p_class)) { return p_class; } @@ -337,7 +311,6 @@ StringName ClassDB::get_compatibility_remapped_class(const StringName &p_class) } StringName ClassDB::get_parent_class(const StringName &p_class) { - OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); @@ -346,7 +319,6 @@ StringName ClassDB::get_parent_class(const StringName &p_class) { } ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) { - OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); @@ -356,7 +328,6 @@ ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) { } uint64_t ClassDB::get_api_hash(APIType p_api) { - OBJTYPE_RLOCK; #ifdef DEBUG_METHODS_ENABLED @@ -367,14 +338,12 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { const StringName *k = nullptr; while ((k = classes.next(k))) { - names.push_back(*k); } //must be alphabetically sorted for hash to compute names.sort_custom<StringName::AlphCompare>(); for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - ClassInfo *t = classes.getptr(E->get()); ERR_FAIL_COND_V_MSG(!t, 0, "Cannot get class '" + String(E->get()) + "'."); if (t->api != p_api || !t->exposed) @@ -389,7 +358,6 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { k = nullptr; while ((k = t->method_map.next(k))) { - String name = k->operator String(); ERR_CONTINUE(name.empty()); @@ -403,7 +371,6 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { snames.sort_custom<StringName::AlphCompare>(); for (List<StringName>::Element *F = snames.front(); F; F = F->next()) { - MethodBind *mb = t->method_map[F->get()]; hash = hash_djb2_one_64(mb->get_name().hash(), hash); hash = hash_djb2_one_64(mb->get_argument_count(), hash); @@ -436,14 +403,12 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { k = nullptr; while ((k = t->constant_map.next(k))) { - snames.push_back(*k); } snames.sort_custom<StringName::AlphCompare>(); for (List<StringName>::Element *F = snames.front(); F; F = F->next()) { - hash = hash_djb2_one_64(F->get().hash(), hash); hash = hash_djb2_one_64(t->constant_map[F->get()], hash); } @@ -456,14 +421,12 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { k = nullptr; while ((k = t->signal_map.next(k))) { - snames.push_back(*k); } snames.sort_custom<StringName::AlphCompare>(); for (List<StringName>::Element *F = snames.front(); F; F = F->next()) { - MethodInfo &mi = t->signal_map[F->get()]; hash = hash_djb2_one_64(F->get().hash(), hash); for (int i = 0; i < mi.arguments.size(); i++) { @@ -479,14 +442,12 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { k = nullptr; while ((k = t->property_setget.next(k))) { - snames.push_back(*k); } snames.sort_custom<StringName::AlphCompare>(); for (List<StringName>::Element *F = snames.front(); F; F = F->next()) { - PropertySetGet *psg = t->property_setget.getptr(F->get()); ERR_FAIL_COND_V(!psg, 0); @@ -498,7 +459,6 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { //property list for (List<PropertyInfo>::Element *F = t->property_list.front(); F; F = F->next()) { - hash = hash_djb2_one_64(F->get().name.hash(), hash); hash = hash_djb2_one_64(F->get().type, hash); hash = hash_djb2_one_64(F->get().hint, hash); @@ -514,19 +474,16 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { } bool ClassDB::class_exists(const StringName &p_class) { - OBJTYPE_RLOCK; return classes.has(p_class); } void ClassDB::add_compatibility_class(const StringName &p_class, const StringName &p_fallback) { - OBJTYPE_WLOCK; compat_classes[p_class] = p_fallback; } Object *ClassDB::instance(const StringName &p_class) { - ClassInfo *ti; { OBJTYPE_RLOCK; @@ -549,7 +506,6 @@ Object *ClassDB::instance(const StringName &p_class) { return ti->creation_func(); } bool ClassDB::can_instance(const StringName &p_class) { - OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); @@ -563,7 +519,6 @@ bool ClassDB::can_instance(const StringName &p_class) { } void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherits) { - OBJTYPE_WLOCK; const StringName &name = p_class; @@ -577,7 +532,6 @@ void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherit ti.api = current_api; if (ti.inherits) { - ERR_FAIL_COND(!classes.has(ti.inherits)); //it MUST be registered. ti.inherits_ptr = &classes[ti.inherits]; @@ -587,15 +541,12 @@ void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherit } void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, bool p_no_inheritance, bool p_exclude_from_properties) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); while (type) { - if (type->disabled) { - if (p_no_inheritance) break; @@ -606,12 +557,10 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b #ifdef DEBUG_METHODS_ENABLED for (List<MethodInfo>::Element *E = type->virtual_methods.front(); E; E = E->next()) { - p_methods->push_back(E->get()); } for (List<StringName>::Element *E = type->method_order.front(); E; E = E->next()) { - MethodBind *method = type->method_map.get(E->get()); MethodInfo minfo; minfo.name = E->get(); @@ -621,7 +570,6 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b continue; for (int i = 0; i < method->get_argument_count(); i++) { - //Variant::Type t=method->get_argument_type(i); minfo.arguments.push_back(method->get_argument_info(i)); @@ -643,7 +591,6 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b const StringName *K = nullptr; while ((K = type->method_map.next(K))) { - MethodBind *m = type->method_map[*K]; MethodInfo mi; mi.name = m->get_name(); @@ -660,13 +607,11 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b } MethodBind *ClassDB::get_method(StringName p_class, StringName p_name) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); while (type) { - MethodBind **method = type->method_map.getptr(p_name); if (method && *method) return *method; @@ -676,7 +621,6 @@ MethodBind *ClassDB::get_method(StringName p_class, StringName p_name) { } void ClassDB::bind_integer_constant(const StringName &p_class, const StringName &p_enum, const StringName &p_name, int p_constant) { - OBJTYPE_WLOCK; ClassInfo *type = classes.getptr(p_class); @@ -684,7 +628,6 @@ void ClassDB::bind_integer_constant(const StringName &p_class, const StringName ERR_FAIL_COND(!type); if (type->constant_map.has(p_name)) { - ERR_FAIL(); } @@ -713,13 +656,11 @@ void ClassDB::bind_integer_constant(const StringName &p_class, const StringName } void ClassDB::get_integer_constant_list(const StringName &p_class, List<String> *p_constants, bool p_no_inheritance) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); while (type) { - #ifdef DEBUG_METHODS_ENABLED for (List<StringName>::Element *E = type->constant_order.front(); E; E = E->next()) p_constants->push_back(E->get()); @@ -739,16 +680,13 @@ void ClassDB::get_integer_constant_list(const StringName &p_class, List<String> } int ClassDB::get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); while (type) { - int *constant = type->constant_map.getptr(p_name); if (constant) { - if (p_success) *p_success = true; return *constant; @@ -764,16 +702,13 @@ int ClassDB::get_integer_constant(const StringName &p_class, const StringName &p } StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); while (type) { - const StringName *k = nullptr; while ((k = type->enum_map.next(k))) { - List<StringName> &constants_list = type->enum_map.get(*k); const List<StringName>::Element *found = constants_list.find(p_name); if (found) @@ -790,13 +725,11 @@ StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const S } void ClassDB::get_enum_list(const StringName &p_class, List<StringName> *p_enums, bool p_no_inheritance) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); while (type) { - const StringName *k = nullptr; while ((k = type->enum_map.next(k))) { p_enums->push_back(*k); @@ -810,13 +743,11 @@ void ClassDB::get_enum_list(const StringName &p_class, List<StringName> *p_enums } void ClassDB::get_enum_constants(const StringName &p_class, const StringName &p_enum, List<StringName> *p_constants, bool p_no_inheritance) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); while (type) { - const List<StringName> *constants = type->enum_map.getptr(p_enum); if (constants) { @@ -833,7 +764,6 @@ void ClassDB::get_enum_constants(const StringName &p_class, const StringName &p_ } void ClassDB::add_signal(StringName p_class, const MethodInfo &p_signal) { - OBJTYPE_WLOCK; ClassInfo *type = classes.getptr(p_class); @@ -853,7 +783,6 @@ void ClassDB::add_signal(StringName p_class, const MethodInfo &p_signal) { } void ClassDB::get_signal_list(StringName p_class, List<MethodInfo> *p_signals, bool p_no_inheritance) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); @@ -862,10 +791,8 @@ void ClassDB::get_signal_list(StringName p_class, List<MethodInfo> *p_signals, b ClassInfo *check = type; while (check) { - const StringName *S = nullptr; while ((S = check->signal_map.next(S))) { - p_signals->push_back(check->signal_map[*S]); } @@ -877,7 +804,6 @@ void ClassDB::get_signal_list(StringName p_class, List<MethodInfo> *p_signals, b } bool ClassDB::has_signal(StringName p_class, StringName p_signal) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; @@ -891,7 +817,6 @@ bool ClassDB::has_signal(StringName p_class, StringName p_signal) { } bool ClassDB::get_signal(StringName p_class, StringName p_signal, MethodInfo *r_signal) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; @@ -909,7 +834,6 @@ bool ClassDB::get_signal(StringName p_class, StringName p_signal, MethodInfo *r_ } void ClassDB::add_property_group(StringName p_class, const String &p_name, const String &p_prefix) { - OBJTYPE_WLOCK; ClassInfo *type = classes.getptr(p_class); ERR_FAIL_COND(!type); @@ -918,7 +842,6 @@ void ClassDB::add_property_group(StringName p_class, const String &p_name, const } void ClassDB::add_property_subgroup(StringName p_class, const String &p_name, const String &p_prefix) { - OBJTYPE_WLOCK; ClassInfo *type = classes.getptr(p_class); ERR_FAIL_COND(!type); @@ -927,7 +850,6 @@ void ClassDB::add_property_subgroup(StringName p_class, const String &p_name, co } void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index) { - lock->read_lock(); ClassInfo *type = classes.getptr(p_class); lock->read_unlock(); @@ -948,7 +870,6 @@ void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, cons MethodBind *mb_get = nullptr; if (p_getter) { - mb_get = get_method(p_class, p_getter); #ifdef DEBUG_METHODS_ENABLED @@ -993,15 +914,12 @@ void ClassDB::set_property_default_value(StringName p_class, const StringName &p } void ClassDB::get_property_list(StringName p_class, List<PropertyInfo> *p_list, bool p_no_inheritance, const Object *p_validator) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { - for (List<PropertyInfo>::Element *E = check->property_list.front(); E; E = E->next()) { - if (p_validator) { PropertyInfo pi = E->get(); p_validator->_validate_property(pi); @@ -1017,13 +935,11 @@ void ClassDB::get_property_list(StringName p_class, List<PropertyInfo> *p_list, } } bool ClassDB::set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid) { - ClassInfo *type = classes.getptr(p_object->get_class_name()); ClassInfo *check = type; while (check) { const PropertySetGet *psg = check->property_setget.getptr(p_property); if (psg) { - if (!psg->setter) { if (r_valid) *r_valid = false; @@ -1063,7 +979,6 @@ bool ClassDB::set_property(Object *p_object, const StringName &p_property, const return false; } bool ClassDB::get_property(Object *p_object, const StringName &p_property, Variant &r_value) { - ClassInfo *type = classes.getptr(p_object->get_class_name()); ClassInfo *check = type; while (check) { @@ -1079,10 +994,8 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia r_value = p_object->call(psg->getter, arg, 1, ce); } else { - Callable::CallError ce; if (psg->_getptr) { - r_value = psg->_getptr->call(p_object, nullptr, 0, ce); } else { r_value = p_object->call(psg->getter, nullptr, 0, ce); @@ -1093,7 +1006,6 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia const int *c = check->constant_map.getptr(p_property); //constants count if (c) { - r_value = *c; return true; } @@ -1115,13 +1027,11 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia } int ClassDB::get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid) { - ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { const PropertySetGet *psg = check->property_setget.getptr(p_property); if (psg) { - if (r_is_valid) *r_is_valid = true; @@ -1137,13 +1047,11 @@ int ClassDB::get_property_index(const StringName &p_class, const StringName &p_p } Variant::Type ClassDB::get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid) { - ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { const PropertySetGet *psg = check->property_setget.getptr(p_property); if (psg) { - if (r_is_valid) *r_is_valid = true; @@ -1159,13 +1067,11 @@ Variant::Type ClassDB::get_property_type(const StringName &p_class, const String } StringName ClassDB::get_property_setter(StringName p_class, const StringName &p_property) { - ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { const PropertySetGet *psg = check->property_setget.getptr(p_property); if (psg) { - return psg->setter; } @@ -1176,13 +1082,11 @@ StringName ClassDB::get_property_setter(StringName p_class, const StringName &p_ } StringName ClassDB::get_property_getter(StringName p_class, const StringName &p_property) { - ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { const PropertySetGet *psg = check->property_setget.getptr(p_property); if (psg) { - return psg->getter; } @@ -1193,7 +1097,6 @@ StringName ClassDB::get_property_getter(StringName p_class, const StringName &p_ } bool ClassDB::has_property(const StringName &p_class, const StringName &p_property, bool p_no_inheritance) { - ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { @@ -1209,7 +1112,6 @@ bool ClassDB::has_property(const StringName &p_class, const StringName &p_proper } void ClassDB::set_method_flags(StringName p_class, StringName p_method, int p_flags) { - OBJTYPE_WLOCK; ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; @@ -1219,7 +1121,6 @@ void ClassDB::set_method_flags(StringName p_class, StringName p_method, int p_fl } bool ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inheritance) { - ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { @@ -1282,7 +1183,6 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const c defvals.resize(p_defcount); for (int i = 0; i < p_defcount; i++) { - defvals.write[i] = *p_defs[p_defcount - i - 1]; } @@ -1306,7 +1206,6 @@ void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_ } void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance) { - ERR_FAIL_COND_MSG(!classes.has(p_class), "Request for nonexistent class '" + p_class + "'."); #ifdef DEBUG_METHODS_ENABLED @@ -1314,7 +1213,6 @@ void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { - for (List<MethodInfo>::Element *E = check->virtual_methods.front(); E; E = E->next()) { p_methods->push_back(E->get()); } @@ -1328,7 +1226,6 @@ void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p } void ClassDB::set_class_enabled(StringName p_class, bool p_enable) { - OBJTYPE_WLOCK; ERR_FAIL_COND_MSG(!classes.has(p_class), "Request for nonexistent class '" + p_class + "'."); @@ -1336,7 +1233,6 @@ void ClassDB::set_class_enabled(StringName p_class, bool p_enable) { } bool ClassDB::is_class_enabled(StringName p_class) { - OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); @@ -1351,7 +1247,6 @@ bool ClassDB::is_class_enabled(StringName p_class) { } bool ClassDB::is_class_exposed(StringName p_class) { - OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); @@ -1360,7 +1255,6 @@ bool ClassDB::is_class_exposed(StringName p_class) { } StringName ClassDB::get_category(const StringName &p_node) { - ERR_FAIL_COND_V(!classes.has(p_node), StringName()); #ifdef DEBUG_ENABLED return classes[p_node].category; @@ -1370,7 +1264,6 @@ StringName ClassDB::get_category(const StringName &p_node) { } void ClassDB::add_resource_base_extension(const StringName &p_extension, const StringName &p_class) { - if (resource_base_extensions.has(p_extension)) return; @@ -1378,17 +1271,14 @@ void ClassDB::add_resource_base_extension(const StringName &p_extension, const S } void ClassDB::get_resource_base_extensions(List<String> *p_extensions) { - const StringName *K = nullptr; while ((K = resource_base_extensions.next(K))) { - p_extensions->push_back(*K); } } void ClassDB::get_extensions_for_type(const StringName &p_class, List<String> *p_extensions) { - const StringName *K = nullptr; while ((K = resource_base_extensions.next(K))) { @@ -1402,9 +1292,7 @@ HashMap<StringName, HashMap<StringName, Variant>> ClassDB::default_values; Set<StringName> ClassDB::default_values_cached; Variant ClassDB::class_get_default_property_value(const StringName &p_class, const StringName &p_property, bool *r_valid) { - if (!default_values_cached.has(p_class)) { - if (!default_values.has(p_class)) { default_values[p_class] = HashMap<StringName, Variant>(); } @@ -1421,12 +1309,10 @@ Variant ClassDB::class_get_default_property_value(const StringName &p_class, con } if (c) { - List<PropertyInfo> plist; c->get_property_list(&plist); for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { if (E->get().usage & (PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR)) { - if (!default_values[p_class].has(E->get().name)) { Variant v = c->get(E->get().name); default_values[p_class][E->get().name] = v; @@ -1462,29 +1348,24 @@ Variant ClassDB::class_get_default_property_value(const StringName &p_class, con RWLock *ClassDB::lock = nullptr; void ClassDB::init() { - lock = RWLock::create(); } void ClassDB::cleanup_defaults() { - default_values.clear(); default_values_cached.clear(); } void ClassDB::cleanup() { - //OBJTYPE_LOCK; hah not here const StringName *k = nullptr; while ((k = classes.next(k))) { - ClassInfo &ti = classes[*k]; const StringName *m = nullptr; while ((m = ti.method_map.next(m))) { - memdelete(ti.method_map[*m]); } } diff --git a/core/class_db.h b/core/class_db.h index 32d2148048..eae2a9afd4 100644 --- a/core/class_db.h +++ b/core/class_db.h @@ -48,7 +48,6 @@ #ifdef DEBUG_METHODS_ENABLED struct MethodDefinition { - StringName name; Vector<StringName> args; MethodDefinition() {} @@ -103,7 +102,6 @@ public: public: struct PropertySetGet { - int index; StringName setter; StringName getter; @@ -113,7 +111,6 @@ public: }; struct ClassInfo { - APIType api = API_NONE; ClassInfo *inherits_ptr = nullptr; void *class_ptr = nullptr; @@ -169,13 +166,11 @@ public: // DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!! template <class T> static void _add_class() { - _add_class2(T::get_class_static(), T::get_parent_class_static()); } template <class T> static void register_class() { - GLOBAL_LOCK_FUNCTION; T::initialize_class(); ClassInfo *t = classes.getptr(T::get_class_static()); @@ -188,7 +183,6 @@ public: template <class T> static void register_virtual_class() { - GLOBAL_LOCK_FUNCTION; T::initialize_class(); ClassInfo *t = classes.getptr(T::get_class_static()); @@ -200,13 +194,11 @@ public: template <class T> static Object *_create_ptr_func() { - return T::create(); } template <class T> static void register_custom_instance_class() { - GLOBAL_LOCK_FUNCTION; T::initialize_class(); ClassInfo *t = classes.getptr(T::get_class_static()); @@ -233,7 +225,6 @@ public: template <class N, class M> static MethodBind *bind_method(N p_method_name, M p_method) { - MethodBind *bind = create_method_bind(p_method); return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, nullptr, 0); //use static function, much smaller binary usage @@ -241,7 +232,6 @@ public: template <class N, class M> static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1) { - MethodBind *bind = create_method_bind(p_method); const Variant *ptr[1] = { &p_def1 }; @@ -250,7 +240,6 @@ public: template <class N, class M> static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2) { - MethodBind *bind = create_method_bind(p_method); const Variant *ptr[2] = { &p_def1, &p_def2 }; @@ -259,7 +248,6 @@ public: template <class N, class M> static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3) { - MethodBind *bind = create_method_bind(p_method); const Variant *ptr[3] = { &p_def1, &p_def2, &p_def3 }; @@ -268,7 +256,6 @@ public: template <class N, class M> static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4) { - MethodBind *bind = create_method_bind(p_method); const Variant *ptr[4] = { &p_def1, &p_def2, &p_def3, &p_def4 }; @@ -277,7 +264,6 @@ public: template <class N, class M> static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5) { - MethodBind *bind = create_method_bind(p_method); const Variant *ptr[5] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5 }; @@ -286,7 +272,6 @@ public: template <class N, class M> static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5, const Variant &p_def6) { - MethodBind *bind = create_method_bind(p_method); const Variant *ptr[6] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6 }; @@ -295,7 +280,6 @@ public: template <class N, class M> static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5, const Variant &p_def6, const Variant &p_def7) { - MethodBind *bind = create_method_bind(p_method); const Variant *ptr[7] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6, &p_def7 }; @@ -304,7 +288,6 @@ public: template <class N, class M> static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5, const Variant &p_def6, const Variant &p_def7, const Variant &p_def8) { - MethodBind *bind = create_method_bind(p_method); const Variant *ptr[8] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6, &p_def7, &p_def8 }; @@ -313,7 +296,6 @@ public: template <class M> static MethodBind *bind_vararg_method(uint32_t p_flags, StringName p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const Vector<Variant> &p_default_args = Vector<Variant>(), bool p_return_nil_is_variant = true) { - GLOBAL_LOCK_FUNCTION; MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant); diff --git a/core/color.cpp b/core/color.cpp index 79b9f70a99..328b2e3568 100644 --- a/core/color.cpp +++ b/core/color.cpp @@ -36,7 +36,6 @@ #include "core/print_string.h" uint32_t Color::to_argb32() const { - uint32_t c = (uint8_t)Math::round(a * 255); c <<= 8; c |= (uint8_t)Math::round(r * 255); @@ -49,7 +48,6 @@ uint32_t Color::to_argb32() const { } uint32_t Color::to_abgr32() const { - uint32_t c = (uint8_t)Math::round(a * 255); c <<= 8; c |= (uint8_t)Math::round(b * 255); @@ -62,7 +60,6 @@ uint32_t Color::to_abgr32() const { } uint32_t Color::to_rgba32() const { - uint32_t c = (uint8_t)Math::round(r * 255); c <<= 8; c |= (uint8_t)Math::round(g * 255); @@ -75,7 +72,6 @@ uint32_t Color::to_rgba32() const { } uint64_t Color::to_abgr64() const { - uint64_t c = (uint16_t)Math::round(a * 65535); c <<= 16; c |= (uint16_t)Math::round(b * 65535); @@ -88,7 +84,6 @@ uint64_t Color::to_abgr64() const { } uint64_t Color::to_argb64() const { - uint64_t c = (uint16_t)Math::round(a * 65535); c <<= 16; c |= (uint16_t)Math::round(r * 65535); @@ -101,7 +96,6 @@ uint64_t Color::to_argb64() const { } uint64_t Color::to_rgba64() const { - uint64_t c = (uint16_t)Math::round(r * 65535); c <<= 16; c |= (uint16_t)Math::round(g * 65535); @@ -114,7 +108,6 @@ uint64_t Color::to_rgba64() const { } float Color::get_h() const { - float min = MIN(r, g); min = MIN(min, b); float max = MAX(r, g); @@ -141,7 +134,6 @@ float Color::get_h() const { } float Color::get_s() const { - float min = MIN(r, g); min = MIN(min, b); float max = MAX(r, g); @@ -153,14 +145,12 @@ float Color::get_s() const { } float Color::get_v() const { - float max = MAX(r, g); max = MAX(max, b); return max; } void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) { - int i; float f, p, q, t; a = p_alpha; @@ -215,25 +205,21 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) { } bool Color::is_equal_approx(const Color &p_color) const { - return Math::is_equal_approx(r, p_color.r) && Math::is_equal_approx(g, p_color.g) && Math::is_equal_approx(b, p_color.b) && Math::is_equal_approx(a, p_color.a); } void Color::invert() { - r = 1.0 - r; g = 1.0 - g; b = 1.0 - b; } void Color::contrast() { - r = Math::fmod(r + 0.5, 1.0); g = Math::fmod(g + 0.5, 1.0); b = Math::fmod(b + 0.5, 1.0); } Color Color::hex(uint32_t p_hex) { - float a = (p_hex & 0xFF) / 255.0; p_hex >>= 8; float b = (p_hex & 0xFF) / 255.0; @@ -246,7 +232,6 @@ Color Color::hex(uint32_t p_hex) { } Color Color::hex64(uint64_t p_hex) { - float a = (p_hex & 0xFFFF) / 65535.0; p_hex >>= 16; float b = (p_hex & 0xFFFF) / 65535.0; @@ -259,7 +244,6 @@ Color Color::hex64(uint64_t p_hex) { } Color Color::from_rgbe9995(uint32_t p_rgbe) { - float r = p_rgbe & 0x1ff; float g = (p_rgbe >> 9) & 0x1ff; float b = (p_rgbe >> 18) & 0x1ff; @@ -274,11 +258,9 @@ Color Color::from_rgbe9995(uint32_t p_rgbe) { } static float _parse_col(const String &p_str, int p_ofs) { - int ig = 0; for (int i = 0; i < 2; i++) { - int c = p_str[i + p_ofs]; int v = 0; @@ -304,21 +286,18 @@ static float _parse_col(const String &p_str, int p_ofs) { } Color Color::inverted() const { - Color c = *this; c.invert(); return c; } Color Color::contrasted() const { - Color c = *this; c.contrast(); return c; } Color Color::html(const String &p_color) { - String color = p_color; if (color.length() == 0) return Color(); @@ -362,7 +341,6 @@ Color Color::html(const String &p_color) { } bool Color::html_is_valid(const String &p_color) { - String color = p_color; if (color.length() == 0) @@ -423,13 +401,11 @@ Color Color::named(const String &p_name) { } String _to_hex(float p_val) { - int v = Math::round(p_val * 255); v = CLAMP(v, 0, 255); String ret; for (int i = 0; i < 2; i++) { - CharType c[2] = { 0, 0 }; int lv = v & 0xF; if (lv < 10) @@ -446,7 +422,6 @@ String _to_hex(float p_val) { } String Color::to_html(bool p_alpha) const { - String txt; txt += _to_hex(r); txt += _to_hex(g); @@ -457,7 +432,6 @@ String Color::to_html(bool p_alpha) const { } Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) const { - p_h = Math::fmod(p_h * 360.0f, 360.0f); if (p_h < 0.0) p_h += 360.0f; @@ -510,12 +484,10 @@ Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) const { } Color::operator String() const { - return rtos(r) + ", " + rtos(g) + ", " + rtos(b) + ", " + rtos(a); } Color Color::operator+(const Color &p_color) const { - return Color( r + p_color.r, g + p_color.g, @@ -524,7 +496,6 @@ Color Color::operator+(const Color &p_color) const { } Color Color::operator-(const Color &p_color) const { - return Color( r - p_color.r, g - p_color.g, @@ -533,7 +504,6 @@ Color Color::operator-(const Color &p_color) const { } void Color::operator-=(const Color &p_color) { - r = r - p_color.r; g = g - p_color.g; b = b - p_color.b; @@ -541,7 +511,6 @@ void Color::operator-=(const Color &p_color) { } Color Color::operator*(const Color &p_color) const { - return Color( r * p_color.r, g * p_color.g, @@ -550,7 +519,6 @@ Color Color::operator*(const Color &p_color) const { } Color Color::operator*(const real_t &rvalue) const { - return Color( r * rvalue, g * rvalue, @@ -559,7 +527,6 @@ Color Color::operator*(const real_t &rvalue) const { } void Color::operator*=(const Color &p_color) { - r = r * p_color.r; g = g * p_color.g; b = b * p_color.b; @@ -567,7 +534,6 @@ void Color::operator*=(const Color &p_color) { } void Color::operator*=(const real_t &rvalue) { - r = r * rvalue; g = g * rvalue; b = b * rvalue; @@ -575,7 +541,6 @@ void Color::operator*=(const real_t &rvalue) { } Color Color::operator/(const Color &p_color) const { - return Color( r / p_color.r, g / p_color.g, @@ -584,7 +549,6 @@ Color Color::operator/(const Color &p_color) const { } Color Color::operator/(const real_t &rvalue) const { - return Color( r / rvalue, g / rvalue, @@ -593,7 +557,6 @@ Color Color::operator/(const real_t &rvalue) const { } void Color::operator/=(const Color &p_color) { - r = r / p_color.r; g = g / p_color.g; b = b / p_color.b; @@ -601,7 +564,6 @@ void Color::operator/=(const Color &p_color) { } void Color::operator/=(const real_t &rvalue) { - if (rvalue == 0) { r = 1.0; g = 1.0; @@ -616,7 +578,6 @@ void Color::operator/=(const real_t &rvalue) { }; Color Color::operator-() const { - return Color( 1.0 - r, 1.0 - g, diff --git a/core/color.h b/core/color.h index 066a3f6696..10d49f3cad 100644 --- a/core/color.h +++ b/core/color.h @@ -35,9 +35,7 @@ #include "core/ustring.h" struct Color { - union { - struct { float r; float g; @@ -98,7 +96,6 @@ struct Color { Color contrasted() const; _FORCE_INLINE_ Color lerp(const Color &p_b, float p_t) const { - Color res = *this; res.r += (p_t * (p_b.r - r)); @@ -110,7 +107,6 @@ struct Color { } _FORCE_INLINE_ Color darkened(float p_amount) const { - Color res = *this; res.r = res.r * (1.0f - p_amount); res.g = res.g * (1.0f - p_amount); @@ -119,7 +115,6 @@ struct Color { } _FORCE_INLINE_ Color lightened(float p_amount) const { - Color res = *this; res.r = res.r + (1.0f - res.r) * p_amount; res.g = res.g + (1.0f - res.g) * p_amount; @@ -128,7 +123,6 @@ struct Color { } _FORCE_INLINE_ uint32_t to_rgbe9995() const { - const float pow2to9 = 512.0f; const float B = 15.0f; //const float Emax = 31.0f; @@ -162,7 +156,6 @@ struct Color { } _FORCE_INLINE_ Color blend(const Color &p_over) const { - Color res; float sa = 1.0 - p_over.a; res.a = a * sa + p_over.a; @@ -177,7 +170,6 @@ struct Color { } _FORCE_INLINE_ Color to_linear() const { - return Color( r < 0.04045 ? r * (1.0 / 12.92) : Math::pow((r + 0.055) * (1.0 / (1 + 0.055)), 2.4), g < 0.04045 ? g * (1.0 / 12.92) : Math::pow((g + 0.055) * (1.0 / (1 + 0.055)), 2.4), @@ -185,7 +177,6 @@ struct Color { a); } _FORCE_INLINE_ Color to_srgb() const { - return Color( r < 0.0031308 ? 12.92 * r : (1.0 + 0.055) * Math::pow(r, 1.0f / 2.4f) - 0.055, g < 0.0031308 ? 12.92 * g : (1.0 + 0.055) * Math::pow(g, 1.0f / 2.4f) - 0.055, @@ -228,7 +219,6 @@ struct Color { }; bool Color::operator<(const Color &p_color) const { - if (r == p_color.r) { if (g == p_color.g) { if (b == p_color.b) { diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp index 60ab5d133b..d23a6425e3 100644 --- a/core/command_queue_mt.cpp +++ b/core/command_queue_mt.cpp @@ -33,30 +33,24 @@ #include "core/os/os.h" void CommandQueueMT::lock() { - mutex.lock(); } void CommandQueueMT::unlock() { - mutex.unlock(); } void CommandQueueMT::wait_for_flush() { - // wait one millisecond for a flush to happen OS::get_singleton()->delay_usec(1000); } CommandQueueMT::SyncSemaphore *CommandQueueMT::_alloc_sync_sem() { - int idx = -1; while (true) { - lock(); for (int i = 0; i < SYNC_SEMAPHORES; i++) { - if (!sync_sems[i].in_use) { sync_sems[i].in_use = true; idx = i; diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h index af8bbb24c6..d40005fb12 100644 --- a/core/command_queue_mt.h +++ b/core/command_queue_mt.h @@ -297,22 +297,18 @@ #define MAX_CMD_PARAMS 15 class CommandQueueMT { - struct SyncSemaphore { - Semaphore sem; bool in_use = false; }; struct CommandBase { - virtual void call() = 0; virtual void post() {} virtual ~CommandBase() {} }; struct SyncCommand : public CommandBase { - SyncSemaphore *sync_sem; virtual void post() { @@ -349,7 +345,6 @@ class CommandQueueMT { template <class T> T *allocate() { - // alloc size is size+T+safeguard uint32_t alloc_size = ((sizeof(T) + 8 - 1) & ~(8 - 1)) + 8; @@ -358,7 +353,6 @@ class CommandQueueMT { if (write_ptr < dealloc_ptr) { // behind dealloc_ptr, check that there is room if ((dealloc_ptr - write_ptr) <= alloc_size) { - // There is no more room, try to deallocate something if (dealloc_one()) { goto tryagain; @@ -405,12 +399,10 @@ class CommandQueueMT { template <class T> T *allocate_and_lock() { - lock(); T *ret; while ((ret = allocate<T>()) == nullptr) { - unlock(); // sleep a little until fetch happened and some room is made wait_for_flush(); @@ -488,7 +480,6 @@ public: } void flush_all() { - //ERR_FAIL_COND(sync); lock(); while (flush_one(false)) diff --git a/core/compressed_translation.cpp b/core/compressed_translation.cpp index 9e6ba6cde2..89e738e596 100644 --- a/core/compressed_translation.cpp +++ b/core/compressed_translation.cpp @@ -37,7 +37,6 @@ extern "C" { } struct _PHashTranslationCmp { - int orig_len; CharString compressed; int offset; @@ -65,7 +64,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) { int total_string_size = 0; for (List<StringName>::Element *E = keys.front(); E; E = E->next()) { - //hash string CharString cs = E->get().operator String().utf8(); uint32_t h = hash(0, cs.get_data()); @@ -108,7 +106,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) { int bucket_table_size = 0; for (int i = 0; i < size; i++) { - const Vector<Pair<int, CharString>> &b = buckets[i]; Map<uint32_t, int> &t = table.write[i]; @@ -119,10 +116,8 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) { int item = 0; while (item < b.size()) { - uint32_t slot = hash(d, b[item].second.get_data()); if (t.has(slot)) { - item = 0; d++; t.clear(); @@ -151,7 +146,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) { int collisions = 0; for (int i = 0; i < size; i++) { - const Map<uint32_t, int> &t = table[i]; if (t.size() == 0) { htw[i] = 0xFFFFFFFF; //nothing @@ -165,7 +159,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) { btw[btindex++] = hfunc_table[i]; for (Map<uint32_t, int>::Element *E = t.front(); E; E = E->next()) { - btw[btindex++] = E->key(); btw[btindex++] = compressed[E->get()].offset; btw[btindex++] = compressed[E->get()].compressed.size(); @@ -187,7 +180,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) { } bool PHashTranslation::_set(const StringName &p_name, const Variant &p_value) { - String name = p_name.operator String(); if (name == "hash_table") { hash_table = p_value; @@ -204,7 +196,6 @@ bool PHashTranslation::_set(const StringName &p_name, const Variant &p_value) { } bool PHashTranslation::_get(const StringName &p_name, Variant &r_ret) const { - String name = p_name.operator String(); if (name == "hash_table") r_ret = hash_table; @@ -219,7 +210,6 @@ bool PHashTranslation::_get(const StringName &p_name, Variant &r_ret) const { } StringName PHashTranslation::get_message(const StringName &p_src_text) const { - int htsize = hash_table.size(); if (htsize == 0) @@ -248,9 +238,7 @@ StringName PHashTranslation::get_message(const StringName &p_src_text) const { int idx = -1; for (int i = 0; i < bucket.size; i++) { - if (bucket.elem[i].key == h) { - idx = i; break; } @@ -261,13 +249,11 @@ StringName PHashTranslation::get_message(const StringName &p_src_text) const { } if (bucket.elem[idx].comp_size == bucket.elem[idx].uncomp_size) { - String rstr; rstr.parse_utf8(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].uncomp_size); return rstr; } else { - CharString uncomp; uncomp.resize(bucket.elem[idx].uncomp_size + 1); smaz_decompress(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].comp_size, uncomp.ptrw(), bucket.elem[idx].uncomp_size); @@ -278,13 +264,11 @@ StringName PHashTranslation::get_message(const StringName &p_src_text) const { } void PHashTranslation::_get_property_list(List<PropertyInfo> *p_list) const { - p_list->push_back(PropertyInfo(Variant::PACKED_INT32_ARRAY, "hash_table")); p_list->push_back(PropertyInfo(Variant::PACKED_INT32_ARRAY, "bucket_table")); p_list->push_back(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "strings")); p_list->push_back(PropertyInfo(Variant::OBJECT, "load_from", PROPERTY_HINT_RESOURCE_TYPE, "Translation", PROPERTY_USAGE_EDITOR)); } void PHashTranslation::_bind_methods() { - ClassDB::bind_method(D_METHOD("generate", "from"), &PHashTranslation::generate); } diff --git a/core/compressed_translation.h b/core/compressed_translation.h index fff4350caa..032e391729 100644 --- a/core/compressed_translation.h +++ b/core/compressed_translation.h @@ -34,7 +34,6 @@ #include "core/translation.h" class PHashTranslation : public Translation { - GDCLASS(PHashTranslation, Translation); //this translation uses a sort of modified perfect hash algorithm @@ -48,12 +47,10 @@ class PHashTranslation : public Translation { Vector<uint8_t> strings; struct Bucket { - int size; uint32_t func; struct Elem { - uint32_t key; uint32_t str_offset; uint32_t comp_size; @@ -64,11 +61,9 @@ class PHashTranslation : public Translation { }; _FORCE_INLINE_ uint32_t hash(uint32_t d, const char *p_str) const { - if (d == 0) d = 0x1000193; while (*p_str) { - d = (d * 0x1000193) ^ uint32_t(*p_str); p_str++; } diff --git a/core/container_type_validate.h b/core/container_type_validate.h index 7809e5f385..f2724e884d 100644 --- a/core/container_type_validate.h +++ b/core/container_type_validate.h @@ -35,7 +35,6 @@ #include "core/variant.h" struct ContainerTypeValidate { - Variant::Type type = Variant::NIL; StringName class_name; Ref<Script> script; @@ -76,7 +75,6 @@ struct ContainerTypeValidate { } _FORCE_INLINE_ bool validate(const Variant &p_variant, const char *p_operation = "use") { - if (type == Variant::NIL) { return true; } diff --git a/core/core_string_names.h b/core/core_string_names.h index 2ade44f4e0..1a18c84572 100644 --- a/core/core_string_names.h +++ b/core/core_string_names.h @@ -34,7 +34,6 @@ #include "core/string_name.h" class CoreStringNames { - friend void register_core_types(); friend void unregister_core_types(); diff --git a/core/cowdata.h b/core/cowdata.h index b63a407511..72a76d735d 100644 --- a/core/cowdata.h +++ b/core/cowdata.h @@ -59,7 +59,6 @@ private: // internal helpers _FORCE_INLINE_ uint32_t *_get_refcount() const { - if (!_ptr) return nullptr; @@ -67,7 +66,6 @@ private: } _FORCE_INLINE_ uint32_t *_get_size() const { - if (!_ptr) return nullptr; @@ -75,7 +73,6 @@ private: } _FORCE_INLINE_ T *_get_data() const { - if (!_ptr) return nullptr; return reinterpret_cast<T *>(_ptr); @@ -135,21 +132,18 @@ public: _FORCE_INLINE_ bool empty() const { return _ptr == nullptr; } _FORCE_INLINE_ void set(int p_index, const T &p_elem) { - CRASH_BAD_INDEX(p_index, size()); _copy_on_write(); _get_data()[p_index] = p_elem; } _FORCE_INLINE_ T &get_m(int p_index) { - CRASH_BAD_INDEX(p_index, size()); _copy_on_write(); return _get_data()[p_index]; } _FORCE_INLINE_ const T &get(int p_index) const { - CRASH_BAD_INDEX(p_index, size()); return _get_data()[p_index]; @@ -158,12 +152,10 @@ public: Error resize(int p_size); _FORCE_INLINE_ void remove(int p_index) { - ERR_FAIL_INDEX(p_index, size()); T *p = ptrw(); int len = size(); for (int i = p_index; i < len - 1; i++) { - p[i] = p[i + 1]; }; @@ -171,7 +163,6 @@ public: }; Error insert(int p_pos, const T &p_val) { - ERR_FAIL_INDEX_V(p_pos, size() + 1, ERR_INVALID_PARAMETER); resize(size() + 1); for (int i = (size() - 1); i > p_pos; i--) @@ -190,7 +181,6 @@ public: template <class T> void CowData<T>::_unref(void *p_data) { - if (!p_data) return; @@ -216,7 +206,6 @@ void CowData<T>::_unref(void *p_data) { template <class T> void CowData<T>::_copy_on_write() { - if (!_ptr) return; @@ -250,7 +239,6 @@ void CowData<T>::_copy_on_write() { template <class T> Error CowData<T>::resize(int p_size) { - ERR_FAIL_COND_V(p_size < 0, ERR_INVALID_PARAMETER); int current_size = size(); @@ -273,7 +261,6 @@ Error CowData<T>::resize(int p_size) { ERR_FAIL_COND_V(!_get_alloc_size_checked(p_size, &alloc_size), ERR_OUT_OF_MEMORY); if (p_size > current_size) { - if (alloc_size != current_alloc_size) { if (current_size == 0) { // alloc from scratch @@ -304,7 +291,6 @@ Error CowData<T>::resize(int p_size) { *_get_size() = p_size; } else if (p_size < current_size) { - if (!__has_trivial_destructor(T)) { // deinitialize no longer needed elements for (uint32_t i = p_size; i < *_get_size(); i++) { @@ -351,7 +337,6 @@ void CowData<T>::_ref(const CowData *p_from) { template <class T> void CowData<T>::_ref(const CowData &p_from) { - if (_ptr == p_from._ptr) return; // self assign, do nothing. @@ -368,7 +353,6 @@ void CowData<T>::_ref(const CowData &p_from) { template <class T> CowData<T>::~CowData() { - _unref(_ptr); } diff --git a/core/crypto/crypto.cpp b/core/crypto/crypto.cpp index 585731ac9f..60db329e64 100644 --- a/core/crypto/crypto.cpp +++ b/core/crypto/crypto.cpp @@ -71,7 +71,6 @@ Crypto *Crypto::create() { } void Crypto::load_default_certificates(String p_path) { - if (_load_default_certificates) _load_default_certificates(p_path); } @@ -97,7 +96,6 @@ Ref<X509Certificate> Crypto::generate_self_signed_certificate(Ref<CryptoKey> p_k /// Resource loader/saver RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - String el = p_path.get_extension().to_lower(); if (el == "crt") { X509Certificate *cert = X509Certificate::create(); @@ -114,18 +112,15 @@ RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_origi } void ResourceFormatLoaderCrypto::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("crt"); p_extensions->push_back("key"); } bool ResourceFormatLoaderCrypto::handles_type(const String &p_type) const { - return p_type == "X509Certificate" || p_type == "CryptoKey"; } String ResourceFormatLoaderCrypto::get_resource_type(const String &p_path) const { - String el = p_path.get_extension().to_lower(); if (el == "crt") return "X509Certificate"; @@ -135,7 +130,6 @@ String ResourceFormatLoaderCrypto::get_resource_type(const String &p_path) const } Error ResourceFormatSaverCrypto::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - Error err; Ref<X509Certificate> cert = p_resource; Ref<CryptoKey> key = p_resource; @@ -151,7 +145,6 @@ Error ResourceFormatSaverCrypto::save(const String &p_path, const RES &p_resourc } void ResourceFormatSaverCrypto::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { - const X509Certificate *cert = Object::cast_to<X509Certificate>(*p_resource); const CryptoKey *key = Object::cast_to<CryptoKey>(*p_resource); if (cert) { @@ -162,6 +155,5 @@ void ResourceFormatSaverCrypto::get_recognized_extensions(const RES &p_resource, } } bool ResourceFormatSaverCrypto::recognize(const RES &p_resource) const { - return Object::cast_to<X509Certificate>(*p_resource) || Object::cast_to<CryptoKey>(*p_resource); } diff --git a/core/crypto/crypto_core.h b/core/crypto/crypto_core.h index b3be58e8ee..36d8ace723 100644 --- a/core/crypto/crypto_core.h +++ b/core/crypto/crypto_core.h @@ -34,10 +34,8 @@ #include "core/reference.h" class CryptoCore { - public: class MD5Context { - private: void *ctx; // To include, or not to include... @@ -51,7 +49,6 @@ public: }; class SHA1Context { - private: void *ctx; // To include, or not to include... @@ -65,7 +62,6 @@ public: }; class SHA256Context { - private: void *ctx; // To include, or not to include... @@ -79,7 +75,6 @@ public: }; class AESContext { - private: void *ctx; // To include, or not to include... diff --git a/core/crypto/hashing_context.cpp b/core/crypto/hashing_context.cpp index 0b21dead74..726dc615df 100644 --- a/core/crypto/hashing_context.cpp +++ b/core/crypto/hashing_context.cpp @@ -104,7 +104,6 @@ void HashingContext::_create_ctx(HashType p_type) { } void HashingContext::_delete_ctx() { - switch (type) { case HASH_MD5: memdelete((CryptoCore::MD5Context *)ctx); diff --git a/core/debugger/debugger_marshalls.h b/core/debugger/debugger_marshalls.h index 9ba316d997..7b7f4ac4b5 100644 --- a/core/debugger/debugger_marshalls.h +++ b/core/debugger/debugger_marshalls.h @@ -35,7 +35,6 @@ #include "servers/rendering_server.h" struct DebuggerMarshalls { - // Memory usage struct ResourceInfo { String path; diff --git a/core/debugger/engine_debugger.cpp b/core/debugger/engine_debugger.cpp index 04eba84b30..19ac87ad8b 100644 --- a/core/debugger/engine_debugger.cpp +++ b/core/debugger/engine_debugger.cpp @@ -162,7 +162,6 @@ void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Ve singleton_script_debugger->set_skip_breakpoints(p_skip_breakpoints); for (int i = 0; i < p_breakpoints.size(); i++) { - String bp = p_breakpoints[i]; int sp = bp.find_last(":"); ERR_CONTINUE_MSG(sp == -1, "Invalid breakpoint: '" + bp + "', expected file:line format."); diff --git a/core/debugger/local_debugger.cpp b/core/debugger/local_debugger.cpp index 6d88ceb2c1..9251b77f96 100644 --- a/core/debugger/local_debugger.cpp +++ b/core/debugger/local_debugger.cpp @@ -36,7 +36,6 @@ struct LocalDebugger::ScriptsProfiler { struct ProfileInfoSort { - bool operator()(const ScriptLanguage::ProfilingInfo &A, const ScriptLanguage::ProfilingInfo &B) const { return A.total_time > B.total_time; } @@ -89,7 +88,6 @@ struct LocalDebugger::ScriptsProfiler { // compute total script frame time uint64_t script_time_us = 0; for (int i = 0; i < ofs; i++) { - script_time_us += pinfo[i].self_time; } float script_time = USEC_TO_SEC(script_time_us); @@ -102,7 +100,6 @@ struct LocalDebugger::ScriptsProfiler { } for (int i = 0; i < ofs; i++) { - print_line(itos(i) + ":" + pinfo[i].signature); float tt = USEC_TO_SEC(pinfo[i].total_time); float st = USEC_TO_SEC(pinfo[i].self_time); @@ -116,7 +113,6 @@ struct LocalDebugger::ScriptsProfiler { }; void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { - ScriptLanguage *script_lang = script_debugger->get_break_language(); if (!target_function.empty()) { @@ -135,7 +131,6 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { int current_frame = 0; int total_frames = script_lang->debug_get_stack_level_count(); while (true) { - OS::get_singleton()->print("debug> "); String line = OS::get_singleton()->get_stdin_string().strip_edges(); @@ -149,15 +144,12 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { } else if (line == "c" || line == "continue") break; else if (line == "bt" || line == "breakpoint") { - for (int i = 0; i < total_frames; i++) { - String cfi = (current_frame == i) ? "*" : " "; //current frame indicator print_line(cfi + "Frame " + itos(i) + " - " + script_lang->debug_get_stack_level_source(i) + ":" + itos(script_lang->debug_get_stack_level_line(i)) + " in function '" + script_lang->debug_get_stack_level_function(i) + "'"); } } else if (line.begins_with("fr") || line.begins_with("frame")) { - if (line.get_slice_count(" ") == 1) { print_line("*Frame " + itos(current_frame) + " - " + script_lang->debug_get_stack_level_source(current_frame) + ":" + itos(script_lang->debug_get_stack_level_line(current_frame)) + " in function '" + script_lang->debug_get_stack_level_function(current_frame) + "'"); } else { @@ -171,9 +163,7 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { } } else if (line.begins_with("set")) { - if (line.get_slice_count(" ") == 1) { - for (Map<String, String>::Element *E = options.front(); E; E = E->next()) { print_line("\t" + E->key() + "=" + E->value()); } @@ -185,13 +175,11 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { if (value_pos < 0) { print_line("Error: Invalid set format. Use: set key=value"); } else { - String key = key_value.left(value_pos); if (!options.has(key)) { print_line("Error: Unknown option " + key); } else { - // Allow explicit tab character String value = key_value.right(value_pos + 1).replace("\\t", "\t"); @@ -201,49 +189,41 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { } } else if (line == "lv" || line == "locals") { - List<String> locals; List<Variant> values; script_lang->debug_get_stack_level_locals(current_frame, &locals, &values); print_variables(locals, values, variable_prefix); } else if (line == "gv" || line == "globals") { - List<String> globals; List<Variant> values; script_lang->debug_get_globals(&globals, &values); print_variables(globals, values, variable_prefix); } else if (line == "mv" || line == "members") { - List<String> members; List<Variant> values; script_lang->debug_get_stack_level_members(current_frame, &members, &values); print_variables(members, values, variable_prefix); } else if (line.begins_with("p") || line.begins_with("print")) { - if (line.get_slice_count(" ") <= 1) { print_line("Usage: print <expre>"); } else { - String expr = line.get_slicec(' ', 2); String res = script_lang->debug_parse_stack_level_expression(current_frame, expr); print_line(res); } } else if (line == "s" || line == "step") { - script_debugger->set_depth(-1); script_debugger->set_lines_left(1); break; } else if (line == "n" || line == "next") { - script_debugger->set_depth(0); script_debugger->set_lines_left(1); break; } else if (line == "fin" || line == "finish") { - String current_function = script_lang->debug_get_stack_level_function(0); for (int i = 0; i < total_frames; i++) { @@ -259,9 +239,7 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { target_function = ""; } else if (line.begins_with("br") || line.begins_with("break")) { - if (line.get_slice_count(" ") <= 1) { - const Map<int, Set<StringName>> &breakpoints = script_debugger->get_breakpoints(); if (breakpoints.size() == 0) { print_line("No Breakpoints."); @@ -274,7 +252,6 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { } } else { - Pair<String, int> breakpoint = to_breakpoint(line); String source = breakpoint.first; @@ -289,7 +266,6 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { } } else if (line == "q" || line == "quit") { - // Do not stop again on quit script_debugger->clear_breakpoints(); script_debugger->set_depth(-1); @@ -298,11 +274,9 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { SceneTree::get_singleton()->quit(); break; } else if (line.begins_with("delete")) { - if (line.get_slice_count(" ") <= 1) { script_debugger->clear_breakpoints(); } else { - Pair<String, int> breakpoint = to_breakpoint(line); String source = breakpoint.first; @@ -317,7 +291,6 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { } } else if (line == "h" || line == "help") { - print_line("Built-In Debugger command list:\n"); print_line("\tc,continue\t\t Continue execution."); print_line("\tbt,backtrace\t\t Show stack trace (frames)."); @@ -340,18 +313,15 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { } void LocalDebugger::print_variables(const List<String> &names, const List<Variant> &values, const String &variable_prefix) { - String value; Vector<String> value_lines; const List<Variant>::Element *V = values.front(); for (const List<String>::Element *E = names.front(); E; E = E->next()) { - value = String(V->get()); if (variable_prefix.empty()) { print_line(E->get() + ": " + String(V->get())); } else { - print_line(E->get() + ":"); value_lines = value.split("\n"); for (int i = 0; i < value_lines.size(); ++i) { @@ -364,7 +334,6 @@ void LocalDebugger::print_variables(const List<String> &names, const List<Varian } Pair<String, int> LocalDebugger::to_breakpoint(const String &p_line) { - String breakpoint_part = p_line.get_slicec(' ', 1); Pair<String, int> breakpoint; @@ -381,18 +350,15 @@ Pair<String, int> LocalDebugger::to_breakpoint(const String &p_line) { } void LocalDebugger::send_message(const String &p_message, const Array &p_args) { - // This needs to be cleaned up entirely. // print_line("MESSAGE: '" + p_message + "' - " + String(Variant(p_args))); } void LocalDebugger::send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type) { - print_line("ERROR: '" + (p_descr.empty() ? p_err : p_descr) + "'"); } LocalDebugger::LocalDebugger() { - options["variable_prefix"] = ""; // Bind scripts profiler. diff --git a/core/debugger/local_debugger.h b/core/debugger/local_debugger.h index 2c4302f4da..d342da6d44 100644 --- a/core/debugger/local_debugger.h +++ b/core/debugger/local_debugger.h @@ -36,7 +36,6 @@ #include "core/script_language.h" class LocalDebugger : public EngineDebugger { - private: struct ScriptsProfiler; diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp index 18c9602eb2..ba195f2ab5 100644 --- a/core/debugger/remote_debugger.cpp +++ b/core/debugger/remote_debugger.cpp @@ -57,7 +57,6 @@ void RemoteDebugger::_bind_profiler(const String &p_name, T *p_prof) { } struct RemoteDebugger::NetworkProfiler { - public: typedef DebuggerMarshalls::MultiplayerNodeInfo NodeInfo; struct BandwidthFrame { @@ -191,7 +190,6 @@ struct RemoteDebugger::ScriptsProfiler { typedef DebuggerMarshalls::ScriptFunctionSignature FunctionSignature; typedef DebuggerMarshalls::ScriptFunctionInfo FunctionInfo; struct ProfileInfoSort { - bool operator()(ScriptLanguage::ProfilingInfo *A, ScriptLanguage::ProfilingInfo *B) const { return A->total_time < B->total_time; } @@ -270,7 +268,6 @@ struct RemoteDebugger::ScriptsProfiler { }; struct RemoteDebugger::ServersProfiler { - bool skip_profile_frame = false; typedef DebuggerMarshalls::ServerInfo ServerInfo; typedef DebuggerMarshalls::ServerFunctionInfo ServerFunctionInfo; @@ -347,7 +344,6 @@ struct RemoteDebugger::ServersProfiler { }; struct RemoteDebugger::VisualProfiler { - typedef DebuggerMarshalls::ServerInfo ServerInfo; typedef DebuggerMarshalls::ServerFunctionInfo ServerFunctionInfo; @@ -372,7 +368,6 @@ struct RemoteDebugger::VisualProfiler { }; struct RemoteDebugger::PerformanceProfiler { - Object *performance = nullptr; int last_perf_time = 0; @@ -401,14 +396,12 @@ struct RemoteDebugger::PerformanceProfiler { }; void RemoteDebugger::_send_resource_usage() { - DebuggerMarshalls::ResourceUsage usage; List<RS::TextureInfo> tinfo; RS::get_singleton()->texture_debug_usage(&tinfo); for (List<RS::TextureInfo>::Element *E = tinfo.front(); E; E = E->next()) { - DebuggerMarshalls::ResourceInfo info; info.path = E->get().path; info.vram = E->get().bytes; @@ -436,7 +429,6 @@ Error RemoteDebugger::_put_msg(String p_message, Array p_data) { } void RemoteDebugger::_err_handler(void *p_this, const char *p_func, const char *p_file, int p_line, const char *p_err, const char *p_descr, ErrorHandlerType p_type) { - if (p_type == ERR_HANDLER_SCRIPT) return; //ignore script errors, those go through debugger @@ -457,7 +449,6 @@ void RemoteDebugger::_err_handler(void *p_this, const char *p_func, const char * } void RemoteDebugger::_print_handler(void *p_this, const String &p_string, bool p_error) { - RemoteDebugger *rd = (RemoteDebugger *)p_this; if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) // Can't handle recursive prints during flush. @@ -521,7 +512,6 @@ void RemoteDebugger::flush_output() { } if (output_strings.size()) { - // Join output strings so we generate less messages. Vector<String> joined_log_strings; Vector<String> strings; @@ -574,7 +564,6 @@ void RemoteDebugger::flush_output() { } void RemoteDebugger::send_message(const String &p_message, const Array &p_args) { - MutexLock lock(mutex); if (is_peer_connected()) { _put_msg(p_message, p_args); @@ -582,7 +571,6 @@ void RemoteDebugger::send_message(const String &p_message, const Array &p_args) } void RemoteDebugger::send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type) { - ErrorMessage oe; oe.error = p_err; oe.error_descr = p_descr; @@ -609,7 +597,6 @@ void RemoteDebugger::send_error(const String &p_func, const String &p_file, int } if (is_peer_connected()) { - if (oe.warning) { if (warn_count > max_warnings_per_second) { n_warnings_dropped++; @@ -664,7 +651,6 @@ Error RemoteDebugger::_try_capture(const String &p_msg, const Array &p_data, boo } void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { - //this function is called when there is a debugger break (bug on script) //or when execution is paused from editor @@ -698,7 +684,6 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { peer->poll(); if (peer->has_message()) { - Array cmd = peer->get_message(); ERR_CONTINUE(cmd.size() != 2); @@ -816,7 +801,6 @@ void RemoteDebugger::poll_events(bool p_is_idle) { flush_output(); peer->poll(); while (peer->has_message()) { - Array arr = peer->get_message(); ERR_CONTINUE(arr.size() != 2); diff --git a/core/debugger/remote_debugger_peer.cpp b/core/debugger/remote_debugger_peer.cpp index 458c46df93..1218bc5060 100644 --- a/core/debugger/remote_debugger_peer.cpp +++ b/core/debugger/remote_debugger_peer.cpp @@ -154,7 +154,6 @@ void RemoteDebuggerPeerTCP::_read_in() { } Error RemoteDebuggerPeerTCP::connect_to_host(const String &p_host, uint16_t p_port) { - IP_Address ip; if (p_host.is_valid_ip_address()) ip = p_host; @@ -169,12 +168,10 @@ Error RemoteDebuggerPeerTCP::connect_to_host(const String &p_host, uint16_t p_po tcp_client->connect_to_host(ip, port); for (int i = 0; i < tries; i++) { - if (tcp_client->get_status() == StreamPeerTCP::STATUS_CONNECTED) { print_verbose("Remote Debugger: Connected!"); break; } else { - const int ms = waits[i]; OS::get_singleton()->delay_usec(ms * 1000); print_verbose("Remote Debugger: Connection failed with status: '" + String::num(tcp_client->get_status()) + "', retrying in " + String::num(ms) + " msec."); @@ -182,7 +179,6 @@ Error RemoteDebuggerPeerTCP::connect_to_host(const String &p_host, uint16_t p_po }; if (tcp_client->get_status() != StreamPeerTCP::STATUS_CONNECTED) { - ERR_PRINT("Remote Debugger: Unable to connect. Status: " + String::num(tcp_client->get_status()) + "."); return FAILED; }; diff --git a/core/debugger/script_debugger.cpp b/core/debugger/script_debugger.cpp index 935ad01d80..9dd669f816 100644 --- a/core/debugger/script_debugger.cpp +++ b/core/debugger/script_debugger.cpp @@ -33,34 +33,28 @@ #include "core/debugger/engine_debugger.h" void ScriptDebugger::set_lines_left(int p_left) { - lines_left = p_left; } int ScriptDebugger::get_lines_left() const { - return lines_left; } void ScriptDebugger::set_depth(int p_depth) { - depth = p_depth; } int ScriptDebugger::get_depth() const { - return depth; } void ScriptDebugger::insert_breakpoint(int p_line, const StringName &p_source) { - if (!breakpoints.has(p_line)) breakpoints[p_line] = Set<StringName>(); breakpoints[p_line].insert(p_source); } void ScriptDebugger::remove_breakpoint(int p_line, const StringName &p_source) { - if (!breakpoints.has(p_line)) return; @@ -69,33 +63,27 @@ void ScriptDebugger::remove_breakpoint(int p_line, const StringName &p_source) { breakpoints.erase(p_line); } bool ScriptDebugger::is_breakpoint(int p_line, const StringName &p_source) const { - if (!breakpoints.has(p_line)) return false; return breakpoints[p_line].has(p_source); } bool ScriptDebugger::is_breakpoint_line(int p_line) const { - return breakpoints.has(p_line); } String ScriptDebugger::breakpoint_find_source(const String &p_source) const { - return p_source; } void ScriptDebugger::clear_breakpoints() { - breakpoints.clear(); } void ScriptDebugger::set_skip_breakpoints(bool p_skip_breakpoints) { - skip_breakpoints = p_skip_breakpoints; } bool ScriptDebugger::is_skipping_breakpoints() { - return skip_breakpoints; } @@ -118,6 +106,5 @@ Vector<ScriptLanguage::StackInfo> ScriptDebugger::get_error_stack_info() const { } ScriptLanguage *ScriptDebugger::get_break_language() const { - return break_lang; } diff --git a/core/debugger/script_debugger.h b/core/debugger/script_debugger.h index e5066273d2..0068691825 100644 --- a/core/debugger/script_debugger.h +++ b/core/debugger/script_debugger.h @@ -38,7 +38,6 @@ #include "core/vector.h" class ScriptDebugger { - typedef ScriptLanguage::StackInfo StackInfo; int lines_left = -1; diff --git a/core/dictionary.cpp b/core/dictionary.cpp index bc3b792bd5..bc8e795da7 100644 --- a/core/dictionary.cpp +++ b/core/dictionary.cpp @@ -35,13 +35,11 @@ #include "core/variant.h" struct DictionaryPrivate { - SafeRefCount refcount; OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> variant_map; }; void Dictionary::get_key_list(List<Variant> *p_keys) const { - if (_p->variant_map.empty()) return; @@ -51,7 +49,6 @@ void Dictionary::get_key_list(List<Variant> *p_keys) const { } Variant Dictionary::get_key_at_index(int p_index) const { - int index = 0; for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) { if (index == p_index) { @@ -64,7 +61,6 @@ Variant Dictionary::get_key_at_index(int p_index) const { } Variant Dictionary::get_value_at_index(int p_index) const { - int index = 0; for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) { if (index == p_index) { @@ -77,16 +73,13 @@ Variant Dictionary::get_value_at_index(int p_index) const { } Variant &Dictionary::operator[](const Variant &p_key) { - return _p->variant_map[p_key]; } const Variant &Dictionary::operator[](const Variant &p_key) const { - return _p->variant_map[p_key]; } const Variant *Dictionary::getptr(const Variant &p_key) const { - OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstElement E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key); if (!E) @@ -95,7 +88,6 @@ const Variant *Dictionary::getptr(const Variant &p_key) const { } Variant *Dictionary::getptr(const Variant &p_key) { - OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.find(p_key); if (!E) @@ -104,7 +96,6 @@ Variant *Dictionary::getptr(const Variant &p_key) { } Variant Dictionary::get_valid(const Variant &p_key) const { - OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstElement E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key); if (!E) @@ -122,16 +113,13 @@ Variant Dictionary::get(const Variant &p_key, const Variant &p_default) const { } int Dictionary::size() const { - return _p->variant_map.size(); } bool Dictionary::empty() const { - return !_p->variant_map.size(); } bool Dictionary::has(const Variant &p_key) const { - return _p->variant_map.has(p_key); } @@ -145,22 +133,18 @@ bool Dictionary::has_all(const Array &p_keys) const { } bool Dictionary::erase(const Variant &p_key) { - return _p->variant_map.erase(p_key); } bool Dictionary::operator==(const Dictionary &p_dictionary) const { - return _p == p_dictionary._p; } bool Dictionary::operator!=(const Dictionary &p_dictionary) const { - return _p != p_dictionary._p; } void Dictionary::_ref(const Dictionary &p_from) const { - //make a copy first (thread safe) if (!p_from._p->refcount.ref()) return; // couldn't copy @@ -176,12 +160,10 @@ void Dictionary::_ref(const Dictionary &p_from) const { } void Dictionary::clear() { - _p->variant_map.clear(); } void Dictionary::_unref() const { - ERR_FAIL_COND(!_p); if (_p->refcount.unref()) { memdelete(_p); @@ -189,7 +171,6 @@ void Dictionary::_unref() const { _p = nullptr; } uint32_t Dictionary::hash() const { - uint32_t h = hash_djb2_one_32(Variant::DICTIONARY); for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) { @@ -201,7 +182,6 @@ uint32_t Dictionary::hash() const { } Array Dictionary::keys() const { - Array varr; if (_p->variant_map.empty()) return varr; @@ -218,7 +198,6 @@ Array Dictionary::keys() const { } Array Dictionary::values() const { - Array varr; if (_p->variant_map.empty()) return varr; @@ -235,7 +214,6 @@ Array Dictionary::values() const { } const Variant *Dictionary::next(const Variant *p_key) const { - if (p_key == nullptr) { // caller wants to get the first element if (_p->variant_map.front()) @@ -250,7 +228,6 @@ const Variant *Dictionary::next(const Variant *p_key) const { } Dictionary Dictionary::duplicate(bool p_deep) const { - Dictionary n; for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) { @@ -261,7 +238,6 @@ Dictionary Dictionary::duplicate(bool p_deep) const { } void Dictionary::operator=(const Dictionary &p_dictionary) { - _ref(p_dictionary); } @@ -275,11 +251,9 @@ Dictionary::Dictionary(const Dictionary &p_from) { } Dictionary::Dictionary() { - _p = memnew(DictionaryPrivate); _p->refcount.init(); } Dictionary::~Dictionary() { - _unref(); } diff --git a/core/dictionary.h b/core/dictionary.h index c6cbacc144..a01d96ba01 100644 --- a/core/dictionary.h +++ b/core/dictionary.h @@ -40,7 +40,6 @@ class Variant; struct DictionaryPrivate; class Dictionary { - mutable DictionaryPrivate *_p; void _ref(const Dictionary &p_from) const; diff --git a/core/engine.cpp b/core/engine.cpp index 86ce0395b9..bd86535a70 100644 --- a/core/engine.cpp +++ b/core/engine.cpp @@ -37,12 +37,10 @@ #include "core/version_hash.gen.h" void Engine::set_iterations_per_second(int p_ips) { - ERR_FAIL_COND_MSG(p_ips <= 0, "Engine iterations per second must be greater than 0."); ips = p_ips; } int Engine::get_iterations_per_second() const { - return ips; } @@ -65,32 +63,26 @@ int Engine::get_target_fps() const { } uint64_t Engine::get_frames_drawn() { - return frames_drawn; } void Engine::set_frame_delay(uint32_t p_msec) { - _frame_delay = p_msec; } uint32_t Engine::get_frame_delay() const { - return _frame_delay; } void Engine::set_time_scale(float p_scale) { - _time_scale = p_scale; } float Engine::get_time_scale() const { - return _time_scale; } Dictionary Engine::get_version_info() const { - Dictionary dict; dict["major"] = VERSION_MAJOR; dict["minor"] = VERSION_MINOR; @@ -185,25 +177,21 @@ String Engine::get_license_text() const { } void Engine::add_singleton(const Singleton &p_singleton) { - singletons.push_back(p_singleton); singleton_ptrs[p_singleton.name] = p_singleton.ptr; } Object *Engine::get_singleton_object(const String &p_name) const { - const Map<StringName, Object *>::Element *E = singleton_ptrs.find(p_name); ERR_FAIL_COND_V_MSG(!E, nullptr, "Failed to retrieve non-existent singleton '" + p_name + "'."); return E->get(); }; bool Engine::has_singleton(const String &p_name) const { - return singleton_ptrs.has(p_name); }; void Engine::get_singletons(List<Singleton> *p_singletons) { - for (List<Singleton>::Element *E = singletons.front(); E; E = E->next()) p_singletons->push_back(E->get()); } diff --git a/core/engine.h b/core/engine.h index aa28b35814..fef330c0c1 100644 --- a/core/engine.h +++ b/core/engine.h @@ -37,7 +37,6 @@ #include "core/vector.h" class Engine { - public: struct Singleton { StringName name; diff --git a/core/error_macros.cpp b/core/error_macros.cpp index 5de070844a..ff50c9786a 100644 --- a/core/error_macros.cpp +++ b/core/error_macros.cpp @@ -37,7 +37,6 @@ static ErrorHandlerList *error_handler_list = nullptr; void add_error_handler(ErrorHandlerList *p_handler) { - _global_lock(); p_handler->next = error_handler_list; error_handler_list = p_handler; @@ -45,16 +44,13 @@ void add_error_handler(ErrorHandlerList *p_handler) { } void remove_error_handler(ErrorHandlerList *p_handler) { - _global_lock(); ErrorHandlerList *prev = nullptr; ErrorHandlerList *l = error_handler_list; while (l) { - if (l == p_handler) { - if (prev) prev->next = l->next; else @@ -77,13 +73,11 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co } void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const char *p_message, ErrorHandlerType p_type) { - OS::get_singleton()->print_error(p_function, p_file, p_line, p_error, p_message, (Logger::ErrorType)p_type); _global_lock(); ErrorHandlerList *l = error_handler_list; while (l) { - l->errfunc(l->userdata, p_function, p_file, p_line, p_error, p_message, p_type); l = l->next; } @@ -104,7 +98,6 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co } void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const char *p_message, bool fatal) { - String fstr(fatal ? "FATAL: " : ""); String err(fstr + "Index " + p_index_str + " = " + itos(p_index) + " is out of bounds (" + p_size_str + " = " + itos(p_size) + ")."); _err_print_error(p_function, p_file, p_line, err.utf8().get_data(), p_message); diff --git a/core/error_macros.h b/core/error_macros.h index eb2cc5215d..a592f752d5 100644 --- a/core/error_macros.h +++ b/core/error_macros.h @@ -47,7 +47,6 @@ enum ErrorHandlerType { typedef void (*ErrorHandlerFunc)(void *, const char *, const char *, int p_line, const char *, const char *, ErrorHandlerType p_type); struct ErrorHandlerList { - ErrorHandlerFunc errfunc = nullptr; void *userdata = nullptr; diff --git a/core/func_ref.cpp b/core/func_ref.cpp index ad29f4488d..9c0e1698c2 100644 --- a/core/func_ref.cpp +++ b/core/func_ref.cpp @@ -31,7 +31,6 @@ #include "func_ref.h" Variant FuncRef::call_func(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (id.is_null()) { r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL; return Variant(); @@ -47,7 +46,6 @@ Variant FuncRef::call_func(const Variant **p_args, int p_argcount, Callable::Cal } Variant FuncRef::call_funcv(const Array &p_args) { - ERR_FAIL_COND_V(id.is_null(), Variant()); Object *obj = ObjectDB::get_instance(id); @@ -58,13 +56,11 @@ Variant FuncRef::call_funcv(const Array &p_args) { } void FuncRef::set_instance(Object *p_obj) { - ERR_FAIL_NULL(p_obj); id = p_obj->get_instance_id(); } void FuncRef::set_function(const StringName &p_func) { - function = p_func; } @@ -80,7 +76,6 @@ bool FuncRef::is_valid() const { } void FuncRef::_bind_methods() { - { MethodInfo mi; mi.name = "call_func"; diff --git a/core/func_ref.h b/core/func_ref.h index 07b361db2d..6b0b22bab5 100644 --- a/core/func_ref.h +++ b/core/func_ref.h @@ -34,7 +34,6 @@ #include "core/reference.h" class FuncRef : public Reference { - GDCLASS(FuncRef, Reference); ObjectID id; StringName function; diff --git a/core/global_constants.cpp b/core/global_constants.cpp index 4f415a2056..6281e56395 100644 --- a/core/global_constants.cpp +++ b/core/global_constants.cpp @@ -36,7 +36,6 @@ #include "core/variant.h" struct _GlobalConstant { - #ifdef DEBUG_METHODS_ENABLED StringName enum_name; #endif @@ -638,33 +637,27 @@ void register_global_constants() { } void unregister_global_constants() { - _global_constants.clear(); } int GlobalConstants::get_global_constant_count() { - return _global_constants.size(); } #ifdef DEBUG_METHODS_ENABLED StringName GlobalConstants::get_global_constant_enum(int p_idx) { - return _global_constants[p_idx].enum_name; } #else StringName GlobalConstants::get_global_constant_enum(int p_idx) { - return StringName(); } #endif const char *GlobalConstants::get_global_constant_name(int p_idx) { - return _global_constants[p_idx].name; } int GlobalConstants::get_global_constant_value(int p_idx) { - return _global_constants[p_idx].value; } diff --git a/core/hash_map.h b/core/hash_map.h index cfc0f87010..a4bc811b67 100644 --- a/core/hash_map.h +++ b/core/hash_map.h @@ -59,7 +59,6 @@ template <class TKey, class TData, class Hasher = HashMapHasherDefault, class Co class HashMap { public: struct Pair { - TKey key; TData data; @@ -99,7 +98,6 @@ private: uint32_t elements = 0; void make_hash_table() { - ERR_FAIL_COND(hash_table); hash_table = memnew_arr(Element *, (1 << MIN_HASH_TABLE_POWER)); @@ -111,7 +109,6 @@ private: } void erase_hash_table() { - ERR_FAIL_COND_MSG(elements, "Cannot erase hash table if there are still elements inside."); memdelete_arr(hash_table); @@ -121,7 +118,6 @@ private: } void check_hash_table() { - int new_hash_table_power = -1; if ((int)elements > ((1 << hash_table_power) * RELATIONSHIP)) { @@ -129,17 +125,14 @@ private: new_hash_table_power = hash_table_power + 1; while ((int)elements > ((1 << new_hash_table_power) * RELATIONSHIP)) { - new_hash_table_power++; } } else if ((hash_table_power > (int)MIN_HASH_TABLE_POWER) && ((int)elements < ((1 << (hash_table_power - 1)) * RELATIONSHIP))) { - /* rehash down */ new_hash_table_power = hash_table_power - 1; while ((int)elements < ((1 << (new_hash_table_power - 1)) * RELATIONSHIP)) { - new_hash_table_power--; } @@ -154,15 +147,12 @@ private: ERR_FAIL_COND_MSG(!new_hash_table, "Out of memory."); for (int i = 0; i < (1 << new_hash_table_power); i++) { - new_hash_table[i] = nullptr; } if (hash_table) { for (int i = 0; i < (1 << hash_table_power); i++) { - while (hash_table[i]) { - Element *se = hash_table[i]; hash_table[i] = se->next; int new_pos = se->hash & ((1 << new_hash_table_power) - 1); @@ -179,17 +169,14 @@ private: /* I want to have only one function.. */ _FORCE_INLINE_ const Element *get_element(const TKey &p_key) const { - uint32_t hash = Hasher::hash(p_key); uint32_t index = hash & ((1 << hash_table_power) - 1); Element *e = hash_table[index]; while (e) { - /* checking hash first avoids comparing key, which may take longer */ if (e->hash == hash && Comparator::compare(e->pair.key, p_key)) { - /* the pair exists in this hashtable, so just update data */ return e; } @@ -201,7 +188,6 @@ private: } Element *create_element(const TKey &p_key) { - /* if element doesn't exist, create it */ Element *e = memnew(Element); ERR_FAIL_COND_V_MSG(!e, nullptr, "Out of memory."); @@ -219,7 +205,6 @@ private: } void copy_from(const HashMap &p_t) { - if (&p_t == this) return; /* much less bother with that */ @@ -233,13 +218,11 @@ private: elements = p_t.elements; for (int i = 0; i < (1 << p_t.hash_table_power); i++) { - hash_table[i] = nullptr; const Element *e = p_t.hash_table[i]; while (e) { - Element *le = memnew(Element); /* local element */ *le = *e; /* copy data */ @@ -259,7 +242,6 @@ public: } Element *set(const Pair &p_pair) { - Element *e = nullptr; if (!hash_table) make_hash_table(); // if no table, make one @@ -269,7 +251,6 @@ public: /* if we made it up to here, the pair doesn't exist, create and assign */ if (!e) { - e = create_element(p_pair.key); if (!e) return nullptr; @@ -281,7 +262,6 @@ public: } bool has(const TKey &p_key) const { - return getptr(p_key) != nullptr; } @@ -292,14 +272,12 @@ public: */ const TData &get(const TKey &p_key) const { - const TData *res = getptr(p_key); ERR_FAIL_COND_V(!res, *res); return *res; } TData &get(const TKey &p_key) { - TData *res = getptr(p_key); ERR_FAIL_COND_V(!res, *res); return *res; @@ -311,7 +289,6 @@ public: */ _FORCE_INLINE_ TData *getptr(const TKey &p_key) { - if (unlikely(!hash_table)) return nullptr; @@ -324,7 +301,6 @@ public: } _FORCE_INLINE_ const TData *getptr(const TKey &p_key) const { - if (unlikely(!hash_table)) return nullptr; @@ -343,7 +319,6 @@ public: template <class C> _FORCE_INLINE_ TData *custom_getptr(C p_custom_key, uint32_t p_custom_hash) { - if (unlikely(!hash_table)) return nullptr; @@ -353,10 +328,8 @@ public: Element *e = hash_table[index]; while (e) { - /* checking hash first avoids comparing key, which may take longer */ if (e->hash == hash && Comparator::compare(e->pair.key, p_custom_key)) { - /* the pair exists in this hashtable, so just update data */ return &e->pair.data; } @@ -369,7 +342,6 @@ public: template <class C> _FORCE_INLINE_ const TData *custom_getptr(C p_custom_key, uint32_t p_custom_hash) const { - if (unlikely(!hash_table)) return nullptr; @@ -379,10 +351,8 @@ public: const Element *e = hash_table[index]; while (e) { - /* checking hash first avoids comparing key, which may take longer */ if (e->hash == hash && Comparator::compare(e->pair.key, p_custom_key)) { - /* the pair exists in this hashtable, so just update data */ return &e->pair.data; } @@ -398,7 +368,6 @@ public: */ bool erase(const TKey &p_key) { - if (unlikely(!hash_table)) return false; @@ -408,12 +377,9 @@ public: Element *e = hash_table[index]; Element *p = nullptr; while (e) { - /* checking hash first avoids comparing key, which may take longer */ if (e->hash == hash && Comparator::compare(e->pair.key, p_key)) { - if (p) { - p->next = e->next; } else { //begin of list @@ -451,7 +417,6 @@ public: /* if we made it up to here, the pair doesn't exist, create */ if (!e) { - e = create_element(p_key); CRASH_COND(!e); check_hash_table(); // perform mantenience routine @@ -476,14 +441,12 @@ public: * */ const TKey *next(const TKey *p_key) const { - if (unlikely(!hash_table)) return nullptr; if (!p_key) { /* get the first key */ for (int i = 0; i < (1 << hash_table_power); i++) { - if (hash_table[i]) { return &hash_table[i]->pair.key; } @@ -501,7 +464,6 @@ public: uint32_t index = e->hash & ((1 << hash_table_power) - 1); index++; for (int i = index; i < (1 << hash_table_power); i++) { - if (hash_table[i]) { return &hash_table[i]->pair.key; } @@ -515,23 +477,18 @@ public: } inline unsigned int size() const { - return elements; } inline bool empty() const { - return elements == 0; } void clear() { - /* clean up */ if (hash_table) { for (int i = 0; i < (1 << hash_table_power); i++) { - while (hash_table[i]) { - Element *e = hash_table[i]; hash_table[i] = e->next; memdelete(e); @@ -547,7 +504,6 @@ public: } void operator=(const HashMap &p_table) { - copy_from(p_table); } @@ -555,7 +511,6 @@ public: if (unlikely(!hash_table)) return; for (int i = 0; i < (1 << hash_table_power); i++) { - Element *e = hash_table[i]; while (e) { *p_pairs = &e->pair; @@ -569,7 +524,6 @@ public: if (unlikely(!hash_table)) return; for (int i = 0; i < (1 << hash_table_power); i++) { - Element *e = hash_table[i]; while (e) { p_keys->push_back(e->pair.key); diff --git a/core/hashfuncs.h b/core/hashfuncs.h index a41a034843..ccecba5137 100644 --- a/core/hashfuncs.h +++ b/core/hashfuncs.h @@ -49,7 +49,6 @@ * @return 32-bits hashcode */ static inline uint32_t hash_djb2(const char *p_cstr) { - const unsigned char *chr = (const unsigned char *)p_cstr; uint32_t hash = 5381; uint32_t c; @@ -61,7 +60,6 @@ static inline uint32_t hash_djb2(const char *p_cstr) { } static inline uint32_t hash_djb2_buffer(const uint8_t *p_buff, int p_len, uint32_t p_prev = 5381) { - uint32_t hash = p_prev; for (int i = 0; i < p_len; i++) @@ -71,7 +69,6 @@ static inline uint32_t hash_djb2_buffer(const uint8_t *p_buff, int p_len, uint32 } static inline uint32_t hash_djb2_one_32(uint32_t p_in, uint32_t p_prev = 5381) { - return ((p_prev << 5) + p_prev) + p_in; } @@ -105,7 +102,6 @@ static inline uint32_t hash_djb2_one_float(double p_in, uint32_t p_prev = 5381) template <class T> static inline uint32_t make_uint32_t(T p_in) { - union { T t; uint32_t _u32; @@ -116,13 +112,11 @@ static inline uint32_t make_uint32_t(T p_in) { } static inline uint64_t hash_djb2_one_64(uint64_t p_in, uint64_t p_prev = 5381) { - return ((p_prev << 5) + p_prev) + p_in; } template <class T> static inline uint64_t make_uint64_t(T p_in) { - union { T t; uint64_t _u64; @@ -134,7 +128,6 @@ static inline uint64_t make_uint64_t(T p_in) { } 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); } diff --git a/core/image.cpp b/core/image.cpp index c88ed7e3cb..4cbecbf44f 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -90,7 +90,6 @@ SaveEXRFunc Image::save_exr_func = nullptr; SavePNGBufferFunc Image::save_png_buffer_func = nullptr; void Image::_put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_data, const uint8_t *p_pixel) { - uint32_t ofs = (p_y * width + p_x) * p_pixelsize; for (uint32_t i = 0; i < p_pixelsize; i++) { @@ -99,7 +98,6 @@ void Image::_put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_data, } void Image::_get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p_data, uint8_t *p_pixel) { - uint32_t ofs = (p_y * width + p_x) * p_pixelsize; for (uint32_t i = 0; i < p_pixelsize; i++) { @@ -108,7 +106,6 @@ void Image::_get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p } int Image::get_format_pixel_size(Format p_format) { - switch (p_format) { case FORMAT_L8: return 1; //luminance @@ -195,7 +192,6 @@ int Image::get_format_pixel_size(Format p_format) { } void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) { - switch (p_format) { case FORMAT_DXT1: //s3tc bc1 case FORMAT_DXT3: //bc2 @@ -208,25 +204,21 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) { } break; case FORMAT_PVRTC2: case FORMAT_PVRTC2A: { - r_w = 16; r_h = 8; } break; case FORMAT_PVRTC4A: case FORMAT_PVRTC4: { - r_w = 8; r_h = 8; } break; case FORMAT_ETC: { - r_w = 4; r_h = 4; } break; case FORMAT_BPTC_RGBA: case FORMAT_BPTC_RGBF: case FORMAT_BPTC_RGBFU: { - r_w = 4; r_h = 4; } break; @@ -239,7 +231,6 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) { case FORMAT_ETC2_RGB8A1: case FORMAT_ETC2_RA_AS_RG: case FORMAT_DXT5_RA_AS_RG: { - r_w = 4; r_h = 4; @@ -253,7 +244,6 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) { } int Image::get_format_pixel_rshift(Format p_format) { - if (p_format == FORMAT_DXT1 || p_format == FORMAT_RGTC_R || p_format == FORMAT_PVRTC4 || p_format == FORMAT_PVRTC4A || p_format == FORMAT_ETC || p_format == FORMAT_ETC2_R11 || p_format == FORMAT_ETC2_R11S || p_format == FORMAT_ETC2_RGB8 || p_format == FORMAT_ETC2_RGB8A1) return 1; else if (p_format == FORMAT_PVRTC2 || p_format == FORMAT_PVRTC2A) @@ -263,7 +253,6 @@ int Image::get_format_pixel_rshift(Format p_format) { } int Image::get_format_block_size(Format p_format) { - switch (p_format) { case FORMAT_DXT1: //s3tc bc1 case FORMAT_DXT3: //bc2 @@ -275,22 +264,18 @@ int Image::get_format_block_size(Format p_format) { } case FORMAT_PVRTC2: case FORMAT_PVRTC2A: { - return 4; } case FORMAT_PVRTC4A: case FORMAT_PVRTC4: { - return 4; } case FORMAT_ETC: { - return 4; } case FORMAT_BPTC_RGBA: case FORMAT_BPTC_RGBF: case FORMAT_BPTC_RGBFU: { - return 4; } case FORMAT_ETC2_R11: //etc2 @@ -304,7 +289,6 @@ int Image::get_format_block_size(Format p_format) { case FORMAT_DXT5_RA_AS_RG: //used to make basis universal happy { - return 4; } default: { @@ -315,7 +299,6 @@ int Image::get_format_block_size(Format p_format) { } void Image::_get_mipmap_offset_and_size(int p_mipmap, int &r_offset, int &r_width, int &r_height) const { - int w = width; int h = height; int ofs = 0; @@ -345,7 +328,6 @@ void Image::_get_mipmap_offset_and_size(int p_mipmap, int &r_offset, int &r_widt } int Image::get_mipmap_offset(int p_mipmap) const { - ERR_FAIL_INDEX_V(p_mipmap, get_mipmap_count() + 1, -1); int ofs, w, h; @@ -354,7 +336,6 @@ int Image::get_mipmap_offset(int p_mipmap) const { } int Image::get_mipmap_byte_size(int p_mipmap) const { - ERR_FAIL_INDEX_V(p_mipmap, get_mipmap_count() + 1, -1); int ofs, w, h; @@ -365,7 +346,6 @@ int Image::get_mipmap_byte_size(int p_mipmap) const { } void Image::get_mipmap_offset_and_size(int p_mipmap, int &r_ofs, int &r_size) const { - int ofs, w, h; _get_mipmap_offset_and_size(p_mipmap, ofs, w, h); int ofs2; @@ -375,7 +355,6 @@ void Image::get_mipmap_offset_and_size(int p_mipmap, int &r_ofs, int &r_size) co } void Image::get_mipmap_offset_size_and_dimensions(int p_mipmap, int &r_ofs, int &r_size, int &w, int &h) const { - int ofs; _get_mipmap_offset_and_size(p_mipmap, ofs, w, h); int ofs2, w2, h2; @@ -385,27 +364,22 @@ void Image::get_mipmap_offset_size_and_dimensions(int p_mipmap, int &r_ofs, int } int Image::get_width() const { - return width; } int Image::get_height() const { - return height; } Vector2 Image::get_size() const { - return Vector2(width, height); } bool Image::has_mipmaps() const { - return mipmaps; } int Image::get_mipmap_count() const { - if (mipmaps) return get_image_required_mipmaps(width, height, format); else @@ -415,12 +389,10 @@ int Image::get_mipmap_count() const { //using template generates perfectly optimized code due to constant expression reduction and unused variable removal present in all compilers template <uint32_t read_bytes, bool read_alpha, uint32_t write_bytes, bool write_alpha, bool read_gray, bool write_gray> static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p_dst) { - uint32_t max_bytes = MAX(read_bytes, write_bytes); for (int y = 0; y < p_height; y++) { for (int x = 0; x < p_width; x++) { - const uint8_t *rofs = &p_src[((y * p_width) + x) * (read_bytes + (read_alpha ? 1 : 0))]; uint8_t *wofs = &p_dst[((y * p_width) + x) * (write_bytes + (write_alpha ? 1 : 0))]; @@ -431,9 +403,7 @@ static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p rgba[1] = rofs[0]; rgba[2] = rofs[0]; } else { - for (uint32_t i = 0; i < max_bytes; i++) { - rgba[i] = (i < read_bytes) ? rofs[i] : 0; } } @@ -447,7 +417,6 @@ static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p wofs[0] = uint8_t((uint16_t(rofs[0]) + uint16_t(rofs[1]) + uint16_t(rofs[2])) / 3); } else { for (uint32_t i = 0; i < write_bytes; i++) { - wofs[i] = rgba[i]; } } @@ -460,7 +429,6 @@ static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p } void Image::convert(Format p_new_format) { - if (data.size() == 0) return; @@ -468,17 +436,14 @@ void Image::convert(Format p_new_format) { return; if (format > FORMAT_RGBE9995 || p_new_format > FORMAT_RGBE9995) { - ERR_FAIL_MSG("Cannot convert to <-> from compressed formats. Use compress() and decompress() instead."); } else if (format > FORMAT_RGBA8 || p_new_format > FORMAT_RGBA8) { - //use put/set pixel which is slower but works with non byte formats Image new_img(width, height, false, p_new_format); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { - new_img.set_pixel(i, j, get_pixel(i, j)); } } @@ -500,7 +465,6 @@ void Image::convert(Format p_new_format) { int conversion_type = format | p_new_format << 8; switch (conversion_type) { - case FORMAT_L8 | (FORMAT_LA8 << 8): _convert<1, false, 1, true, true, true>(width, height, rptr, wptr); break; @@ -602,12 +566,10 @@ void Image::convert(Format p_new_format) { } Image::Format Image::get_format() const { - return format; } static double _bicubic_interp_kernel(double x) { - x = ABS(x); double bc = 0; @@ -622,7 +584,6 @@ static double _bicubic_interp_kernel(double x) { template <int CC, class T> static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) { - // get source image size int width = p_src_width; int height = p_src_height; @@ -706,7 +667,6 @@ static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_ template <int CC, class T> static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) { - enum { FRAC_BITS = 8, FRAC_LEN = (1 << FRAC_BITS), @@ -715,7 +675,6 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict }; for (uint32_t i = 0; i < p_dst_height; i++) { - uint32_t src_yofs_up_fp = (i * p_src_height * FRAC_LEN / p_dst_height); uint32_t src_yofs_frac = src_yofs_up_fp & FRAC_MASK; uint32_t src_yofs_up = src_yofs_up_fp >> FRAC_BITS; @@ -731,7 +690,6 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict uint32_t y_ofs_down = src_yofs_down * p_src_width * CC; for (uint32_t j = 0; j < p_dst_width; j++) { - uint32_t src_xofs_left_fp = (j * p_src_width * FRAC_LEN / p_dst_width); uint32_t src_xofs_frac = src_xofs_left_fp & FRAC_MASK; uint32_t src_xofs_left = src_xofs_left_fp >> FRAC_BITS; @@ -743,7 +701,6 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict src_xofs_right *= CC; for (uint32_t l = 0; l < CC; l++) { - if (sizeof(T) == 1) { //uint8 uint32_t p00 = p_src[y_ofs_up + src_xofs_left + l] << FRAC_BITS; uint32_t p10 = p_src[y_ofs_up + src_xofs_right + l] << FRAC_BITS; @@ -797,19 +754,15 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict template <int CC, class T> static void _scale_nearest(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) { - for (uint32_t i = 0; i < p_dst_height; i++) { - uint32_t src_yofs = i * p_src_height / p_dst_height; uint32_t y_ofs = src_yofs * p_src_width * CC; for (uint32_t j = 0; j < p_dst_width; j++) { - uint32_t src_xofs = j * p_src_width / p_dst_width; src_xofs *= CC; for (uint32_t l = 0; l < CC; l++) { - const T *src = ((const T *)p_src); T *dst = ((T *)p_dst); @@ -828,7 +781,6 @@ static float _lanczos(float p_x) { template <int CC, class T> static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) { - int32_t src_width = p_src_width; int32_t src_height = p_src_height; int32_t dst_height = p_dst_height; @@ -847,7 +799,6 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict float *kernel = memnew_arr(float, half_kernel * 2); for (int32_t buffer_x = 0; buffer_x < dst_width; buffer_x++) { - // The corresponding point on the source image float src_x = (buffer_x + 0.5f) * x_scale; // Offset by 0.5 so it uses the pixel's center int32_t start_x = MAX(0, int32_t(src_x) - half_kernel + 1); @@ -858,12 +809,10 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict kernel[target_x - start_x] = _lanczos((target_x + 0.5f - src_x) / scale_factor); for (int32_t buffer_y = 0; buffer_y < src_height; buffer_y++) { - float pixel[CC] = { 0 }; float weight = 0; for (int32_t target_x = start_x; target_x <= end_x; target_x++) { - float lanczos_val = kernel[target_x - start_x]; weight += lanczos_val; @@ -897,7 +846,6 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict float *kernel = memnew_arr(float, half_kernel * 2); for (int32_t dst_y = 0; dst_y < dst_height; dst_y++) { - float buffer_y = (dst_y + 0.5f) * y_scale; int32_t start_y = MAX(0, int32_t(buffer_y) - half_kernel + 1); int32_t end_y = MIN(src_height - 1, int32_t(buffer_y) + half_kernel); @@ -906,12 +854,10 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict kernel[target_y - start_y] = _lanczos((target_y + 0.5f - buffer_y) / scale_factor); for (int32_t dst_x = 0; dst_x < dst_width; dst_x++) { - float pixel[CC] = { 0 }; float weight = 0; for (int32_t target_y = start_y; target_y <= end_y; target_y++) { - float lanczos_val = kernel[target_y - start_y]; weight += lanczos_val; @@ -943,11 +889,9 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict } static void _overlay(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, float p_alpha, uint32_t p_width, uint32_t p_height, uint32_t p_pixel_size) { - uint16_t alpha = MIN((uint16_t)(p_alpha * 256.0f), 256); for (uint32_t i = 0; i < p_width * p_height * p_pixel_size; i++) { - p_dst[i] = (p_dst[i] * (256 - alpha) + p_src[i] * alpha) >> 8; } } @@ -957,7 +901,6 @@ bool Image::is_size_po2() const { } void Image::resize_to_po2(bool p_square) { - ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot resize in compressed or custom image formats."); int w = next_power_of_2(width); @@ -967,7 +910,6 @@ void Image::resize_to_po2(bool p_square) { } if (w == width && h == height) { - if (!p_square || w == h) return; //nothing to do } @@ -976,7 +918,6 @@ void Image::resize_to_po2(bool p_square) { } void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { - ERR_FAIL_COND_MSG(data.size() == 0, "Cannot resize image before creating it, use create() or create_from_data() first."); ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot resize in compressed or custom image formats."); @@ -1027,9 +968,7 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { unsigned char *w_ptr = w; switch (p_interpolation) { - case INTERPOLATE_NEAREST: { - if (format >= FORMAT_L8 && format <= FORMAT_RGBA8) { switch (get_format_pixel_size(format)) { case 1: @@ -1081,7 +1020,6 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { } break; case INTERPOLATE_BILINEAR: case INTERPOLATE_TRILINEAR: { - for (int i = 0; i < 2; ++i) { int src_width; int src_height; @@ -1174,7 +1112,6 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { } break; case INTERPOLATE_CUBIC: { - if (format >= FORMAT_L8 && format <= FORMAT_RGBA8) { switch (get_format_pixel_size(format)) { case 1: @@ -1223,7 +1160,6 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { } } break; case INTERPOLATE_LANCZOS: { - if (format >= FORMAT_L8 && format <= FORMAT_RGBA8) { switch (get_format_pixel_size(format)) { case 1: @@ -1284,7 +1220,6 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { } void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) { - ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot crop in compressed or custom image formats."); ERR_FAIL_COND_MSG(p_x < 0, "Start x position cannot be smaller than 0."); @@ -1313,9 +1248,7 @@ void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) { int m_h = p_y + p_height; int m_w = p_x + p_width; for (int y = p_y; y < m_h; y++) { - for (int x = p_x; x < m_w; x++) { - if ((x >= width || y >= height)) { for (uint32_t i = 0; i < pixel_size; i++) pdata[i] = 0; @@ -1334,12 +1267,10 @@ void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) { } void Image::crop(int p_width, int p_height) { - crop_from_point(0, 0, p_width, p_height); } void Image::flip_y() { - ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot flip_y in compressed or custom image formats."); bool used_mipmaps = has_mipmaps(); @@ -1354,9 +1285,7 @@ void Image::flip_y() { uint32_t pixel_size = get_format_pixel_size(format); for (int y = 0; y < height / 2; y++) { - for (int x = 0; x < width; x++) { - _get_pixelb(x, y, pixel_size, w, up); _get_pixelb(x, height - y - 1, pixel_size, w, down); @@ -1372,7 +1301,6 @@ void Image::flip_y() { } void Image::flip_x() { - ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot flip_x in compressed or custom image formats."); bool used_mipmaps = has_mipmaps(); @@ -1387,9 +1315,7 @@ void Image::flip_x() { uint32_t pixel_size = get_format_pixel_size(format); for (int y = 0; y < height; y++) { - for (int x = 0; x < width / 2; x++) { - _get_pixelb(x, y, pixel_size, w, up); _get_pixelb(width - x - 1, y, pixel_size, w, down); @@ -1405,7 +1331,6 @@ void Image::flip_x() { } int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps, int *r_mm_width, int *r_mm_height) { - int size = 0; int w = p_width; int h = p_height; @@ -1420,7 +1345,6 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int & int minw = 1, minh = 1; while (true) { - int bw = w % block != 0 ? w + (block - w % block) : w; int bh = h % block != 0 ? h + (block - h % block) : h; @@ -1442,7 +1366,6 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int & break; if (p_mipmaps >= 0) { - w = MAX(minw, w >> 1); h = MAX(minh, h >> 1); } else { @@ -1459,7 +1382,6 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int & } bool Image::_can_modify(Format p_format) const { - return p_format <= FORMAT_RGBE9995; } @@ -1467,7 +1389,6 @@ template <class Component, int CC, bool renormalize, void (*average_func)(Component &, const Component &, const Component &, const Component &, const Component &), void (*renormalize_func)(Component *)> static void _generate_po2_mipmap(const Component *p_src, Component *p_dst, uint32_t p_width, uint32_t p_height) { - //fast power of 2 mipmap generation uint32_t dst_w = MAX(p_width >> 1, 1); uint32_t dst_h = MAX(p_height >> 1, 1); @@ -1476,7 +1397,6 @@ static void _generate_po2_mipmap(const Component *p_src, Component *p_dst, uint3 int down_step = (p_height == 1) ? 0 : (p_width * CC); for (uint32_t i = 0; i < dst_h; i++) { - const Component *rup_ptr = &p_src[i * 2 * down_step]; const Component *rdown_ptr = rup_ptr + down_step; Component *dst_ptr = &p_dst[i * dst_w * CC]; @@ -1500,7 +1420,6 @@ static void _generate_po2_mipmap(const Component *p_src, Component *p_dst, uint3 } void Image::expand_x2_hq2x() { - ERR_FAIL_COND(!_can_modify(format)); bool used_mipmaps = has_mipmaps(); @@ -1540,11 +1459,9 @@ void Image::expand_x2_hq2x() { } void Image::shrink_x2() { - ERR_FAIL_COND(data.size() == 0); if (mipmaps) { - //just use the lower mipmap as base and copy all Vector<uint8_t> new_img; @@ -1566,7 +1483,6 @@ void Image::shrink_x2() { data = new_img; } else { - Vector<uint8_t> new_img; ERR_FAIL_COND(!_can_modify(format)); @@ -1580,7 +1496,6 @@ void Image::shrink_x2() { const uint8_t *r = data.ptr(); switch (format) { - case FORMAT_L8: case FORMAT_R8: _generate_po2_mipmap<uint8_t, 1, false, Image::average_4_uint8, Image::renormalize_uint8>(r, w, width, height); @@ -1639,16 +1554,13 @@ void Image::shrink_x2() { } void Image::normalize() { - bool used_mipmaps = has_mipmaps(); if (used_mipmaps) { clear_mipmaps(); } for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - Color c = get_pixel(x, y); Vector3 v(c.r * 2.0 - 1.0, c.g * 2.0 - 1.0, c.b * 2.0 - 1.0); v.normalize(); @@ -1665,7 +1577,6 @@ void Image::normalize() { } Error Image::generate_mipmaps(bool p_renormalize) { - ERR_FAIL_COND_V_MSG(!_can_modify(format), ERR_UNAVAILABLE, "Cannot generate mipmaps in compressed or custom image formats."); ERR_FAIL_COND_V_MSG(format == FORMAT_RGBA4444, ERR_UNAVAILABLE, "Cannot generate mipmaps from RGBA4444 format."); @@ -1685,12 +1596,10 @@ Error Image::generate_mipmaps(bool p_renormalize) { int prev_w = width; for (int i = 1; i <= mmcount; i++) { - int ofs, w, h; _get_mipmap_offset_and_size(i, ofs, w, h); switch (format) { - case FORMAT_L8: case FORMAT_R8: _generate_po2_mipmap<uint8_t, 1, false, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); @@ -1774,7 +1683,6 @@ Error Image::generate_mipmaps(bool p_renormalize) { } Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, const Ref<Image> &p_normal_map) { - Vector<double> normal_sat_vec; //summed area table double *normal_sat = nullptr; //summed area table for normalmap int normal_w = 0, normal_h = 0; @@ -1839,7 +1747,6 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con uint8_t *base_ptr = data.ptrw(); for (int i = 1; i <= mmcount; i++) { - int ofs, w, h; _get_mipmap_offset_and_size(i, ofs, w, h); uint8_t *ptr = &base_ptr[ofs]; @@ -1970,7 +1877,6 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con } void Image::clear_mipmaps() { - if (!mipmaps) return; @@ -1985,17 +1891,14 @@ void Image::clear_mipmaps() { } bool Image::empty() const { - return (data.size() == 0); } Vector<uint8_t> Image::get_data() const { - return data; } void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_format) { - ERR_FAIL_INDEX(p_width - 1, MAX_WIDTH); ERR_FAIL_INDEX(p_height - 1, MAX_HEIGHT); ERR_FAIL_COND_MSG(p_width * p_height > MAX_PIXELS, "Too many pixels for image, maximum is " + itos(MAX_PIXELS)); @@ -2016,7 +1919,6 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma } void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data) { - ERR_FAIL_INDEX(p_width - 1, MAX_WIDTH); ERR_FAIL_INDEX(p_height - 1, MAX_HEIGHT); ERR_FAIL_COND_MSG(p_width * p_height > MAX_PIXELS, "Too many pixels for image, maximum is " + itos(MAX_PIXELS)); @@ -2035,7 +1937,6 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma } void Image::create(const char **p_xpm) { - int size_width = 0; int size_height = 0; int pixelchars = 0; @@ -2058,13 +1959,10 @@ void Image::create(const char **p_xpm) { uint8_t *w; while (status != DONE) { - const char *line_ptr = p_xpm[line]; switch (status) { - case READING_HEADER: { - String line_str = line_ptr; line_str.replace("\t", " "); @@ -2079,10 +1977,8 @@ void Image::create(const char **p_xpm) { status = READING_COLORS; } break; case READING_COLORS: { - String colorstring; for (int i = 0; i < pixelchars; i++) { - colorstring += *line_ptr; line_ptr++; } @@ -2093,7 +1989,6 @@ void Image::create(const char **p_xpm) { line_ptr++; } if (*line_ptr == 'c') { - line_ptr++; while (*line_ptr == ' ' || *line_ptr == '\t' || *line_ptr == 0) { if (*line_ptr == 0) @@ -2109,7 +2004,6 @@ void Image::create(const char **p_xpm) { //uint8_t col_a=255; for (int i = 0; i < 6; i++) { - char v = line_ptr[i]; if (v >= '0' && v <= '9') @@ -2145,17 +2039,14 @@ void Image::create(const char **p_xpm) { // magenta mask if (col_r == 255 && col_g == 0 && col_b == 255) { - colormap[colorstring] = Color(0, 0, 0, 0); has_alpha = true; } else { - colormap[colorstring] = Color(col_r / 255.0, col_g / 255.0, col_b / 255.0, 1.0); } } } if (line == colormap_size) { - status = READING_PIXELS; create(size_width, size_height, false, has_alpha ? FORMAT_RGBA8 : FORMAT_RGB8); w = data.ptrw(); @@ -2163,10 +2054,8 @@ void Image::create(const char **p_xpm) { } } break; case READING_PIXELS: { - int y = line - colormap_size - 1; for (int x = 0; x < size_width; x++) { - char pixelstr[6] = { 0, 0, 0, 0, 0, 0 }; for (int i = 0; i < pixelchars; i++) pixelstr[i] = line_ptr[x * pixelchars + i]; @@ -2199,7 +2088,6 @@ void Image::create(const char **p_xpm) { if (value < DETECT_ALPHA_MIN_THRESHOLD) \ bit = true; \ else if (value < DETECT_ALPHA_MAX_THRESHOLD) { \ - \ detected = true; \ break; \ } \ @@ -2209,14 +2097,12 @@ void Image::create(const char **p_xpm) { { \ uint8_t value = m_value; \ if (value > 0) { \ - \ detected = true; \ break; \ } \ } bool Image::is_invisible() const { - if (format == FORMAT_L8 || format == FORMAT_RGB8 || format == FORMAT_RG8) return false; @@ -2235,16 +2121,13 @@ bool Image::is_invisible() const { bool detected = false; switch (format) { - case FORMAT_LA8: { - for (int i = 0; i < (len >> 1); i++) { DETECT_NON_ALPHA(data_ptr[(i << 1) + 1]); } } break; case FORMAT_RGBA8: { - for (int i = 0; i < (len >> 2); i++) { DETECT_NON_ALPHA(data_ptr[(i << 2) + 3]) } @@ -2265,7 +2148,6 @@ bool Image::is_invisible() const { } Image::AlphaMode Image::detect_alpha() const { - int len = data.size(); if (len == 0) @@ -2281,16 +2163,13 @@ Image::AlphaMode Image::detect_alpha() const { bool detected = false; switch (format) { - case FORMAT_LA8: { - for (int i = 0; i < (len >> 1); i++) { DETECT_ALPHA(data_ptr[(i << 1) + 1]); } } break; case FORMAT_RGBA8: { - for (int i = 0; i < (len >> 2); i++) { DETECT_ALPHA(data_ptr[(i << 2) + 3]) } @@ -2324,7 +2203,6 @@ Error Image::load(const String &p_path) { } Error Image::save_png(const String &p_path) const { - if (save_png_func == nullptr) return ERR_UNAVAILABLE; @@ -2340,7 +2218,6 @@ Vector<uint8_t> Image::save_png_to_buffer() const { } Error Image::save_exr(const String &p_path, bool p_grayscale) const { - if (save_exr_func == nullptr) return ERR_UNAVAILABLE; @@ -2348,13 +2225,11 @@ Error Image::save_exr(const String &p_path, bool p_grayscale) const { } int Image::get_image_data_size(int p_width, int p_height, Format p_format, bool p_mipmaps) { - int mm; return _get_dst_image_size(p_width, p_height, p_format, mm, p_mipmaps ? -1 : 0); } int Image::get_image_required_mipmaps(int p_width, int p_height, Format p_format) { - int mm; _get_dst_image_size(p_width, p_height, p_format, mm, -1); return mm; @@ -2368,7 +2243,6 @@ Size2i Image::get_image_mipmap_size(int p_width, int p_height, Format p_format, } int Image::get_image_mipmap_offset(int p_width, int p_height, Format p_format, int p_mipmap) { - if (p_mipmap <= 0) { return 0; } @@ -2377,7 +2251,6 @@ int Image::get_image_mipmap_offset(int p_width, int p_height, Format p_format, i } int Image::get_image_mipmap_offset_and_dimensions(int p_width, int p_height, Format p_format, int p_mipmap, int &r_w, int &r_h) { - if (p_mipmap <= 0) { r_w = p_width; r_h = p_height; @@ -2392,7 +2265,6 @@ bool Image::is_compressed() const { } Error Image::decompress() { - if (((format >= FORMAT_DXT1 && format <= FORMAT_RGTC_RG) || (format == FORMAT_DXT5_RA_AS_RG)) && _image_decompress_bc) _image_decompress_bc(this); else if (format >= FORMAT_BPTC_RGBA && format <= FORMAT_BPTC_RGBFU && _image_decompress_bptc) @@ -2409,40 +2281,31 @@ Error Image::decompress() { } Error Image::compress(CompressMode p_mode, CompressSource p_source, float p_lossy_quality) { - return compress_from_channels(p_mode, detect_used_channels(p_source), p_lossy_quality); } Error Image::compress_from_channels(CompressMode p_mode, UsedChannels p_channels, float p_lossy_quality) { - switch (p_mode) { - case COMPRESS_S3TC: { - ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE); _image_compress_bc_func(this, p_lossy_quality, p_channels); } break; case COMPRESS_PVRTC2: { - ERR_FAIL_COND_V(!_image_compress_pvrtc2_func, ERR_UNAVAILABLE); _image_compress_pvrtc2_func(this); } break; case COMPRESS_PVRTC4: { - ERR_FAIL_COND_V(!_image_compress_pvrtc4_func, ERR_UNAVAILABLE); _image_compress_pvrtc4_func(this); } break; case COMPRESS_ETC: { - ERR_FAIL_COND_V(!_image_compress_etc1_func, ERR_UNAVAILABLE); _image_compress_etc1_func(this, p_lossy_quality); } break; case COMPRESS_ETC2: { - ERR_FAIL_COND_V(!_image_compress_etc2_func, ERR_UNAVAILABLE); _image_compress_etc2_func(this, p_lossy_quality, p_channels); } break; case COMPRESS_BPTC: { - ERR_FAIL_COND_V(!_image_compress_bptc_func, ERR_UNAVAILABLE); _image_compress_bptc_func(this, p_lossy_quality, p_channels); } break; @@ -2452,7 +2315,6 @@ Error Image::compress_from_channels(CompressMode p_mode, UsedChannels p_channels } Image::Image(const char **p_xpm) { - width = 0; height = 0; mipmaps = false; @@ -2462,7 +2324,6 @@ Image::Image(const char **p_xpm) { } Image::Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format) { - width = 0; height = 0; mipmaps = p_use_mipmaps; @@ -2472,7 +2333,6 @@ Image::Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format) { } Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const Vector<uint8_t> &p_data) { - width = 0; height = 0; mipmaps = p_mipmaps; @@ -2482,7 +2342,6 @@ Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const V } Rect2 Image::get_used_rect() const { - if (format != FORMAT_LA8 && format != FORMAT_RGBA8 && format != FORMAT_RGBAF && format != FORMAT_RGBAH && format != FORMAT_RGBA4444 && format != FORMAT_RGB565) return Rect2(Point2(), Size2(width, height)); @@ -2495,7 +2354,6 @@ Rect2 Image::get_used_rect() const { int maxx = -1, maxy = -1; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - if (!(get_pixel(i, j).a > 0)) continue; if (i > maxx) @@ -2516,14 +2374,12 @@ Rect2 Image::get_used_rect() const { } Ref<Image> Image::get_rect(const Rect2 &p_area) const { - Ref<Image> img = memnew(Image(p_area.size.x, p_area.size.y, mipmaps, format)); img->blit_rect(Ref<Image>((Image *)this), p_area, Point2(0, 0)); return img; } void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Point2 &p_dest) { - ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object."); int dsize = data.size(); int srcdsize = p_src->data.size(); @@ -2554,9 +2410,7 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po int pixel_size = get_format_pixel_size(format); for (int i = 0; i < dest_rect.size.y; i++) { - for (int j = 0; j < dest_rect.size.x; j++) { - int src_x = clipped_src_rect.position.x + j; int src_y = clipped_src_rect.position.y + i; @@ -2574,7 +2428,6 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po } void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, const Rect2 &p_src_rect, const Point2 &p_dest) { - ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object."); ERR_FAIL_COND_MSG(p_mask.is_null(), "It's not a reference to a valid Image object."); int dsize = data.size(); @@ -2611,14 +2464,11 @@ void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, co Ref<Image> msk = p_mask; for (int i = 0; i < dest_rect.size.y; i++) { - for (int j = 0; j < dest_rect.size.x; j++) { - 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; int dst_y = dest_rect.position.y + i; @@ -2634,7 +2484,6 @@ void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, co } void Image::blend_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Point2 &p_dest) { - ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object."); int dsize = data.size(); int srcdsize = p_src->data.size(); @@ -2658,9 +2507,7 @@ void Image::blend_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const P Ref<Image> img = p_src; for (int i = 0; i < dest_rect.size.y; i++) { - for (int j = 0; j < dest_rect.size.x; j++) { - int src_x = clipped_src_rect.position.x + j; int src_y = clipped_src_rect.position.y + i; @@ -2679,7 +2526,6 @@ void Image::blend_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const P } void Image::blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, const Rect2 &p_src_rect, const Point2 &p_dest) { - ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object."); ERR_FAIL_COND_MSG(p_mask.is_null(), "It's not a reference to a valid Image object."); int dsize = data.size(); @@ -2709,9 +2555,7 @@ void Image::blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, c Ref<Image> msk = p_mask; for (int i = 0; i < dest_rect.size.y; i++) { - for (int j = 0; j < dest_rect.size.x; j++) { - int src_x = clipped_src_rect.position.x + j; int src_y = clipped_src_rect.position.y + i; @@ -2719,7 +2563,6 @@ void Image::blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, c //Color c = msk->get_pixel(src_x, src_y); //if (c.a == 0) continue; if (msk->get_pixel(src_x, src_y).a != 0) { - int dst_x = dest_rect.position.x + j; int dst_y = dest_rect.position.y + i; @@ -2747,9 +2590,7 @@ void Image::fill(const Color &c) { set_pixel(0, 0, c); for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - uint8_t *dst = &dst_data_ptr[(y * width + x) * pixel_size]; for (int k = 0; k < pixel_size; k++) { @@ -2783,7 +2624,6 @@ Vector<uint8_t> (*Image::basis_universal_packer)(const Ref<Image> &, Image::Used Ref<Image> (*Image::basis_universal_unpacker)(const Vector<uint8_t> &) = nullptr; void Image::_set_data(const Dictionary &p_data) { - ERR_FAIL_COND(!p_data.has("width")); ERR_FAIL_COND(!p_data.has("height")); ERR_FAIL_COND(!p_data.has("format")); @@ -2809,7 +2649,6 @@ void Image::_set_data(const Dictionary &p_data) { } Dictionary Image::_get_data() const { - Dictionary d; d["width"] = width; d["height"] = height; @@ -2824,7 +2663,6 @@ Color Image::get_pixelv(const Point2 &p_src) const { } Color Image::_get_color_at_ofs(const uint8_t *ptr, uint32_t ofs) const { - switch (format) { case FORMAT_L8: { float l = ptr[ofs] / 255.0; @@ -2836,12 +2674,10 @@ Color Image::_get_color_at_ofs(const uint8_t *ptr, uint32_t ofs) const { return Color(l, l, l, a); } case FORMAT_R8: { - float r = ptr[ofs] / 255.0; return Color(r, 0, 0, 1); } case FORMAT_RG8: { - float r = ptr[ofs * 2 + 0] / 255.0; float g = ptr[ofs * 2 + 1] / 255.0; return Color(r, g, 0, 1); @@ -2868,7 +2704,6 @@ Color Image::_get_color_at_ofs(const uint8_t *ptr, uint32_t ofs) const { return Color(r, g, b, a); } case FORMAT_RGB565: { - uint16_t u = ((uint16_t *)ptr)[ofs]; float r = (u & 0x1F) / 31.0; float g = ((u >> 5) & 0x3F) / 63.0; @@ -2876,25 +2711,21 @@ Color Image::_get_color_at_ofs(const uint8_t *ptr, uint32_t ofs) const { return Color(r, g, b, 1.0); } case FORMAT_RF: { - float r = ((float *)ptr)[ofs]; return Color(r, 0, 0, 1); } case FORMAT_RGF: { - float r = ((float *)ptr)[ofs * 2 + 0]; float g = ((float *)ptr)[ofs * 2 + 1]; return Color(r, g, 0, 1); } case FORMAT_RGBF: { - float r = ((float *)ptr)[ofs * 3 + 0]; float g = ((float *)ptr)[ofs * 3 + 1]; float b = ((float *)ptr)[ofs * 3 + 2]; return Color(r, g, b, 1); } case FORMAT_RGBAF: { - float r = ((float *)ptr)[ofs * 4 + 0]; float g = ((float *)ptr)[ofs * 4 + 1]; float b = ((float *)ptr)[ofs * 4 + 2]; @@ -2902,25 +2733,21 @@ Color Image::_get_color_at_ofs(const uint8_t *ptr, uint32_t ofs) const { return Color(r, g, b, a); } case FORMAT_RH: { - uint16_t r = ((uint16_t *)ptr)[ofs]; return Color(Math::half_to_float(r), 0, 0, 1); } case FORMAT_RGH: { - uint16_t r = ((uint16_t *)ptr)[ofs * 2 + 0]; uint16_t g = ((uint16_t *)ptr)[ofs * 2 + 1]; return Color(Math::half_to_float(r), Math::half_to_float(g), 0, 1); } case FORMAT_RGBH: { - uint16_t r = ((uint16_t *)ptr)[ofs * 3 + 0]; uint16_t g = ((uint16_t *)ptr)[ofs * 3 + 1]; uint16_t b = ((uint16_t *)ptr)[ofs * 3 + 2]; return Color(Math::half_to_float(r), Math::half_to_float(g), Math::half_to_float(b), 1); } case FORMAT_RGBAH: { - uint16_t r = ((uint16_t *)ptr)[ofs * 4 + 0]; uint16_t g = ((uint16_t *)ptr)[ofs * 4 + 1]; uint16_t b = ((uint16_t *)ptr)[ofs * 4 + 2]; @@ -2946,11 +2773,9 @@ void Image::_set_color_at_ofs(uint8_t *ptr, uint32_t ofs, const Color &p_color) ptr[ofs * 2 + 1] = uint8_t(CLAMP(p_color.a * 255.0, 0, 255)); } break; case FORMAT_R8: { - ptr[ofs] = uint8_t(CLAMP(p_color.r * 255.0, 0, 255)); } break; case FORMAT_RG8: { - ptr[ofs * 2 + 0] = uint8_t(CLAMP(p_color.r * 255.0, 0, 255)); ptr[ofs * 2 + 1] = uint8_t(CLAMP(p_color.g * 255.0, 0, 255)); } break; @@ -2967,7 +2792,6 @@ void Image::_set_color_at_ofs(uint8_t *ptr, uint32_t ofs, const Color &p_color) } break; case FORMAT_RGBA4444: { - uint16_t rgba = 0; rgba = uint16_t(CLAMP(p_color.r * 15.0, 0, 15)) << 12; @@ -2979,7 +2803,6 @@ void Image::_set_color_at_ofs(uint8_t *ptr, uint32_t ofs, const Color &p_color) } break; case FORMAT_RGB565: { - uint16_t rgba = 0; rgba = uint16_t(CLAMP(p_color.r * 31.0, 0, 31)); @@ -2990,51 +2813,42 @@ void Image::_set_color_at_ofs(uint8_t *ptr, uint32_t ofs, const Color &p_color) } break; case FORMAT_RF: { - ((float *)ptr)[ofs] = p_color.r; } break; case FORMAT_RGF: { - ((float *)ptr)[ofs * 2 + 0] = p_color.r; ((float *)ptr)[ofs * 2 + 1] = p_color.g; } break; case FORMAT_RGBF: { - ((float *)ptr)[ofs * 3 + 0] = p_color.r; ((float *)ptr)[ofs * 3 + 1] = p_color.g; ((float *)ptr)[ofs * 3 + 2] = p_color.b; } break; case FORMAT_RGBAF: { - ((float *)ptr)[ofs * 4 + 0] = p_color.r; ((float *)ptr)[ofs * 4 + 1] = p_color.g; ((float *)ptr)[ofs * 4 + 2] = p_color.b; ((float *)ptr)[ofs * 4 + 3] = p_color.a; } break; case FORMAT_RH: { - ((uint16_t *)ptr)[ofs] = Math::make_half_float(p_color.r); } break; case FORMAT_RGH: { - ((uint16_t *)ptr)[ofs * 2 + 0] = Math::make_half_float(p_color.r); ((uint16_t *)ptr)[ofs * 2 + 1] = Math::make_half_float(p_color.g); } break; case FORMAT_RGBH: { - ((uint16_t *)ptr)[ofs * 3 + 0] = Math::make_half_float(p_color.r); ((uint16_t *)ptr)[ofs * 3 + 1] = Math::make_half_float(p_color.g); ((uint16_t *)ptr)[ofs * 3 + 2] = Math::make_half_float(p_color.b); } break; case FORMAT_RGBAH: { - ((uint16_t *)ptr)[ofs * 4 + 0] = Math::make_half_float(p_color.r); ((uint16_t *)ptr)[ofs * 4 + 1] = Math::make_half_float(p_color.g); ((uint16_t *)ptr)[ofs * 4 + 2] = Math::make_half_float(p_color.b); ((uint16_t *)ptr)[ofs * 4 + 3] = Math::make_half_float(p_color.a); } break; case FORMAT_RGBE9995: { - ((uint32_t *)ptr)[ofs] = p_color.to_rgbe9995(); } break; @@ -3069,14 +2883,12 @@ void Image::set_pixel(int p_x, int p_y, const Color &p_color) { } Image::UsedChannels Image::detect_used_channels(CompressSource p_source) { - ERR_FAIL_COND_V(data.size() == 0, USED_CHANNELS_RGBA); ERR_FAIL_COND_V(is_compressed(), USED_CHANNELS_RGBA); bool r = false, g = false, b = false, a = false, c = false; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { - Color col = get_pixel(i, j); if (col.r > 0.001) @@ -3146,7 +2958,6 @@ void Image::optimize_channels() { } void Image::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_width"), &Image::get_width); ClassDB::bind_method(D_METHOD("get_height"), &Image::get_height); ClassDB::bind_method(D_METHOD("get_size"), &Image::get_size); @@ -3292,17 +3103,14 @@ void Image::_bind_methods() { } void Image::set_compress_bc_func(void (*p_compress_func)(Image *, float, UsedChannels)) { - _image_compress_bc_func = p_compress_func; } void Image::set_compress_bptc_func(void (*p_compress_func)(Image *, float, UsedChannels)) { - _image_compress_bptc_func = p_compress_func; } void Image::normalmap_to_xy() { - convert(Image::FORMAT_RGBA8); { @@ -3310,7 +3118,6 @@ void Image::normalmap_to_xy() { uint8_t *data_ptr = data.ptrw(); for (int i = 0; i < len; i++) { - data_ptr[(i << 2) + 3] = data_ptr[(i << 2) + 0]; //x to w data_ptr[(i << 2) + 0] = data_ptr[(i << 2) + 1]; //y to xz data_ptr[(i << 2) + 2] = data_ptr[(i << 2) + 1]; @@ -3321,7 +3128,6 @@ void Image::normalmap_to_xy() { } Ref<Image> Image::rgbe_to_srgb() { - if (data.size() == 0) return Ref<Image>(); @@ -3345,7 +3151,6 @@ Ref<Image> Image::rgbe_to_srgb() { } Ref<Image> Image::get_image_from_mipmap(int p_mipamp) const { - int ofs, size, w, h; get_mipmap_offset_size_and_dimensions(p_mipamp, ofs, size, w, h); @@ -3415,7 +3220,6 @@ void Image::bumpmap_to_normalmap(float bump_scale) { } void Image::srgb_to_linear() { - if (data.size() == 0) return; @@ -3424,24 +3228,20 @@ void Image::srgb_to_linear() { ERR_FAIL_COND(format != FORMAT_RGB8 && format != FORMAT_RGBA8); if (format == FORMAT_RGBA8) { - int len = data.size() / 4; uint8_t *data_ptr = data.ptrw(); for (int i = 0; i < len; i++) { - data_ptr[(i << 2) + 0] = srgb2lin[data_ptr[(i << 2) + 0]]; data_ptr[(i << 2) + 1] = srgb2lin[data_ptr[(i << 2) + 1]]; data_ptr[(i << 2) + 2] = srgb2lin[data_ptr[(i << 2) + 2]]; } } else if (format == FORMAT_RGB8) { - int len = data.size() / 3; uint8_t *data_ptr = data.ptrw(); for (int i = 0; i < len; i++) { - data_ptr[(i * 3) + 0] = srgb2lin[data_ptr[(i * 3) + 0]]; data_ptr[(i * 3) + 1] = srgb2lin[data_ptr[(i * 3) + 1]]; data_ptr[(i * 3) + 2] = srgb2lin[data_ptr[(i * 3) + 2]]; @@ -3450,7 +3250,6 @@ void Image::srgb_to_linear() { } void Image::premultiply_alpha() { - if (data.size() == 0) return; @@ -3461,7 +3260,6 @@ void Image::premultiply_alpha() { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { - uint8_t *ptr = &data_ptr[(i * width + j) * 4]; ptr[0] = (uint16_t(ptr[0]) * uint16_t(ptr[3])) >> 8; @@ -3472,7 +3270,6 @@ void Image::premultiply_alpha() { } void Image::fix_alpha_edges() { - if (data.size() == 0) return; @@ -3490,7 +3287,6 @@ void Image::fix_alpha_edges() { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { - const uint8_t *rptr = &srcptr[(i * width + j) * 4]; uint8_t *wptr = &data_ptr[(i * width + j) * 4]; @@ -3507,7 +3303,6 @@ void Image::fix_alpha_edges() { for (int k = from_y; k <= to_y; k++) { for (int l = from_x; l <= to_x; l++) { - int dy = i - k; int dx = j - l; int dist = dy * dy + dx * dx; @@ -3527,7 +3322,6 @@ void Image::fix_alpha_edges() { } if (closest_dist != max_dist) { - wptr[0] = closest_color[0]; wptr[1] = closest_color[1]; wptr[2] = closest_color[2]; @@ -3537,7 +3331,6 @@ void Image::fix_alpha_edges() { } String Image::get_format_name(Format p_format) { - ERR_FAIL_INDEX_V(p_format, FORMAT_MAX, String()); return format_names[p_format]; } @@ -3645,7 +3438,6 @@ void Image::renormalize_rgbe9995(uint32_t *p_rgb) { } Image::Image(const uint8_t *p_mem_png_jpg, int p_len) { - width = 0; height = 0; mipmaps = false; @@ -3661,7 +3453,6 @@ Image::Image(const uint8_t *p_mem_png_jpg, int p_len) { } Ref<Resource> Image::duplicate(bool p_subresources) const { - Ref<Image> copy; copy.instance(); copy->_copy_internals_from(*this); diff --git a/core/input/input.cpp b/core/input/input.cpp index 38a71994d8..a9921f791a 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -129,7 +129,6 @@ Input::CursorShape (*Input::get_current_cursor_shape_func)() = nullptr; void (*Input::set_custom_mouse_cursor_func)(const RES &, Input::CursorShape, const Vector2 &) = nullptr; Input *Input::get_singleton() { - return singleton; } @@ -139,12 +138,10 @@ void Input::set_mouse_mode(MouseMode p_mode) { } Input::MouseMode Input::get_mouse_mode() const { - return get_mouse_mode_func(); } void Input::_bind_methods() { - ClassDB::bind_method(D_METHOD("is_key_pressed", "keycode"), &Input::is_key_pressed); ClassDB::bind_method(D_METHOD("is_mouse_button_pressed", "button"), &Input::is_mouse_button_pressed); ClassDB::bind_method(D_METHOD("is_joy_button_pressed", "device", "button"), &Input::is_joy_button_pressed); @@ -219,7 +216,6 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S String pf = p_function; if (p_idx == 0 && (pf == "is_action_pressed" || pf == "action_press" || pf == "action_release" || pf == "is_action_just_pressed" || pf == "is_action_just_released" || pf == "get_action_strength")) { - List<PropertyInfo> pinfo; ProjectSettings::get_singleton()->get_property_list(&pinfo); @@ -237,7 +233,6 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S } void Input::SpeedTrack::update(const Vector2 &p_delta_p) { - uint64_t tick = OS::get_singleton()->get_ticks_usec(); uint32_t tdiff = tick - last_tick; float delta_t = tdiff / 1000000.0; @@ -250,7 +245,6 @@ void Input::SpeedTrack::update(const Vector2 &p_delta_p) { accum_t = max_ref_frame * 10; while (accum_t >= min_ref_frame) { - float slice_t = min_ref_frame / accum_t; Vector2 slice = accum * slice_t; accum = accum - slice; @@ -267,42 +261,35 @@ void Input::SpeedTrack::reset() { } Input::SpeedTrack::SpeedTrack() { - min_ref_frame = 0.1; max_ref_frame = 0.3; reset(); } bool Input::is_key_pressed(int p_keycode) const { - _THREAD_SAFE_METHOD_ return keys_pressed.has(p_keycode); } bool Input::is_mouse_button_pressed(int p_button) const { - _THREAD_SAFE_METHOD_ return (mouse_button_mask & (1 << (p_button - 1))) != 0; } static int _combine_device(int p_value, int p_device) { - return p_value | (p_device << 20); } bool Input::is_joy_button_pressed(int p_device, int p_button) const { - _THREAD_SAFE_METHOD_ return joy_buttons_pressed.has(_combine_device(p_button, p_device)); } bool Input::is_action_pressed(const StringName &p_action) const { - return action_state.has(p_action) && action_state[p_action].pressed; } bool Input::is_action_just_pressed(const StringName &p_action) const { - const Map<StringName, Action>::Element *E = action_state.find(p_action); if (!E) return false; @@ -315,7 +302,6 @@ bool Input::is_action_just_pressed(const StringName &p_action) const { } bool Input::is_action_just_released(const StringName &p_action) const { - const Map<StringName, Action>::Element *E = action_state.find(p_action); if (!E) return false; @@ -336,7 +322,6 @@ float Input::get_action_strength(const StringName &p_action) const { } float Input::get_joy_axis(int p_device, int p_axis) const { - _THREAD_SAFE_METHOD_ int c = _combine_device(p_axis, p_device); if (_joy_axis.has(c)) { @@ -347,7 +332,6 @@ float Input::get_joy_axis(int p_device, int p_axis) const { } String Input::get_joy_name(int p_idx) { - _THREAD_SAFE_METHOD_ return joy_names[p_idx].name; }; @@ -377,7 +361,6 @@ float Input::get_joy_vibration_duration(int p_device) { } static String _hex_str(uint8_t p_byte) { - static const char *dict = "0123456789abcdef"; char ret[3]; ret[2] = 0; @@ -389,14 +372,12 @@ static String _hex_str(uint8_t p_byte) { }; void Input::joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid) { - _THREAD_SAFE_METHOD_ Joypad js; js.name = p_connected ? p_name : ""; js.uid = p_connected ? p_guid : ""; if (p_connected) { - String uidname = p_guid; if (p_guid == "") { int uidlen = MIN(p_name.length(), 16); @@ -430,36 +411,30 @@ void Input::joy_connection_changed(int p_idx, bool p_connected, String p_name, S }; Vector3 Input::get_gravity() const { - _THREAD_SAFE_METHOD_ return gravity; } Vector3 Input::get_accelerometer() const { - _THREAD_SAFE_METHOD_ return accelerometer; } Vector3 Input::get_magnetometer() const { - _THREAD_SAFE_METHOD_ return magnetometer; } Vector3 Input::get_gyroscope() const { - _THREAD_SAFE_METHOD_ return gyroscope; } void Input::parse_input_event(const Ref<InputEvent> &p_event) { - _parse_input_event_impl(p_event, false); } void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated) { - // Notes on mouse-touch emulation: // - Emulated mouse events are parsed, that is, re-routed to this method, so they make the same effects // as true mouse events. The only difference is the situation is flagged as emulated so they are not @@ -480,7 +455,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid()) { - if (mb->is_pressed()) { mouse_button_mask |= (1 << (mb->get_button_index() - 1)); } else { @@ -504,7 +478,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em Ref<InputEventMouseMotion> mm = p_event; if (mm.is_valid()) { - Point2 pos = mm->get_global_position(); if (mouse_pos != pos) { set_mouse_position(pos); @@ -525,7 +498,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em Ref<InputEventScreenTouch> st = p_event; if (st.is_valid()) { - if (st->is_pressed()) { SpeedTrack &track = touch_speed_track[st->get_index()]; track.reset(); @@ -536,7 +508,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em } if (emulate_mouse_from_touch) { - bool translate = false; if (st->is_pressed()) { if (mouse_from_touch_index == -1) { @@ -573,13 +544,11 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em Ref<InputEventScreenDrag> sd = p_event; if (sd.is_valid()) { - SpeedTrack &track = touch_speed_track[sd->get_index()]; track.update(sd->get_relative()); sd->set_speed(track.speed); if (emulate_mouse_from_touch && sd->get_index() == mouse_from_touch_index) { - Ref<InputEventMouseMotion> motion_event; motion_event.instance(); @@ -597,7 +566,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em Ref<InputEventJoypadButton> jb = p_event; if (jb.is_valid()) { - int c = _combine_device(jb->get_button_index(), jb->get_device()); if (jb->is_pressed()) @@ -615,7 +583,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em Ref<InputEventGesture> ge = p_event; if (ge.is_valid()) { - if (event_dispatch_function) { event_dispatch_function(ge); } @@ -623,7 +590,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em for (const Map<StringName, InputMap::Action>::Element *E = InputMap::get_singleton()->get_action_map().front(); E; E = E->next()) { if (InputMap::get_singleton()->event_is_action(p_event, E->key())) { - // Save the action's state if (!p_event->is_echo() && is_action_pressed(E->key()) != p_event->is_action_pressed(E->key())) { Action action; @@ -642,7 +608,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em } void Input::set_joy_axis(int p_device, int p_axis, float p_value) { - _THREAD_SAFE_METHOD_ int c = _combine_device(p_axis, p_device); _joy_axis[c] = p_value; @@ -676,50 +641,42 @@ void Input::vibrate_handheld(int p_duration_ms) { } void Input::set_gravity(const Vector3 &p_gravity) { - _THREAD_SAFE_METHOD_ gravity = p_gravity; } void Input::set_accelerometer(const Vector3 &p_accel) { - _THREAD_SAFE_METHOD_ accelerometer = p_accel; } void Input::set_magnetometer(const Vector3 &p_magnetometer) { - _THREAD_SAFE_METHOD_ magnetometer = p_magnetometer; } void Input::set_gyroscope(const Vector3 &p_gyroscope) { - _THREAD_SAFE_METHOD_ gyroscope = p_gyroscope; } void Input::set_mouse_position(const Point2 &p_posf) { - mouse_speed_track.update(p_posf - mouse_pos); mouse_pos = p_posf; } Point2 Input::get_mouse_position() const { - return mouse_pos; } Point2 Input::get_last_mouse_speed() const { - return mouse_speed_track.speed; } int Input::get_mouse_button_mask() const { - return mouse_button_mask; // do not trust OS implementation, should remove it - OS::get_singleton()->get_mouse_button_state(); } @@ -728,7 +685,6 @@ void Input::warp_mouse_position(const Vector2 &p_to) { } Point2i Input::warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect) { - // The relative distance reported for the next event after a warp is in the boundaries of the // size of the rect on that axis, but it may be greater, in which case there's not problem as fmod() // will warp it, but if the pointer has moved in the opposite direction between the pointer relocation @@ -757,7 +713,6 @@ void Input::iteration(float p_step) { } void Input::action_press(const StringName &p_action, float p_strength) { - Action action; action.physics_frame = Engine::get_singleton()->get_physics_frames(); @@ -769,7 +724,6 @@ void Input::action_press(const StringName &p_action, float p_strength) { } void Input::action_release(const StringName &p_action) { - Action action; action.physics_frame = Engine::get_singleton()->get_physics_frames(); @@ -781,19 +735,16 @@ void Input::action_release(const StringName &p_action) { } void Input::set_emulate_touch_from_mouse(bool p_emulate) { - emulate_touch_from_mouse = p_emulate; } bool Input::is_emulating_touch_from_mouse() const { - return emulate_touch_from_mouse; } // Calling this whenever the game window is focused helps unstucking the "touch mouse" // if the OS or its abstraction class hasn't properly reported that touch pointers raised void Input::ensure_touch_mouse_raised() { - if (mouse_from_touch_index != -1) { mouse_from_touch_index = -1; @@ -812,22 +763,18 @@ void Input::ensure_touch_mouse_raised() { } void Input::set_emulate_mouse_from_touch(bool p_emulate) { - emulate_mouse_from_touch = p_emulate; } bool Input::is_emulating_mouse_from_touch() const { - return emulate_mouse_from_touch; } Input::CursorShape Input::get_default_cursor_shape() const { - return default_shape; } void Input::set_default_cursor_shape(CursorShape p_shape) { - if (default_shape == p_shape) return; @@ -842,7 +789,6 @@ void Input::set_default_cursor_shape(CursorShape p_shape) { } Input::CursorShape Input::get_current_cursor_shape() const { - return get_current_cursor_shape_func(); } @@ -867,7 +813,6 @@ void Input::accumulate_input_event(const Ref<InputEvent> &p_event) { accumulated_events.push_back(p_event); } void Input::flush_accumulated_events() { - while (accumulated_events.front()) { parse_input_event(accumulated_events.front()->get()); accumulated_events.pop_front(); @@ -875,12 +820,10 @@ void Input::flush_accumulated_events() { } void Input::set_use_accumulated_input(bool p_enable) { - use_accumulated_input = p_enable; } void Input::release_pressed_events() { - flush_accumulated_events(); // this is needed to release actions strengths keys_pressed.clear(); @@ -898,7 +841,6 @@ void Input::set_event_dispatch_function(EventDispatchFunc p_function) { } void Input::joy_button(int p_device, int p_button, bool p_pressed) { - _THREAD_SAFE_METHOD_; Joypad &joy = joy_names[p_device]; //printf("got button %i, mapping is %i\n", p_button, joy.mapping); @@ -925,7 +867,6 @@ void Input::joy_button(int p_device, int p_button, bool p_pressed) { } void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { - _THREAD_SAFE_METHOD_; ERR_FAIL_INDEX(p_axis, JOY_AXIS_MAX); @@ -937,13 +878,10 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { } if (p_value.value > joy.last_axis[p_axis]) { - if (p_value.value < joy.last_axis[p_axis] + joy.filter) { - return; } } else if (p_value.value > joy.last_axis[p_axis] - joy.filter) { - return; } @@ -972,7 +910,6 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { JoyEvent map = _get_mapped_axis_event(map_db[joy.mapping], p_axis, p_value); if (map.type == TYPE_BUTTON) { - if (map.index == JOY_BUTTON_DPAD_UP || map.index == JOY_BUTTON_DPAD_DOWN) { bool pressed = p_value.value != 0.0f; int button = p_value.value < 0 ? JOY_BUTTON_DPAD_UP : JOY_BUTTON_DPAD_DOWN; @@ -1023,7 +960,6 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { } if (map.type == TYPE_AXIS) { - _axis_event(p_device, map.index, map.value); return; } @@ -1031,7 +967,6 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { } void Input::joy_hat(int p_device, int p_val) { - _THREAD_SAFE_METHOD_; const Joypad &joy = joy_names[p_device]; @@ -1077,7 +1012,6 @@ void Input::joy_hat(int p_device, int p_val) { } void Input::_button_event(int p_device, int p_index, bool p_pressed) { - Ref<InputEventJoypadButton> ievent; ievent.instance(); ievent->set_device(p_device); @@ -1088,7 +1022,6 @@ void Input::_button_event(int p_device, int p_index, bool p_pressed) { } void Input::_axis_event(int p_device, int p_axis, float p_value) { - Ref<InputEventJoypadMotion> ievent; ievent.instance(); ievent->set_device(p_device); @@ -1099,7 +1032,6 @@ void Input::_axis_event(int p_device, int p_axis, float p_value) { }; Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button) { - JoyEvent event; event.type = TYPE_MAX; @@ -1123,7 +1055,6 @@ Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, } Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, const JoyAxis &p_value) { - JoyEvent event; event.type = TYPE_MAX; @@ -1180,11 +1111,9 @@ Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, i } void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, JoyEvent r_events[]) { - for (int i = 0; i < mapping.bindings.size(); i++) { const JoyBinding binding = mapping.bindings[i]; if (binding.inputType == TYPE_HAT && binding.input.hat.hat == p_hat) { - int index; switch (binding.input.hat.hat_mask) { case HAT_MASK_UP: @@ -1220,7 +1149,6 @@ void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, J } JoyButtonList Input::_get_output_button(String output) { - for (int i = 0; _joy_buttons[i]; i++) { if (output == _joy_buttons[i]) return JoyButtonList(i); @@ -1229,7 +1157,6 @@ JoyButtonList Input::_get_output_button(String output) { } JoyAxisList Input::_get_output_axis(String output) { - for (int i = 0; _joy_axes[i]; i++) { if (output == _joy_axes[i]) return JoyAxisList(i); @@ -1238,7 +1165,6 @@ JoyAxisList Input::_get_output_axis(String output) { } void Input::parse_mapping(String p_mapping) { - _THREAD_SAFE_METHOD_; JoyDeviceMapping mapping; @@ -1255,7 +1181,6 @@ void Input::parse_mapping(String p_mapping) { int idx = 1; while (++idx < entry.size()) { - if (entry[idx] == "") continue; @@ -1361,7 +1286,6 @@ void Input::remove_joy_mapping(String p_guid) { } void Input::set_fallback_mapping(String p_guid) { - for (int i = 0; i < map_db.size(); i++) { if (map_db[i].uid == p_guid) { fallback_mapping = i; @@ -1431,7 +1355,6 @@ int Input::get_joy_axis_index_from_string(String p_axis) { } Input::Input() { - singleton = this; // Parse default mappings. diff --git a/core/input/input.h b/core/input/input.h index f3150a8127..91e3b83b95 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -128,7 +128,6 @@ private: int mouse_from_touch_index = -1; struct SpeedTrack { - uint64_t last_tick; Vector2 speed; Vector2 accum; diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 9d3f8f9424..094ed0bc56 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -45,26 +45,22 @@ int InputEvent::get_device() const { } bool InputEvent::is_action(const StringName &p_action) const { - return InputMap::get_singleton()->event_is_action(Ref<InputEvent>((InputEvent *)this), p_action); } bool InputEvent::is_action_pressed(const StringName &p_action, bool p_allow_echo) const { - bool pressed; bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed); return valid && pressed && (p_allow_echo || !is_echo()); } bool InputEvent::is_action_released(const StringName &p_action) const { - bool pressed; bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed); return valid && !pressed; } float InputEvent::get_action_strength(const StringName &p_action) const { - bool pressed; float strength; bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed, &strength); @@ -72,42 +68,34 @@ float InputEvent::get_action_strength(const StringName &p_action) const { } bool InputEvent::is_pressed() const { - return false; } bool InputEvent::is_echo() const { - return false; } Ref<InputEvent> InputEvent::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - return Ref<InputEvent>((InputEvent *)this); } String InputEvent::as_text() const { - return String(); } bool InputEvent::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { - return false; } bool InputEvent::shortcut_match(const Ref<InputEvent> &p_event) const { - return false; } bool InputEvent::is_action_type() const { - return false; } void InputEvent::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_device", "device"), &InputEvent::set_device); ClassDB::bind_method(D_METHOD("get_device"), &InputEvent::get_device); @@ -135,7 +123,6 @@ void InputEvent::_bind_methods() { /////////////////////////////////// void InputEventFromWindow::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_window_id", "id"), &InputEventFromWindow::set_window_id); ClassDB::bind_method(D_METHOD("get_window_id"), &InputEventFromWindow::get_window_id); ADD_PROPERTY(PropertyInfo(Variant::INT, "window_id"), "set_window_id", "get_window_id"); @@ -151,53 +138,42 @@ int64_t InputEventFromWindow::get_window_id() const { /////////////////////////////////// void InputEventWithModifiers::set_shift(bool p_enabled) { - shift = p_enabled; } bool InputEventWithModifiers::get_shift() const { - return shift; } void InputEventWithModifiers::set_alt(bool p_enabled) { - alt = p_enabled; } bool InputEventWithModifiers::get_alt() const { - return alt; } void InputEventWithModifiers::set_control(bool p_enabled) { - control = p_enabled; } bool InputEventWithModifiers::get_control() const { - return control; } void InputEventWithModifiers::set_metakey(bool p_enabled) { - meta = p_enabled; } bool InputEventWithModifiers::get_metakey() const { - return meta; } void InputEventWithModifiers::set_command(bool p_enabled) { - command = p_enabled; } bool InputEventWithModifiers::get_command() const { - return command; } void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModifiers *event) { - set_alt(event->get_alt()); set_shift(event->get_shift()); set_control(event->get_control()); @@ -205,7 +181,6 @@ void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModif } void InputEventWithModifiers::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_alt", "enable"), &InputEventWithModifiers::set_alt); ClassDB::bind_method(D_METHOD("get_alt"), &InputEventWithModifiers::get_alt); @@ -231,57 +206,46 @@ void InputEventWithModifiers::_bind_methods() { /////////////////////////////////// void InputEventKey::set_pressed(bool p_pressed) { - pressed = p_pressed; } bool InputEventKey::is_pressed() const { - return pressed; } void InputEventKey::set_keycode(uint32_t p_keycode) { - keycode = p_keycode; } uint32_t InputEventKey::get_keycode() const { - return keycode; } void InputEventKey::set_physical_keycode(uint32_t p_keycode) { - physical_keycode = p_keycode; } uint32_t InputEventKey::get_physical_keycode() const { - return physical_keycode; } void InputEventKey::set_unicode(uint32_t p_unicode) { - unicode = p_unicode; } uint32_t InputEventKey::get_unicode() const { - return unicode; } void InputEventKey::set_echo(bool p_enable) { - echo = p_enable; } bool InputEventKey::is_echo() const { - return echo; } uint32_t InputEventKey::get_keycode_with_modifiers() const { - uint32_t sc = keycode; if (get_control()) sc |= KEY_MASK_CTRL; @@ -296,7 +260,6 @@ uint32_t InputEventKey::get_keycode_with_modifiers() const { } uint32_t InputEventKey::get_physical_keycode_with_modifiers() const { - uint32_t sc = physical_keycode; if (get_control()) sc |= KEY_MASK_CTRL; @@ -311,7 +274,6 @@ uint32_t InputEventKey::get_physical_keycode_with_modifiers() const { } String InputEventKey::as_text() const { - String kc = keycode_get_string(keycode); if (kc == String()) return kc; @@ -332,7 +294,6 @@ String InputEventKey::as_text() const { } bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { - Ref<InputEventKey> key = p_event; if (key.is_null()) return false; @@ -359,7 +320,6 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed } bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const { - Ref<InputEventKey> key = p_event; if (key.is_null()) return false; @@ -371,7 +331,6 @@ bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const { } void InputEventKey::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventKey::set_pressed); ClassDB::bind_method(D_METHOD("set_keycode", "keycode"), &InputEventKey::set_keycode); @@ -398,34 +357,27 @@ void InputEventKey::_bind_methods() { /////////////////////////////////// void InputEventMouse::set_button_mask(int p_mask) { - button_mask = p_mask; } int InputEventMouse::get_button_mask() const { - return button_mask; } void InputEventMouse::set_position(const Vector2 &p_pos) { - pos = p_pos; } Vector2 InputEventMouse::get_position() const { - return pos; } void InputEventMouse::set_global_position(const Vector2 &p_global_pos) { - global_pos = p_global_pos; } Vector2 InputEventMouse::get_global_position() const { - return global_pos; } void InputEventMouse::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_button_mask", "button_mask"), &InputEventMouse::set_button_mask); ClassDB::bind_method(D_METHOD("get_button_mask"), &InputEventMouse::get_button_mask); @@ -443,44 +395,35 @@ void InputEventMouse::_bind_methods() { /////////////////////////////////// void InputEventMouseButton::set_factor(float p_factor) { - factor = p_factor; } float InputEventMouseButton::get_factor() const { - return factor; } void InputEventMouseButton::set_button_index(int p_index) { - button_index = p_index; } int InputEventMouseButton::get_button_index() const { - return button_index; } void InputEventMouseButton::set_pressed(bool p_pressed) { - pressed = p_pressed; } bool InputEventMouseButton::is_pressed() const { - return pressed; } void InputEventMouseButton::set_doubleclick(bool p_doubleclick) { - doubleclick = p_doubleclick; } bool InputEventMouseButton::is_doubleclick() const { - return doubleclick; } Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - Vector2 g = get_global_position(); Vector2 l = p_xform.xform(get_position() + p_local_ofs); @@ -504,7 +447,6 @@ Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, co } bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { - Ref<InputEventMouseButton> mb = p_event; if (mb.is_null()) return false; @@ -521,7 +463,6 @@ bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p } String InputEventMouseButton::as_text() const { - String button_index_string = ""; switch (get_button_index()) { case BUTTON_LEFT: @@ -559,7 +500,6 @@ String InputEventMouseButton::as_text() const { } void InputEventMouseButton::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMouseButton::set_factor); ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMouseButton::get_factor); @@ -581,47 +521,38 @@ void InputEventMouseButton::_bind_methods() { /////////////////////////////////// void InputEventMouseMotion::set_tilt(const Vector2 &p_tilt) { - tilt = p_tilt; } Vector2 InputEventMouseMotion::get_tilt() const { - return tilt; } void InputEventMouseMotion::set_pressure(float p_pressure) { - pressure = p_pressure; } float InputEventMouseMotion::get_pressure() const { - return pressure; } void InputEventMouseMotion::set_relative(const Vector2 &p_relative) { - relative = p_relative; } Vector2 InputEventMouseMotion::get_relative() const { - return relative; } void InputEventMouseMotion::set_speed(const Vector2 &p_speed) { - speed = p_speed; } Vector2 InputEventMouseMotion::get_speed() const { - return speed; } Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - Vector2 g = get_global_position(); Vector2 l = p_xform.xform(get_position() + p_local_ofs); Vector2 r = p_xform.basis_xform(get_relative()); @@ -648,7 +579,6 @@ Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, co } String InputEventMouseMotion::as_text() const { - String button_mask_string = ""; switch (get_button_mask()) { case BUTTON_MASK_LEFT: @@ -674,7 +604,6 @@ String InputEventMouseMotion::as_text() const { } bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) { - Ref<InputEventMouseMotion> motion = p_event; if (motion.is_null()) return false; @@ -716,7 +645,6 @@ bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) { } void InputEventMouseMotion::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_tilt", "tilt"), &InputEventMouseMotion::set_tilt); ClassDB::bind_method(D_METHOD("get_tilt"), &InputEventMouseMotion::get_tilt); @@ -738,32 +666,26 @@ void InputEventMouseMotion::_bind_methods() { /////////////////////////////////// void InputEventJoypadMotion::set_axis(int p_axis) { - axis = p_axis; } int InputEventJoypadMotion::get_axis() const { - return axis; } void InputEventJoypadMotion::set_axis_value(float p_value) { - axis_value = p_value; } float InputEventJoypadMotion::get_axis_value() const { - return axis_value; } bool InputEventJoypadMotion::is_pressed() const { - return Math::abs(axis_value) >= 0.5f; } bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { - Ref<InputEventJoypadMotion> jm = p_event; if (jm.is_null()) return false; @@ -790,12 +712,10 @@ bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool * } String InputEventJoypadMotion::as_text() const { - return "InputEventJoypadMotion : axis=" + itos(axis) + ", axis_value=" + String(Variant(axis_value)); } void InputEventJoypadMotion::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_axis", "axis"), &InputEventJoypadMotion::set_axis); ClassDB::bind_method(D_METHOD("get_axis"), &InputEventJoypadMotion::get_axis); @@ -809,35 +729,28 @@ void InputEventJoypadMotion::_bind_methods() { /////////////////////////////////// void InputEventJoypadButton::set_button_index(int p_index) { - button_index = p_index; } int InputEventJoypadButton::get_button_index() const { - return button_index; } void InputEventJoypadButton::set_pressed(bool p_pressed) { - pressed = p_pressed; } bool InputEventJoypadButton::is_pressed() const { - return pressed; } void InputEventJoypadButton::set_pressure(float p_pressure) { - pressure = p_pressure; } float InputEventJoypadButton::get_pressure() const { - return pressure; } bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { - Ref<InputEventJoypadButton> jb = p_event; if (jb.is_null()) return false; @@ -854,7 +767,6 @@ bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool * } bool InputEventJoypadButton::shortcut_match(const Ref<InputEvent> &p_event) const { - Ref<InputEventJoypadButton> button = p_event; if (button.is_null()) return false; @@ -863,12 +775,10 @@ bool InputEventJoypadButton::shortcut_match(const Ref<InputEvent> &p_event) cons } String InputEventJoypadButton::as_text() const { - return "InputEventJoypadButton : button_index=" + itos(button_index) + ", pressed=" + (pressed ? "true" : "false") + ", pressure=" + String(Variant(pressure)); } void InputEventJoypadButton::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventJoypadButton::set_button_index); ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventJoypadButton::get_button_index); @@ -886,34 +796,27 @@ void InputEventJoypadButton::_bind_methods() { /////////////////////////////////// void InputEventScreenTouch::set_index(int p_index) { - index = p_index; } int InputEventScreenTouch::get_index() const { - return index; } void InputEventScreenTouch::set_position(const Vector2 &p_pos) { - pos = p_pos; } Vector2 InputEventScreenTouch::get_position() const { - return pos; } void InputEventScreenTouch::set_pressed(bool p_pressed) { - pressed = p_pressed; } bool InputEventScreenTouch::is_pressed() const { - return pressed; } Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - Ref<InputEventScreenTouch> st; st.instance(); st->set_device(get_device()); @@ -926,12 +829,10 @@ Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, co } String InputEventScreenTouch::as_text() const { - return "InputEventScreenTouch : index=" + itos(index) + ", pressed=" + (pressed ? "true" : "false") + ", position=(" + String(get_position()) + ")"; } 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); @@ -949,44 +850,35 @@ void InputEventScreenTouch::_bind_methods() { /////////////////////////////////// void InputEventScreenDrag::set_index(int p_index) { - index = p_index; } int InputEventScreenDrag::get_index() const { - return index; } void InputEventScreenDrag::set_position(const Vector2 &p_pos) { - pos = p_pos; } Vector2 InputEventScreenDrag::get_position() const { - return pos; } void InputEventScreenDrag::set_relative(const Vector2 &p_relative) { - relative = p_relative; } Vector2 InputEventScreenDrag::get_relative() const { - return relative; } void InputEventScreenDrag::set_speed(const Vector2 &p_speed) { - speed = p_speed; } Vector2 InputEventScreenDrag::get_speed() const { - return speed; } Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - Ref<InputEventScreenDrag> sd; sd.instance(); @@ -1003,12 +895,10 @@ Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, con } String InputEventScreenDrag::as_text() const { - return "InputEventScreenDrag : index=" + itos(index) + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")"; } void InputEventScreenDrag::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenDrag::set_index); ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenDrag::get_index); @@ -1030,20 +920,16 @@ void InputEventScreenDrag::_bind_methods() { /////////////////////////////////// void InputEventAction::set_action(const StringName &p_action) { - action = p_action; } StringName InputEventAction::get_action() const { - return action; } void InputEventAction::set_pressed(bool p_pressed) { - pressed = p_pressed; } bool InputEventAction::is_pressed() const { - return pressed; } @@ -1063,12 +949,10 @@ bool InputEventAction::shortcut_match(const Ref<InputEvent> &p_event) const { } bool InputEventAction::is_action(const StringName &p_action) const { - return action == p_action; } bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { - Ref<InputEventAction> act = p_event; if (act.is_null()) return false; @@ -1084,12 +968,10 @@ bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pres } String InputEventAction::as_text() const { - return "InputEventAction : action=" + action + ", pressed=(" + (pressed ? "true" : "false"); } void InputEventAction::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_action", "action"), &InputEventAction::set_action); ClassDB::bind_method(D_METHOD("get_action"), &InputEventAction::get_action); @@ -1109,12 +991,10 @@ void InputEventAction::_bind_methods() { /////////////////////////////////// void InputEventGesture::set_position(const Vector2 &p_pos) { - pos = p_pos; } void InputEventGesture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventGesture::set_position); ClassDB::bind_method(D_METHOD("get_position"), &InputEventGesture::get_position); @@ -1122,24 +1002,20 @@ void InputEventGesture::_bind_methods() { } Vector2 InputEventGesture::get_position() const { - return pos; } /////////////////////////////////// void InputEventMagnifyGesture::set_factor(real_t p_factor) { - factor = p_factor; } real_t InputEventMagnifyGesture::get_factor() const { - return factor; } Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - Ref<InputEventMagnifyGesture> ev; ev.instance(); @@ -1155,12 +1031,10 @@ Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform, } String InputEventMagnifyGesture::as_text() const { - return "InputEventMagnifyGesture : factor=" + rtos(get_factor()) + ", position=(" + String(get_position()) + ")"; } void InputEventMagnifyGesture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMagnifyGesture::set_factor); ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMagnifyGesture::get_factor); @@ -1170,7 +1044,6 @@ void InputEventMagnifyGesture::_bind_methods() { /////////////////////////////////// void InputEventPanGesture::set_delta(const Vector2 &p_delta) { - delta = p_delta; } @@ -1179,7 +1052,6 @@ Vector2 InputEventPanGesture::get_delta() const { } Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - Ref<InputEventPanGesture> ev; ev.instance(); @@ -1195,12 +1067,10 @@ Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, con } String InputEventPanGesture::as_text() const { - return "InputEventPanGesture : delta=(" + String(get_delta()) + "), position=(" + String(get_position()) + ")"; } void InputEventPanGesture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_delta", "delta"), &InputEventPanGesture::set_delta); ClassDB::bind_method(D_METHOD("get_delta"), &InputEventPanGesture::get_delta); @@ -1210,7 +1080,6 @@ void InputEventPanGesture::_bind_methods() { /////////////////////////////////// void InputEventMIDI::set_channel(const int p_channel) { - channel = p_channel; } @@ -1219,7 +1088,6 @@ int InputEventMIDI::get_channel() const { } void InputEventMIDI::set_message(const int p_message) { - message = p_message; } @@ -1228,7 +1096,6 @@ int InputEventMIDI::get_message() const { } void InputEventMIDI::set_pitch(const int p_pitch) { - pitch = p_pitch; } @@ -1237,7 +1104,6 @@ int InputEventMIDI::get_pitch() const { } void InputEventMIDI::set_velocity(const int p_velocity) { - velocity = p_velocity; } @@ -1246,7 +1112,6 @@ int InputEventMIDI::get_velocity() const { } void InputEventMIDI::set_instrument(const int p_instrument) { - instrument = p_instrument; } @@ -1255,7 +1120,6 @@ int InputEventMIDI::get_instrument() const { } void InputEventMIDI::set_pressure(const int p_pressure) { - pressure = p_pressure; } @@ -1264,7 +1128,6 @@ int InputEventMIDI::get_pressure() const { } void InputEventMIDI::set_controller_number(const int p_controller_number) { - controller_number = p_controller_number; } @@ -1273,7 +1136,6 @@ int InputEventMIDI::get_controller_number() const { } void InputEventMIDI::set_controller_value(const int p_controller_value) { - controller_value = p_controller_value; } @@ -1282,12 +1144,10 @@ int InputEventMIDI::get_controller_value() const { } String InputEventMIDI::as_text() const { - return "InputEventMIDI : channel=(" + itos(get_channel()) + "), message=(" + itos(get_message()) + ")"; } void InputEventMIDI::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_channel", "channel"), &InputEventMIDI::set_channel); ClassDB::bind_method(D_METHOD("get_channel"), &InputEventMIDI::get_channel); ClassDB::bind_method(D_METHOD("set_message", "message"), &InputEventMIDI::set_message); diff --git a/core/input/input_event.h b/core/input/input_event.h index 18792076f5..dd1cc11982 100644 --- a/core/input/input_event.h +++ b/core/input/input_event.h @@ -192,7 +192,6 @@ public: }; class InputEventFromWindow : public InputEvent { - GDCLASS(InputEventFromWindow, InputEvent); int64_t window_id = 0; @@ -252,7 +251,6 @@ public: }; class InputEventKey : public InputEventWithModifiers { - GDCLASS(InputEventKey, InputEventWithModifiers); bool pressed = false; /// otherwise release @@ -296,7 +294,6 @@ public: }; class InputEventMouse : public InputEventWithModifiers { - GDCLASS(InputEventMouse, InputEventWithModifiers); int button_mask = 0; @@ -321,7 +318,6 @@ public: }; class InputEventMouseButton : public InputEventMouse { - GDCLASS(InputEventMouseButton, InputEventMouse); float factor = 1; @@ -355,7 +351,6 @@ public: }; class InputEventMouseMotion : public InputEventMouse { - GDCLASS(InputEventMouseMotion, InputEventMouse); Vector2 tilt; @@ -388,7 +383,6 @@ public: }; class InputEventJoypadMotion : public InputEvent { - GDCLASS(InputEventJoypadMotion, InputEvent); int axis = 0; ///< Joypad axis float axis_value = 0; ///< -1 to 1 @@ -467,7 +461,6 @@ public: }; class InputEventScreenDrag : public InputEventFromWindow { - GDCLASS(InputEventScreenDrag, InputEventFromWindow); int index = 0; Vector2 pos; @@ -497,7 +490,6 @@ public: }; class InputEventAction : public InputEvent { - GDCLASS(InputEventAction, InputEvent); StringName action; @@ -529,7 +521,6 @@ public: }; class InputEventGesture : public InputEventWithModifiers { - GDCLASS(InputEventGesture, InputEventWithModifiers); Vector2 pos; @@ -543,7 +534,6 @@ public: }; class InputEventMagnifyGesture : public InputEventGesture { - GDCLASS(InputEventMagnifyGesture, InputEventGesture); real_t factor = 1.0; @@ -561,7 +551,6 @@ public: }; class InputEventPanGesture : public InputEventGesture { - GDCLASS(InputEventPanGesture, InputEventGesture); Vector2 delta; diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp index 6b6acf062d..d341b5ba4c 100644 --- a/core/input/input_map.cpp +++ b/core/input/input_map.cpp @@ -38,7 +38,6 @@ InputMap *InputMap::singleton = nullptr; int InputMap::ALL_DEVICES = -1; void InputMap::_bind_methods() { - ClassDB::bind_method(D_METHOD("has_action", "action"), &InputMap::has_action); ClassDB::bind_method(D_METHOD("get_actions"), &InputMap::_get_actions); ClassDB::bind_method(D_METHOD("add_action", "action", "deadzone"), &InputMap::add_action, DEFVAL(0.5f)); @@ -55,7 +54,6 @@ void InputMap::_bind_methods() { } void InputMap::add_action(const StringName &p_action, float p_deadzone) { - ERR_FAIL_COND_MSG(input_map.has(p_action), "InputMap already has action '" + String(p_action) + "'."); input_map[p_action] = Action(); static int last_id = 1; @@ -65,20 +63,17 @@ void InputMap::add_action(const StringName &p_action, float p_deadzone) { } void InputMap::erase_action(const StringName &p_action) { - ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); input_map.erase(p_action); } Array InputMap::_get_actions() { - Array ret; List<StringName> actions = get_actions(); if (actions.empty()) return ret; for (const List<StringName>::Element *E = actions.front(); E; E = E->next()) { - ret.push_back(E->get()); } @@ -86,7 +81,6 @@ Array InputMap::_get_actions() { } List<StringName> InputMap::get_actions() const { - List<StringName> actions = List<StringName>(); if (input_map.empty()) { return actions; @@ -100,9 +94,7 @@ List<StringName> InputMap::get_actions() const { } List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength) const { - for (List<Ref<InputEvent>>::Element *E = p_action.inputs.front(); E; E = E->next()) { - const Ref<InputEvent> e = E->get(); //if (e.type != Ref<InputEvent>::KEY && e.device != p_event.device) -- unsure about the KEY comparison, why is this here? @@ -120,19 +112,16 @@ List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Re } bool InputMap::has_action(const StringName &p_action) const { - return input_map.has(p_action); } void InputMap::action_set_deadzone(const StringName &p_action, float p_deadzone) { - ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); input_map[p_action].deadzone = p_deadzone; } void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event) { - ERR_FAIL_COND_MSG(p_event.is_null(), "It's not a reference to a valid InputEvent object."); ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); if (_find_event(input_map[p_action], p_event)) @@ -142,13 +131,11 @@ void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent } bool InputMap::action_has_event(const StringName &p_action, const Ref<InputEvent> &p_event) { - ERR_FAIL_COND_V_MSG(!input_map.has(p_action), false, "Request for nonexistent InputMap action '" + String(p_action) + "'."); return (_find_event(input_map[p_action], p_event) != nullptr); } void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEvent> &p_event) { - ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); List<Ref<InputEvent>>::Element *E = _find_event(input_map[p_action], p_event); @@ -157,19 +144,16 @@ void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEve } void InputMap::action_erase_events(const StringName &p_action) { - ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); input_map[p_action].inputs.clear(); } Array InputMap::_get_action_list(const StringName &p_action) { - Array ret; const List<Ref<InputEvent>> *al = get_action_list(p_action); if (al) { for (const List<Ref<InputEvent>>::Element *E = al->front(); E; E = E->next()) { - ret.push_back(E->get()); } } @@ -178,7 +162,6 @@ Array InputMap::_get_action_list(const StringName &p_action) { } const List<Ref<InputEvent>> *InputMap::get_action_list(const StringName &p_action) { - const Map<StringName, Action>::Element *E = input_map.find(p_action); if (!E) return nullptr; @@ -222,7 +205,6 @@ const Map<StringName, InputMap::Action> &InputMap::get_action_map() const { } void InputMap::load_from_globals() { - input_map.clear(); List<PropertyInfo> pinfo; @@ -251,7 +233,6 @@ void InputMap::load_from_globals() { } void InputMap::load_default() { - Ref<InputEventKey> key; add_action("ui_accept"); @@ -332,7 +313,6 @@ void InputMap::load_default() { } InputMap::InputMap() { - ERR_FAIL_COND_MSG(singleton, "Singleton in InputMap already exist."); singleton = this; } diff --git a/core/input/input_map.h b/core/input/input_map.h index e03bc5fd4f..3abc224ccf 100644 --- a/core/input/input_map.h +++ b/core/input/input_map.h @@ -35,7 +35,6 @@ #include "core/object.h" class InputMap : public Object { - GDCLASS(InputMap, Object); public: diff --git a/core/io/compression.cpp b/core/io/compression.cpp index 20c9fdca6f..1b6786d888 100644 --- a/core/io/compression.cpp +++ b/core/io/compression.cpp @@ -40,10 +40,8 @@ #include <zstd.h> int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, Mode p_mode) { - switch (p_mode) { case MODE_FASTLZ: { - if (p_src_size < 16) { uint8_t src[16]; zeromem(&src[p_src_size], 16 - p_src_size); @@ -56,7 +54,6 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, } break; case MODE_DEFLATE: case MODE_GZIP: { - int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16; z_stream strm; @@ -97,10 +94,8 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, } int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) { - switch (p_mode) { case MODE_FASTLZ: { - int ss = p_src_size + p_src_size * 6 / 100; if (ss < 66) ss = 66; @@ -109,7 +104,6 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) { } break; case MODE_DEFLATE: case MODE_GZIP: { - int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16; z_stream strm; @@ -124,7 +118,6 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) { return aout; } break; case MODE_ZSTD: { - return ZSTD_compressBound(p_src_size); } break; } @@ -133,10 +126,8 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) { } int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size, Mode p_mode) { - switch (p_mode) { case MODE_FASTLZ: { - int ret_size = 0; if (p_dst_max_size < 16) { @@ -150,7 +141,6 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p } break; case MODE_DEFLATE: case MODE_GZIP: { - int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16; z_stream strm; diff --git a/core/io/compression.h b/core/io/compression.h index 3e7c125d8e..f195f96ba5 100644 --- a/core/io/compression.h +++ b/core/io/compression.h @@ -34,7 +34,6 @@ #include "core/typedefs.h" class Compression { - public: static int zlib_level; static int gzip_level; diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index 73230e3a3c..902d3cde9f 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -35,14 +35,12 @@ #include "core/variant_parser.h" PackedStringArray ConfigFile::_get_sections() const { - List<String> s; get_sections(&s); PackedStringArray arr; arr.resize(s.size()); int idx = 0; for (const List<String>::Element *E = s.front(); E; E = E->next()) { - arr.set(idx++, E->get()); } @@ -50,14 +48,12 @@ PackedStringArray ConfigFile::_get_sections() const { } PackedStringArray ConfigFile::_get_section_keys(const String &p_section) const { - List<String> s; get_section_keys(p_section, &s); PackedStringArray arr; arr.resize(s.size()); int idx = 0; for (const List<String>::Element *E = s.front(); E; E = E->next()) { - arr.set(idx++, E->get()); } @@ -65,7 +61,6 @@ PackedStringArray ConfigFile::_get_section_keys(const String &p_section) const { } void ConfigFile::set_value(const String &p_section, const String &p_key, const Variant &p_value) { - if (p_value.get_type() == Variant::NIL) { //erase if (!values.has(p_section)) @@ -84,7 +79,6 @@ void ConfigFile::set_value(const String &p_section, const String &p_key, const V } } Variant ConfigFile::get_value(const String &p_section, const String &p_key, Variant p_default) const { - if (!values.has(p_section) || !values[p_section].has(p_key)) { ERR_FAIL_COND_V_MSG(p_default.get_type() == Variant::NIL, Variant(), vformat("Couldn't find the given section \"%s\" and key \"%s\", and no default was given.", p_section, p_key)); @@ -95,24 +89,20 @@ Variant ConfigFile::get_value(const String &p_section, const String &p_key, Vari } bool ConfigFile::has_section(const String &p_section) const { - return values.has(p_section); } bool ConfigFile::has_section_key(const String &p_section, const String &p_key) const { - if (!values.has(p_section)) return false; return values[p_section].has(p_key); } void ConfigFile::get_sections(List<String> *r_sections) const { - for (OrderedHashMap<String, OrderedHashMap<String, Variant>>::ConstElement E = values.front(); E; E = E.next()) { r_sections->push_back(E.key()); } } void ConfigFile::get_section_keys(const String &p_section, List<String> *r_keys) const { - ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot get keys from nonexistent section \"%s\".", p_section)); for (OrderedHashMap<String, Variant>::ConstElement E = values[p_section].front(); E; E = E.next()) { @@ -121,13 +111,11 @@ void ConfigFile::get_section_keys(const String &p_section, List<String> *r_keys) } void ConfigFile::erase_section(const String &p_section) { - ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot erase nonexistent section \"%s\".", p_section)); values.erase(p_section); } void ConfigFile::erase_section_key(const String &p_section, const String &p_key) { - ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot erase key \"%s\" from nonexistent section \"%s\".", p_key, p_section)); ERR_FAIL_COND_MSG(!values[p_section].has(p_key), vformat("Cannot erase nonexistent key \"%s\" from section \"%s\".", p_key, p_section)); @@ -135,7 +123,6 @@ void ConfigFile::erase_section_key(const String &p_section, const String &p_key) } Error ConfigFile::save(const String &p_path) { - Error err; FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err); @@ -149,7 +136,6 @@ Error ConfigFile::save(const String &p_path) { } Error ConfigFile::save_encrypted(const String &p_path, const Vector<uint8_t> &p_key) { - Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err); @@ -167,7 +153,6 @@ Error ConfigFile::save_encrypted(const String &p_path, const Vector<uint8_t> &p_ } Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass) { - Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err); @@ -186,15 +171,12 @@ Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass } Error ConfigFile::_internal_save(FileAccess *file) { - for (OrderedHashMap<String, OrderedHashMap<String, Variant>>::Element E = values.front(); E; E = E.next()) { - if (E != values.front()) file->store_string("\n"); file->store_string("[" + E.key() + "]\n\n"); for (OrderedHashMap<String, Variant>::Element F = E.get().front(); F; F = F.next()) { - String vstr; VariantWriter::write_to_string(F.get(), vstr); file->store_string(F.key() + "=" + vstr + "\n"); @@ -207,7 +189,6 @@ Error ConfigFile::_internal_save(FileAccess *file) { } Error ConfigFile::load(const String &p_path) { - Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); @@ -218,7 +199,6 @@ Error ConfigFile::load(const String &p_path) { } Error ConfigFile::load_encrypted(const String &p_path, const Vector<uint8_t> &p_key) { - Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); @@ -236,7 +216,6 @@ Error ConfigFile::load_encrypted(const String &p_path, const Vector<uint8_t> &p_ } Error ConfigFile::load_encrypted_pass(const String &p_path, const String &p_pass) { - Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); @@ -255,7 +234,6 @@ Error ConfigFile::load_encrypted_pass(const String &p_path, const String &p_pass } Error ConfigFile::_internal_load(const String &p_path, FileAccess *f) { - VariantParser::StreamFile stream; stream.f = f; @@ -267,14 +245,12 @@ Error ConfigFile::_internal_load(const String &p_path, FileAccess *f) { } Error ConfigFile::parse(const String &p_data) { - VariantParser::StreamString stream; stream.s = p_data; return _parse("<string>", &stream); } Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream) { - String assign; Variant value; VariantParser::Tag next_tag; @@ -285,7 +261,6 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream) String section; while (true) { - assign = Variant(); next_tag.fields.clear(); next_tag.name = String(); @@ -309,7 +284,6 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream) } void ConfigFile::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_value", "section", "key", "value"), &ConfigFile::set_value); ClassDB::bind_method(D_METHOD("get_value", "section", "key", "default"), &ConfigFile::get_value, DEFVAL(Variant())); diff --git a/core/io/config_file.h b/core/io/config_file.h index 39fc2ab412..ae06960f02 100644 --- a/core/io/config_file.h +++ b/core/io/config_file.h @@ -37,7 +37,6 @@ #include "core/variant_parser.h" class ConfigFile : public Reference { - GDCLASS(ConfigFile, Reference); OrderedHashMap<String, OrderedHashMap<String, Variant>> values; diff --git a/core/io/dtls_server.cpp b/core/io/dtls_server.cpp index 7cbf5c618e..0278027c50 100644 --- a/core/io/dtls_server.cpp +++ b/core/io/dtls_server.cpp @@ -37,7 +37,6 @@ DTLSServer *(*DTLSServer::_create)() = nullptr; bool DTLSServer::available = false; DTLSServer *DTLSServer::create() { - return _create(); } @@ -46,7 +45,6 @@ bool DTLSServer::is_available() { } void DTLSServer::_bind_methods() { - ClassDB::bind_method(D_METHOD("setup", "key", "certificate", "chain"), &DTLSServer::setup, DEFVAL(Ref<X509Certificate>())); ClassDB::bind_method(D_METHOD("take_connection", "udp_peer"), &DTLSServer::take_connection); } diff --git a/core/io/file_access_buffered.cpp b/core/io/file_access_buffered.cpp index 2df91a4dd8..6208f3a4d1 100644 --- a/core/io/file_access_buffered.cpp +++ b/core/io/file_access_buffered.cpp @@ -33,28 +33,23 @@ #include "core/error_macros.h" Error FileAccessBuffered::set_error(Error p_error) const { - return (last_error = p_error); } void FileAccessBuffered::set_cache_size(int p_size) { - cache_size = p_size; } int FileAccessBuffered::get_cache_size() { - return cache_size; } int FileAccessBuffered::cache_data_left() const { - if (file.offset >= file.size) { return 0; } if (cache.offset == -1 || file.offset < cache.offset || file.offset >= cache.offset + cache.buffer.size()) { - return read_data_block(file.offset, cache_size); } @@ -62,37 +57,30 @@ int FileAccessBuffered::cache_data_left() const { } void FileAccessBuffered::seek(size_t p_position) { - file.offset = p_position; } void FileAccessBuffered::seek_end(int64_t p_position) { - file.offset = file.size + p_position; } size_t FileAccessBuffered::get_position() const { - return file.offset; } size_t FileAccessBuffered::get_len() const { - return file.size; } bool FileAccessBuffered::eof_reached() const { - return file.offset > file.size; } uint8_t FileAccessBuffered::get_8() const { - ERR_FAIL_COND_V_MSG(!file.open, 0, "Can't get data, when file is not opened."); uint8_t byte = 0; if (cache_data_left() >= 1) { - byte = cache.buffer[file.offset - cache.offset]; } @@ -102,15 +90,12 @@ uint8_t FileAccessBuffered::get_8() const { } int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_length) const { - ERR_FAIL_COND_V_MSG(!file.open, -1, "Can't get buffer, when file is not opened."); if (p_length > cache_size) { - int total_read = 0; if (!(cache.offset == -1 || file.offset < cache.offset || file.offset >= cache.offset + cache.buffer.size())) { - int size = (cache.buffer.size() - (file.offset - cache.offset)); size = size - (size % 4); //const uint8_t* read = cache.buffer.ptr(); @@ -134,7 +119,6 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_length) const { int to_read = p_length; int total_read = 0; while (to_read > 0) { - int left = cache_data_left(); if (left == 0) { file.offset += to_read; @@ -158,11 +142,9 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_length) const { } bool FileAccessBuffered::is_open() const { - return file.open; } Error FileAccessBuffered::get_error() const { - return last_error; } diff --git a/core/io/file_access_buffered.h b/core/io/file_access_buffered.h index f473886330..61c0fa7489 100644 --- a/core/io/file_access_buffered.h +++ b/core/io/file_access_buffered.h @@ -36,7 +36,6 @@ #include "core/ustring.h" class FileAccessBuffered : public FileAccess { - public: enum { DEFAULT_CACHE_SIZE = 128 * 1024, @@ -52,7 +51,6 @@ protected: Error set_error(Error p_error) const; mutable struct File { - bool open; int size; int offset; @@ -61,7 +59,6 @@ protected: } file; mutable struct Cache { - Vector<uint8_t> buffer; int offset; } cache; diff --git a/core/io/file_access_buffered_fa.h b/core/io/file_access_buffered_fa.h index edb4ff9a9f..3ea98584a4 100644 --- a/core/io/file_access_buffered_fa.h +++ b/core/io/file_access_buffered_fa.h @@ -35,22 +35,18 @@ template <class T> class FileAccessBufferedFA : public FileAccessBuffered { - T f; int read_data_block(int p_offset, int p_size, uint8_t *p_dest = 0) const { - ERR_FAIL_COND_V_MSG(!f.is_open(), -1, "Can't read data block when file is not opened."); ((T *)&f)->seek(p_offset); if (p_dest) { - f.get_buffer(p_dest, p_size); return p_size; } else { - cache.offset = p_offset; cache.buffer.resize(p_size); @@ -66,7 +62,6 @@ class FileAccessBufferedFA : public FileAccessBuffered { }; static FileAccess *create() { - return memnew(FileAccessBufferedFA<T>()); }; @@ -78,27 +73,22 @@ protected: public: void flush() { - f.flush(); }; void store_8(uint8_t p_dest) { - f.store_8(p_dest); }; void store_buffer(const uint8_t *p_src, int p_length) { - f.store_buffer(p_src, p_length); }; bool file_exists(const String &p_name) { - return f.file_exists(p_name); }; Error _open(const String &p_path, int p_mode_flags) { - close(); Error ret = f._open(p_path, p_mode_flags); @@ -119,7 +109,6 @@ public: }; void close() { - f.close(); file.offset = 0; @@ -133,7 +122,6 @@ public: }; virtual uint64_t _get_modified_time(const String &p_file) { - return f._get_modified_time(p_file); } diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp index f2827b519e..cbb9786af4 100644 --- a/core/io/file_access_compressed.cpp +++ b/core/io/file_access_compressed.cpp @@ -33,7 +33,6 @@ #include "core/print_string.h" void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_mode, int p_block_size) { - magic = p_magic.ascii().get_data(); if (magic.length() > 4) magic = magic.substr(0, 4); @@ -59,7 +58,6 @@ void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_ } Error FileAccessCompressed::open_after_magic(FileAccess *p_base) { - f = p_base; cmode = (Compression::Mode)f->get_32(); block_size = f->get_32(); @@ -72,7 +70,6 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) { int acc_ofs = f->get_position() + bc * 4; int max_bs = 0; for (int i = 0; i < bc; i++) { - ReadBlock rb; rb.offset = acc_ofs; rb.csize = f->get_32(); @@ -98,7 +95,6 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) { } Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) { - ERR_FAIL_COND_V(p_mode_flags == READ_WRITE, ERR_UNAVAILABLE); if (f) @@ -114,7 +110,6 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) { } if (p_mode_flags & WRITE) { - buffer.clear(); writing = true; write_pos = 0; @@ -125,7 +120,6 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) { //don't store anything else unless it's done saving! } else { - char rmagic[5]; f->get_buffer((uint8_t *)rmagic, 4); rmagic[4] = 0; @@ -139,7 +133,6 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) { return OK; } void FileAccessCompressed::close() { - if (!f) return; @@ -159,7 +152,6 @@ void FileAccessCompressed::close() { Vector<int> block_sizes; for (int i = 0; i < bc; i++) { - int bl = i == (bc - 1) ? write_max % block_size : block_size; uint8_t *bp = &write_ptr[i * block_size]; @@ -180,7 +172,6 @@ void FileAccessCompressed::close() { buffer.clear(); } else { - comp_buffer.clear(); buffer.clear(); read_blocks.clear(); @@ -191,21 +182,17 @@ void FileAccessCompressed::close() { } bool FileAccessCompressed::is_open() const { - return f != nullptr; } void FileAccessCompressed::seek(size_t p_position) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); if (writing) { - ERR_FAIL_COND(p_position > write_max); write_pos = p_position; } else { - ERR_FAIL_COND(p_position > read_total); if (p_position == read_total) { at_end = true; @@ -214,7 +201,6 @@ void FileAccessCompressed::seek(size_t p_position) { read_eof = false; int block_idx = p_position / block_size; if (block_idx != read_block) { - read_block = block_idx; f->seek(read_blocks[read_block].offset); f->get_buffer(comp_buffer.ptrw(), read_blocks[read_block].csize); @@ -228,32 +214,24 @@ void FileAccessCompressed::seek(size_t p_position) { } void FileAccessCompressed::seek_end(int64_t p_position) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); if (writing) { - seek(write_max + p_position); } else { - seek(read_total + p_position); } } size_t FileAccessCompressed::get_position() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); if (writing) { - return write_pos; } else { - return read_block * block_size + read_pos; } } size_t FileAccessCompressed::get_len() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); if (writing) { - return write_max; } else { return read_total; @@ -261,7 +239,6 @@ size_t FileAccessCompressed::get_len() const { } bool FileAccessCompressed::eof_reached() const { - ERR_FAIL_COND_V_MSG(!f, false, "File must be opened before use."); if (writing) { return false; @@ -271,7 +248,6 @@ bool FileAccessCompressed::eof_reached() const { } uint8_t FileAccessCompressed::get_8() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode."); @@ -302,7 +278,6 @@ uint8_t FileAccessCompressed::get_8() const { return ret; } int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode."); @@ -312,7 +287,6 @@ int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const { } for (int i = 0; i < p_length; i++) { - p_dst[i] = read_ptr[read_pos]; read_pos++; if (read_pos >= read_block_size) { @@ -339,7 +313,6 @@ int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const { } Error FileAccessCompressed::get_error() const { - return read_eof ? ERR_FILE_EOF : OK; } @@ -351,7 +324,6 @@ void FileAccessCompressed::flush() { } void FileAccessCompressed::store_8(uint8_t p_dest) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); ERR_FAIL_COND_MSG(!writing, "File has not been opened in read mode."); @@ -360,7 +332,6 @@ void FileAccessCompressed::store_8(uint8_t p_dest) { } bool FileAccessCompressed::file_exists(const String &p_name) { - FileAccess *fa = FileAccess::open(p_name, FileAccess::READ); if (!fa) return false; @@ -369,7 +340,6 @@ bool FileAccessCompressed::file_exists(const String &p_name) { } uint64_t FileAccessCompressed::_get_modified_time(const String &p_file) { - if (f) return f->get_modified_time(p_file); else @@ -390,7 +360,6 @@ Error FileAccessCompressed::_set_unix_permissions(const String &p_file, uint32_t } FileAccessCompressed::~FileAccessCompressed() { - if (f) close(); } diff --git a/core/io/file_access_compressed.h b/core/io/file_access_compressed.h index f192be0883..52284b347e 100644 --- a/core/io/file_access_compressed.h +++ b/core/io/file_access_compressed.h @@ -35,7 +35,6 @@ #include "core/os/file_access.h" class FileAccessCompressed : public FileAccess { - Compression::Mode cmode = Compression::MODE_ZSTD; bool writing = false; uint32_t write_pos = 0; diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp index 271c34ec4a..aaf21ad143 100644 --- a/core/io/file_access_encrypted.cpp +++ b/core/io/file_access_encrypted.cpp @@ -40,7 +40,6 @@ #define COMP_MAGIC 0x43454447 Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8_t> &p_key, Mode p_mode) { - ERR_FAIL_COND_V_MSG(file != nullptr, ERR_ALREADY_IN_USE, "Can't open file while another file from path '" + file->get_path_absolute() + "' is open."); ERR_FAIL_COND_V(p_key.size() != 32, ERR_INVALID_PARAMETER); @@ -48,7 +47,6 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8 eofed = false; if (p_mode == MODE_WRITE_AES256) { - data.clear(); writing = true; file = p_base; @@ -56,7 +54,6 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8 key = p_key; } else if (p_mode == MODE_READ) { - writing = false; key = p_key; uint32_t magic = p_base->get_32(); @@ -85,7 +82,6 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8 ctx.set_decode_key(key.ptrw(), 256); for (size_t i = 0; i < ds; i += 16) { - ctx.decrypt_ecb(&data.write[i], &data.write[i]); } @@ -103,13 +99,11 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8 } Error FileAccessEncrypted::open_and_parse_password(FileAccess *p_base, const String &p_key, Mode p_mode) { - String cs = p_key.md5_text(); ERR_FAIL_COND_V(cs.length() != 32, ERR_INVALID_PARAMETER); Vector<uint8_t> key; key.resize(32); for (int i = 0; i < 32; i++) { - key.write[i] = cs[i]; } @@ -117,16 +111,13 @@ Error FileAccessEncrypted::open_and_parse_password(FileAccess *p_base, const Str } Error FileAccessEncrypted::_open(const String &p_path, int p_mode_flags) { - return OK; } void FileAccessEncrypted::close() { - if (!file) return; if (writing) { - Vector<uint8_t> compressed; size_t len = data.size(); if (len % 16) { @@ -146,7 +137,6 @@ void FileAccessEncrypted::close() { ctx.set_encode_key(key.ptrw(), 256); for (size_t i = 0; i < len; i += 16) { - ctx.encrypt_ecb(&compressed.write[i], &compressed.write[i]); } @@ -163,7 +153,6 @@ void FileAccessEncrypted::close() { data.clear(); } else { - file->close(); memdelete(file); data.clear(); @@ -172,12 +161,10 @@ void FileAccessEncrypted::close() { } bool FileAccessEncrypted::is_open() const { - return file != nullptr; } String FileAccessEncrypted::get_path() const { - if (file) return file->get_path(); else @@ -185,7 +172,6 @@ String FileAccessEncrypted::get_path() const { } String FileAccessEncrypted::get_path_absolute() const { - if (file) return file->get_path_absolute(); else @@ -193,7 +179,6 @@ String FileAccessEncrypted::get_path_absolute() const { } void FileAccessEncrypted::seek(size_t p_position) { - if (p_position > (size_t)data.size()) p_position = data.size(); @@ -202,25 +187,20 @@ void FileAccessEncrypted::seek(size_t p_position) { } void FileAccessEncrypted::seek_end(int64_t p_position) { - seek(data.size() + p_position); } size_t FileAccessEncrypted::get_position() const { - return pos; } size_t FileAccessEncrypted::get_len() const { - return data.size(); } bool FileAccessEncrypted::eof_reached() const { - return eofed; } uint8_t FileAccessEncrypted::get_8() const { - ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode."); if (pos >= data.size()) { eofed = true; @@ -232,12 +212,10 @@ uint8_t FileAccessEncrypted::get_8() const { return b; } int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const { - ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode."); int to_copy = MIN(p_length, data.size() - pos); for (int i = 0; i < to_copy; i++) { - p_dst[i] = data[pos++]; } @@ -249,25 +227,19 @@ int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const { } Error FileAccessEncrypted::get_error() const { - return eofed ? ERR_FILE_EOF : OK; } void FileAccessEncrypted::store_buffer(const uint8_t *p_src, int p_length) { - ERR_FAIL_COND_MSG(!writing, "File has not been opened in read mode."); if (pos < data.size()) { - for (int i = 0; i < p_length; i++) { - store_8(p_src[i]); } } else if (pos == data.size()) { - data.resize(pos + p_length); for (int i = 0; i < p_length; i++) { - data.write[pos + i] = p_src[i]; } pos += p_length; @@ -281,7 +253,6 @@ void FileAccessEncrypted::flush() { } void FileAccessEncrypted::store_8(uint8_t p_dest) { - ERR_FAIL_COND_MSG(!writing, "File has not been opened in read mode."); if (pos < data.size()) { @@ -294,7 +265,6 @@ void FileAccessEncrypted::store_8(uint8_t p_dest) { } bool FileAccessEncrypted::file_exists(const String &p_name) { - FileAccess *fa = FileAccess::open(p_name, FileAccess::READ); if (!fa) return false; @@ -303,12 +273,10 @@ bool FileAccessEncrypted::file_exists(const String &p_name) { } uint64_t FileAccessEncrypted::_get_modified_time(const String &p_file) { - return 0; } uint32_t FileAccessEncrypted::_get_unix_permissions(const String &p_file) { - return 0; } @@ -318,7 +286,6 @@ Error FileAccessEncrypted::_set_unix_permissions(const String &p_file, uint32_t } FileAccessEncrypted::~FileAccessEncrypted() { - if (file) close(); } diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp index a3e04a4538..790f946752 100644 --- a/core/io/file_access_memory.cpp +++ b/core/io/file_access_memory.cpp @@ -38,7 +38,6 @@ static Map<String, Vector<uint8_t>> *files = nullptr; void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) { - if (!files) { files = memnew((Map<String, Vector<uint8_t>>)); } @@ -54,7 +53,6 @@ void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) { } void FileAccessMemory::cleanup() { - if (!files) return; @@ -62,12 +60,10 @@ void FileAccessMemory::cleanup() { } FileAccess *FileAccessMemory::create() { - return memnew(FileAccessMemory); } bool FileAccessMemory::file_exists(const String &p_name) { - String name = fix_path(p_name); //name = DirAccess::normalize_path(name); @@ -75,7 +71,6 @@ bool FileAccessMemory::file_exists(const String &p_name) { } Error FileAccessMemory::open_custom(const uint8_t *p_data, int p_len) { - data = (uint8_t *)p_data; length = p_len; pos = 0; @@ -83,7 +78,6 @@ Error FileAccessMemory::open_custom(const uint8_t *p_data, int p_len) { } Error FileAccessMemory::_open(const String &p_path, int p_mode_flags) { - ERR_FAIL_COND_V(!files, ERR_FILE_NOT_FOUND); String name = fix_path(p_path); @@ -100,46 +94,38 @@ Error FileAccessMemory::_open(const String &p_path, int p_mode_flags) { } void FileAccessMemory::close() { - data = nullptr; } bool FileAccessMemory::is_open() const { - return data != nullptr; } void FileAccessMemory::seek(size_t p_position) { - ERR_FAIL_COND(!data); pos = p_position; } void FileAccessMemory::seek_end(int64_t p_position) { - ERR_FAIL_COND(!data); pos = length + p_position; } size_t FileAccessMemory::get_position() const { - ERR_FAIL_COND_V(!data, 0); return pos; } size_t FileAccessMemory::get_len() const { - ERR_FAIL_COND_V(!data, 0); return length; } bool FileAccessMemory::eof_reached() const { - return pos > length; } uint8_t FileAccessMemory::get_8() const { - uint8_t ret = 0; if (pos < length) { ret = data[pos]; @@ -150,7 +136,6 @@ uint8_t FileAccessMemory::get_8() const { } int FileAccessMemory::get_buffer(uint8_t *p_dst, int p_length) const { - ERR_FAIL_COND_V(!data, -1); int left = length - pos; @@ -167,7 +152,6 @@ int FileAccessMemory::get_buffer(uint8_t *p_dst, int p_length) const { } Error FileAccessMemory::get_error() const { - return pos >= length ? ERR_FILE_EOF : OK; } @@ -176,14 +160,12 @@ void FileAccessMemory::flush() { } void FileAccessMemory::store_8(uint8_t p_byte) { - ERR_FAIL_COND(!data); ERR_FAIL_COND(pos >= length); data[pos++] = p_byte; } void FileAccessMemory::store_buffer(const uint8_t *p_src, int p_length) { - int left = length - pos; int write = MIN(p_length, left); if (write < p_length) { diff --git a/core/io/file_access_memory.h b/core/io/file_access_memory.h index d8be989b20..1a9bd3fbbb 100644 --- a/core/io/file_access_memory.h +++ b/core/io/file_access_memory.h @@ -34,7 +34,6 @@ #include "core/os/file_access.h" class FileAccessMemory : public FileAccess { - uint8_t *data = nullptr; int length; mutable int pos; diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 00f504c391..690a2bb269 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -41,19 +41,16 @@ #define DEBUG_TIME(m_what) void FileAccessNetworkClient::lock_mutex() { - mutex.lock(); lockcount++; } void FileAccessNetworkClient::unlock_mutex() { - lockcount--; mutex.unlock(); } void FileAccessNetworkClient::put_32(int p_32) { - uint8_t buf[4]; encode_uint32(p_32, buf); client->put_data(buf, 4); @@ -61,7 +58,6 @@ void FileAccessNetworkClient::put_32(int p_32) { } void FileAccessNetworkClient::put_64(int64_t p_64) { - uint8_t buf[8]; encode_uint64(p_64, buf); client->put_data(buf, 8); @@ -69,24 +65,20 @@ void FileAccessNetworkClient::put_64(int64_t p_64) { } int FileAccessNetworkClient::get_32() { - uint8_t buf[4]; client->get_data(buf, 4); return decode_uint32(buf); } int64_t FileAccessNetworkClient::get_64() { - uint8_t buf[8]; client->get_data(buf, 8); return decode_uint64(buf); } void FileAccessNetworkClient::_thread_func() { - client->set_no_delay(true); while (!quit) { - DEBUG_PRINT("SEM WAIT - " + itos(sem->get())); sem.wait(); DEBUG_TIME("sem_unlock"); @@ -127,9 +119,7 @@ void FileAccessNetworkClient::_thread_func() { fa = accesses[id]; switch (response) { - case FileAccessNetwork::RESPONSE_OPEN: { - DEBUG_TIME("sem_open"); int status = get_32(); if (status != OK) { @@ -143,7 +133,6 @@ void FileAccessNetworkClient::_thread_func() { } break; case FileAccessNetwork::RESPONSE_DATA: { - int64_t offset = get_64(); uint32_t len = get_32(); @@ -156,14 +145,12 @@ void FileAccessNetworkClient::_thread_func() { } break; case FileAccessNetwork::RESPONSE_FILE_EXISTS: { - int status = get_32(); fa->exists_modtime = status != 0; fa->sem.post(); } break; case FileAccessNetwork::RESPONSE_GET_MODTIME: { - uint64_t status = get_64(); fa->exists_modtime = status; fa->sem.post(); @@ -176,14 +163,12 @@ void FileAccessNetworkClient::_thread_func() { } void FileAccessNetworkClient::_thread_func(void *s) { - FileAccessNetworkClient *self = (FileAccessNetworkClient *)s; self->_thread_func(); } Error FileAccessNetworkClient::connect(const String &p_host, int p_port, const String &p_password) { - IP_Address ip; if (p_host.is_valid_ip_address()) { @@ -236,7 +221,6 @@ FileAccessNetworkClient::~FileAccessNetworkClient() { } void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block) { - int page = p_offset / page_size; ERR_FAIL_INDEX(page, pages.size()); if (page < pages.size() - 1) { @@ -258,7 +242,6 @@ void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block) } void FileAccessNetwork::_respond(size_t p_len, Error p_status) { - DEBUG_PRINT("GOT RESPONSE - len: " + itos(p_len) + " status: " + itos(p_status)); response = p_status; if (response != OK) @@ -270,7 +253,6 @@ void FileAccessNetwork::_respond(size_t p_len, Error p_status) { } Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) { - ERR_FAIL_COND_V(p_mode_flags != READ, ERR_UNAVAILABLE); if (opened) close(); @@ -305,7 +287,6 @@ Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) { } void FileAccessNetwork::close() { - if (!opened) return; @@ -320,12 +301,10 @@ void FileAccessNetwork::close() { nc->unlock_mutex(); } bool FileAccessNetwork::is_open() const { - return opened; } void FileAccessNetwork::seek(size_t p_position) { - ERR_FAIL_COND_MSG(!opened, "File must be opened before use."); eof_flag = p_position > total_size; @@ -337,39 +316,32 @@ void FileAccessNetwork::seek(size_t p_position) { } void FileAccessNetwork::seek_end(int64_t p_position) { - seek(total_size + p_position); } size_t FileAccessNetwork::get_position() const { - ERR_FAIL_COND_V_MSG(!opened, 0, "File must be opened before use."); return pos; } size_t FileAccessNetwork::get_len() const { - ERR_FAIL_COND_V_MSG(!opened, 0, "File must be opened before use."); return total_size; } bool FileAccessNetwork::eof_reached() const { - ERR_FAIL_COND_V_MSG(!opened, false, "File must be opened before use."); return eof_flag; } uint8_t FileAccessNetwork::get_8() const { - uint8_t v; get_buffer(&v, 1); return v; } void FileAccessNetwork::_queue_page(int p_page) const { - if (p_page >= pages.size()) return; if (pages[p_page].buffer.empty() && !pages[p_page].queued) { - FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; { MutexLock lock(nc->blockrequest_mutex); @@ -388,7 +360,6 @@ void FileAccessNetwork::_queue_page(int p_page) const { } int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const { - //bool eof=false; if (pos + p_length > total_size) { eof_flag = true; @@ -402,7 +373,6 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const { uint8_t *buff = last_page_buff; for (int i = 0; i < p_length; i++) { - int page = pos / page_size; if (page != last_page) { @@ -410,7 +380,6 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const { if (pages[page].buffer.empty()) { waiting_on_page = page; for (int j = 0; j < read_ahead; j++) { - _queue_page(page + j); } buffer_mutex.unlock(); @@ -418,9 +387,7 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const { page_sem.wait(); DEBUG_PRINT("done"); } else { - for (int j = 0; j < read_ahead; j++) { - _queue_page(page + j); } //queue pages @@ -440,7 +407,6 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const { } Error FileAccessNetwork::get_error() const { - return pos == total_size ? ERR_FILE_EOF : OK; } @@ -449,12 +415,10 @@ void FileAccessNetwork::flush() { } void FileAccessNetwork::store_8(uint8_t p_dest) { - ERR_FAIL(); } bool FileAccessNetwork::file_exists(const String &p_path) { - FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; nc->lock_mutex(); nc->put_32(id); @@ -471,7 +435,6 @@ bool FileAccessNetwork::file_exists(const String &p_path) { } uint64_t FileAccessNetwork::_get_modified_time(const String &p_file) { - FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; nc->lock_mutex(); nc->put_32(id); @@ -498,7 +461,6 @@ Error FileAccessNetwork::_set_unix_permissions(const String &p_file, uint32_t p_ } void FileAccessNetwork::configure() { - GLOBAL_DEF("network/remote_fs/page_size", 65536); ProjectSettings::get_singleton()->set_custom_property_info("network/remote_fs/page_size", PropertyInfo(Variant::INT, "network/remote_fs/page_size", PROPERTY_HINT_RANGE, "1,65536,1,or_greater")); //is used as denominator and can't be zero GLOBAL_DEF("network/remote_fs/page_read_ahead", 4); @@ -506,7 +468,6 @@ void FileAccessNetwork::configure() { } FileAccessNetwork::FileAccessNetwork() { - FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; nc->lock_mutex(); id = nc->last_id++; @@ -517,7 +478,6 @@ FileAccessNetwork::FileAccessNetwork() { } FileAccessNetwork::~FileAccessNetwork() { - close(); FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; diff --git a/core/io/file_access_network.h b/core/io/file_access_network.h index 6cdd6af0b4..dc5ce1e883 100644 --- a/core/io/file_access_network.h +++ b/core/io/file_access_network.h @@ -39,9 +39,7 @@ class FileAccessNetwork; class FileAccessNetworkClient { - struct BlockRequest { - int id; uint64_t offset; int size; @@ -84,7 +82,6 @@ public: }; class FileAccessNetwork : public FileAccess { - Semaphore sem; Semaphore page_sem; Mutex buffer_mutex; diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index d70f2ba445..4fd4d117af 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -35,11 +35,8 @@ #include <stdio.h> Error PackedData::add_pack(const String &p_path, bool p_replace_files) { - for (int i = 0; i < sources.size(); i++) { - if (sources[i]->try_open_pack(p_path, p_replace_files)) { - return OK; }; }; @@ -48,7 +45,6 @@ Error PackedData::add_pack(const String &p_path, bool p_replace_files) { }; void PackedData::add_path(const String &pkg_path, const String &path, uint64_t ofs, uint64_t size, const uint8_t *p_md5, PackSource *p_src, bool p_replace_files) { - PathMD5 pmd5(path.md5_buffer()); //printf("adding path %ls, %lli, %lli\n", path.c_str(), pmd5.a, pmd5.b); @@ -75,9 +71,7 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o Vector<String> ds = p.get_base_dir().split("/"); for (int j = 0; j < ds.size(); j++) { - if (!cd->subdirs.has(ds[j])) { - PackedDir *pd = memnew(PackedDir); pd->name = ds[j]; pd->parent = cd; @@ -97,7 +91,6 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o } void PackedData::add_pack_source(PackSource *p_source) { - if (p_source != nullptr) { sources.push_back(p_source); } @@ -106,7 +99,6 @@ void PackedData::add_pack_source(PackSource *p_source) { PackedData *PackedData::singleton = nullptr; PackedData::PackedData() { - singleton = this; root = memnew(PackedDir); @@ -114,14 +106,12 @@ PackedData::PackedData() { } void PackedData::_free_packed_dirs(PackedDir *p_dir) { - for (Map<String, PackedDir *>::Element *E = p_dir->subdirs.front(); E; E = E->next()) _free_packed_dirs(E->get()); memdelete(p_dir); } PackedData::~PackedData() { - for (int i = 0; i < sources.size(); i++) { memdelete(sources[i]); } @@ -131,7 +121,6 @@ PackedData::~PackedData() { ////////////////////////////////////////////////////////////////// bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files) { - FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) return false; @@ -144,7 +133,6 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files) f->seek(f->get_position() - 4); magic = f->get_32(); if (magic != PACK_HEADER_MAGIC) { - f->close(); memdelete(f); return false; @@ -156,7 +144,6 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files) magic = f->get_32(); if (magic != PACK_HEADER_MAGIC) { - f->close(); memdelete(f); return false; @@ -187,7 +174,6 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files) int file_count = f->get_32(); for (int i = 0; i < file_count; i++) { - uint32_t sl = f->get_32(); CharString cs; cs.resize(sl + 1); @@ -210,30 +196,25 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files) }; FileAccess *PackedSourcePCK::get_file(const String &p_path, PackedData::PackedFile *p_file) { - return memnew(FileAccessPack(p_path, *p_file)); }; ////////////////////////////////////////////////////////////////// Error FileAccessPack::_open(const String &p_path, int p_mode_flags) { - ERR_FAIL_V(ERR_UNAVAILABLE); return ERR_UNAVAILABLE; } void FileAccessPack::close() { - f->close(); } bool FileAccessPack::is_open() const { - return f->is_open(); } void FileAccessPack::seek(size_t p_position) { - if (p_position > pf.size) { eof = true; } else { @@ -244,25 +225,20 @@ void FileAccessPack::seek(size_t p_position) { pos = p_position; } void FileAccessPack::seek_end(int64_t p_position) { - seek(pf.size + p_position); } size_t FileAccessPack::get_position() const { - return pos; } size_t FileAccessPack::get_len() const { - return pf.size; } bool FileAccessPack::eof_reached() const { - return eof; } uint8_t FileAccessPack::get_8() const { - if (pos >= pf.size) { eof = true; return 0; @@ -273,7 +249,6 @@ uint8_t FileAccessPack::get_8() const { } int FileAccessPack::get_buffer(uint8_t *p_dst, int p_length) const { - if (eof) return 0; @@ -298,36 +273,30 @@ void FileAccessPack::set_endian_swap(bool p_swap) { } Error FileAccessPack::get_error() const { - if (eof) return ERR_FILE_EOF; return OK; } void FileAccessPack::flush() { - ERR_FAIL(); } void FileAccessPack::store_8(uint8_t p_dest) { - ERR_FAIL(); } void FileAccessPack::store_buffer(const uint8_t *p_src, int p_length) { - ERR_FAIL(); } bool FileAccessPack::file_exists(const String &p_name) { - return false; } FileAccessPack::FileAccessPack(const String &p_path, const PackedData::PackedFile &p_file) : pf(p_file), f(FileAccess::open(pf.pack, FileAccess::READ)) { - ERR_FAIL_COND_MSG(!f, "Can't open pack-referenced file '" + String(pf.pack) + "'."); f->seek(pf.offset); @@ -345,17 +314,14 @@ FileAccessPack::~FileAccessPack() { ////////////////////////////////////////////////////////////////////////////////// Error DirAccessPack::list_dir_begin() { - list_dirs.clear(); list_files.clear(); for (Map<String, PackedData::PackedDir *>::Element *E = current->subdirs.front(); E; E = E->next()) { - list_dirs.push_back(E->key()); } for (Set<String>::Element *E = current->files.front(); E; E = E->next()) { - list_files.push_back(E->get()); } @@ -363,7 +329,6 @@ Error DirAccessPack::list_dir_begin() { } String DirAccessPack::get_next() { - if (list_dirs.size()) { cdir = true; String d = list_dirs.front()->get(); @@ -379,30 +344,24 @@ String DirAccessPack::get_next() { } } bool DirAccessPack::current_is_dir() const { - return cdir; } bool DirAccessPack::current_is_hidden() const { - return false; } void DirAccessPack::list_dir_end() { - list_dirs.clear(); list_files.clear(); } int DirAccessPack::get_drive_count() { - return 0; } String DirAccessPack::get_drive(int p_drive) { - return ""; } Error DirAccessPack::change_dir(String p_dir) { - String nd = p_dir.replace("\\", "/"); bool absolute = false; if (nd.begins_with("res://")) { @@ -430,7 +389,6 @@ Error DirAccessPack::change_dir(String p_dir) { pd = current; for (int i = 0; i < paths.size(); i++) { - String p = paths[i]; if (p == ".") { continue; @@ -439,11 +397,9 @@ Error DirAccessPack::change_dir(String p_dir) { pd = pd->parent; } } else if (pd->subdirs.has(p)) { - pd = pd->subdirs[p]; } else { - return ERR_INVALID_PARAMETER; } } @@ -454,7 +410,6 @@ Error DirAccessPack::change_dir(String p_dir) { } String DirAccessPack::get_current_dir(bool p_include_drive) { - PackedData::PackedDir *pd = current; String p = current->name; @@ -467,35 +422,29 @@ String DirAccessPack::get_current_dir(bool p_include_drive) { } bool DirAccessPack::file_exists(String p_file) { - p_file = fix_path(p_file); return current->files.has(p_file); } bool DirAccessPack::dir_exists(String p_dir) { - p_dir = fix_path(p_dir); return current->subdirs.has(p_dir); } Error DirAccessPack::make_dir(String p_dir) { - return ERR_UNAVAILABLE; } Error DirAccessPack::rename(String p_from, String p_to) { - return ERR_UNAVAILABLE; } Error DirAccessPack::remove(String p_name) { - return ERR_UNAVAILABLE; } size_t DirAccessPack::get_space_left() { - return 0; } diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h index aa3a14272b..a5d4c1f1b6 100644 --- a/core/io/file_access_pack.h +++ b/core/io/file_access_pack.h @@ -51,7 +51,6 @@ class PackedData { public: struct PackedFile { - String pack; uint64_t offset; //if offset is ZERO, the file was ERASED uint64_t size; @@ -71,7 +70,6 @@ private: uint64_t a = 0; uint64_t b = 0; bool operator<(const PathMD5 &p_md5) const { - if (p_md5.a == a) { return b < p_md5.b; } else { @@ -120,7 +118,6 @@ public: }; class PackSource { - public: virtual bool try_open_pack(const String &p_path, bool p_replace_files) = 0; virtual FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file) = 0; @@ -128,14 +125,12 @@ public: }; class PackedSourcePCK : public PackSource { - public: virtual bool try_open_pack(const String &p_path, bool p_replace_files); virtual FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file); }; class FileAccessPack : public FileAccess { - PackedData::PackedFile pf; mutable size_t pos; @@ -178,7 +173,6 @@ public: }; FileAccess *PackedData::try_open_path(const String &p_path) { - PathMD5 pmd5(p_path.md5_buffer()); Map<PathMD5, PackedFile>::Element *E = files.find(pmd5); if (!E) @@ -190,12 +184,10 @@ FileAccess *PackedData::try_open_path(const String &p_path) { } bool PackedData::has_path(const String &p_path) { - return files.has(PathMD5(p_path.md5_buffer())); } class DirAccessPack : public DirAccess { - PackedData::PackedDir *current; List<String> list_dirs; diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp index 9d068fe809..5dde5aa6ce 100644 --- a/core/io/file_access_zip.cpp +++ b/core/io/file_access_zip.cpp @@ -40,7 +40,6 @@ ZipArchive *ZipArchive::instance = nullptr; extern "C" { static void *godot_open(void *data, const char *p_fname, int mode) { - if (mode & ZLIB_FILEFUNC_MODE_WRITE) { return nullptr; } @@ -52,30 +51,25 @@ static void *godot_open(void *data, const char *p_fname, int mode) { } static uLong godot_read(void *data, void *fdata, void *buf, uLong size) { - FileAccess *f = (FileAccess *)data; f->get_buffer((uint8_t *)buf, size); return size; } static uLong godot_write(voidpf opaque, voidpf stream, const void *buf, uLong size) { - return 0; } static long godot_tell(voidpf opaque, voidpf stream) { - FileAccess *f = (FileAccess *)opaque; return f->get_position(); } static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) { - FileAccess *f = (FileAccess *)opaque; int pos = offset; switch (origin) { - case ZLIB_FILEFUNC_SEEK_CUR: pos = f->get_position() + offset; break; @@ -91,32 +85,27 @@ static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) { } static int godot_close(voidpf opaque, voidpf stream) { - FileAccess *f = (FileAccess *)opaque; f->close(); return 0; } static int godot_testerror(voidpf opaque, voidpf stream) { - FileAccess *f = (FileAccess *)opaque; return f->get_error() != OK ? 1 : 0; } static voidpf godot_alloc(voidpf opaque, uInt items, uInt size) { - return memalloc(items * size); } static void godot_free(voidpf opaque, voidpf address) { - memfree(address); } } // extern "C" void ZipArchive::close_handle(unzFile p_file) const { - ERR_FAIL_COND_MSG(!p_file, "Cannot close a file if none is open."); FileAccess *f = (FileAccess *)unzGetOpaque(p_file); unzCloseCurrentFile(p_file); @@ -125,7 +114,6 @@ void ZipArchive::close_handle(unzFile p_file) const { } unzFile ZipArchive::get_file_handle(String p_file) const { - ERR_FAIL_COND_V_MSG(!file_exists(p_file), nullptr, "File '" + p_file + " doesn't exist."); File file = files[p_file]; @@ -152,7 +140,6 @@ unzFile ZipArchive::get_file_handle(String p_file) const { ERR_FAIL_COND_V(!pkg, nullptr); int unz_err = unzGoToFilePos(pkg, &file.file_pos); if (unz_err != UNZ_OK || unzOpenCurrentFile(pkg) != UNZ_OK) { - unzClose(pkg); ERR_FAIL_V(nullptr); } @@ -161,7 +148,6 @@ unzFile ZipArchive::get_file_handle(String p_file) const { } bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files) { - //printf("opening zip pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz")); if (p_path.get_extension().nocasecmp_to("zip") != 0 && p_path.get_extension().nocasecmp_to("pcz") != 0) return false; @@ -195,7 +181,6 @@ bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files) { int pkg_num = packages.size() - 1; for (uint64_t i = 0; i < gi.number_entry; i++) { - char filename_inzip[256]; unz_file_info64 file_info; @@ -222,17 +207,14 @@ bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files) { } bool ZipArchive::file_exists(String p_name) const { - return files.has(p_name); } FileAccess *ZipArchive::get_file(const String &p_path, PackedData::PackedFile *p_file) { - return memnew(FileAccessZip(p_path, *p_file)); } ZipArchive *ZipArchive::get_singleton() { - if (instance == nullptr) { instance = memnew(ZipArchive); } @@ -245,9 +227,7 @@ ZipArchive::ZipArchive() { } ZipArchive::~ZipArchive() { - for (int i = 0; i < packages.size(); i++) { - FileAccess *f = (FileAccess *)unzGetOpaque(packages[i].zfile); unzClose(packages[i].zfile); memdelete(f); @@ -257,7 +237,6 @@ ZipArchive::~ZipArchive() { } Error FileAccessZip::_open(const String &p_path, int p_mode_flags) { - close(); ERR_FAIL_COND_V(p_mode_flags & FileAccess::WRITE, FAILED); @@ -273,7 +252,6 @@ Error FileAccessZip::_open(const String &p_path, int p_mode_flags) { } void FileAccessZip::close() { - if (!zfile) return; @@ -284,50 +262,42 @@ void FileAccessZip::close() { } bool FileAccessZip::is_open() const { - return zfile != nullptr; } void FileAccessZip::seek(size_t p_position) { - ERR_FAIL_COND(!zfile); unzSeekCurrentFile(zfile, p_position); } void FileAccessZip::seek_end(int64_t p_position) { - ERR_FAIL_COND(!zfile); unzSeekCurrentFile(zfile, get_len() + p_position); } size_t FileAccessZip::get_position() const { - ERR_FAIL_COND_V(!zfile, 0); return unztell(zfile); } size_t FileAccessZip::get_len() const { - ERR_FAIL_COND_V(!zfile, 0); return file_info.uncompressed_size; } bool FileAccessZip::eof_reached() const { - ERR_FAIL_COND_V(!zfile, true); return at_eof; } uint8_t FileAccessZip::get_8() const { - uint8_t ret = 0; get_buffer(&ret, 1); return ret; } int FileAccessZip::get_buffer(uint8_t *p_dst, int p_length) const { - ERR_FAIL_COND_V(!zfile, -1); at_eof = unzeof(zfile); if (at_eof) @@ -340,9 +310,7 @@ int FileAccessZip::get_buffer(uint8_t *p_dst, int p_length) const { } Error FileAccessZip::get_error() const { - if (!zfile) { - return ERR_UNCONFIGURED; } if (eof_reached()) { @@ -353,17 +321,14 @@ Error FileAccessZip::get_error() const { } void FileAccessZip::flush() { - ERR_FAIL(); } void FileAccessZip::store_8(uint8_t p_dest) { - ERR_FAIL(); } bool FileAccessZip::file_exists(const String &p_name) { - return false; } diff --git a/core/io/file_access_zip.h b/core/io/file_access_zip.h index 17a3d085b6..776e830f36 100644 --- a/core/io/file_access_zip.h +++ b/core/io/file_access_zip.h @@ -41,10 +41,8 @@ #include <stdlib.h> class ZipArchive : public PackSource { - public: struct File { - int package = -1; unz_file_pos file_pos; File() {} @@ -81,7 +79,6 @@ public: }; class FileAccessZip : public FileAccess { - unzFile zfile; unz_file_info64 file_info; diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index 940bac0009..2a1a435b8e 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -47,7 +47,6 @@ const char *HTTPClient::_methods[METHOD_MAX] = { #ifndef JAVASCRIPT_ENABLED Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, bool p_verify_host) { - close(); conn_port = p_port; @@ -58,10 +57,8 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, String host_lower = conn_host.to_lower(); if (host_lower.begins_with("http://")) { - conn_host = conn_host.substr(7, conn_host.length() - 7); } else if (host_lower.begins_with("https://")) { - ssl = true; conn_host = conn_host.substr(8, conn_host.length() - 8); } @@ -97,7 +94,6 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, } void HTTPClient::set_connection(const Ref<StreamPeer> &p_connection) { - ERR_FAIL_COND_MSG(p_connection.is_null(), "Connection is not a reference to a valid StreamPeer object."); close(); @@ -106,12 +102,10 @@ void HTTPClient::set_connection(const Ref<StreamPeer> &p_connection) { } Ref<StreamPeer> HTTPClient::get_connection() const { - return connection; } Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector<String> &p_headers, const Vector<uint8_t> &p_body) { - ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(!p_url.begins_with("/"), ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER); @@ -179,7 +173,6 @@ Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector } Error HTTPClient::request(Method p_method, const String &p_url, const Vector<String> &p_headers, const String &p_body) { - ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(!p_url.begins_with("/"), ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER); @@ -235,27 +228,22 @@ Error HTTPClient::request(Method p_method, const String &p_url, const Vector<Str } bool HTTPClient::has_response() const { - return response_headers.size() != 0; } bool HTTPClient::is_response_chunked() const { - return chunked; } int HTTPClient::get_response_code() const { - return response_num; } Error HTTPClient::get_response_headers(List<String> *r_response) { - if (!response_headers.size()) return ERR_INVALID_PARAMETER; for (int i = 0; i < response_headers.size(); i++) { - r_response->push_back(response_headers[i]); } @@ -265,7 +253,6 @@ Error HTTPClient::get_response_headers(List<String> *r_response) { } void HTTPClient::close() { - if (tcp_connection->get_status() != StreamPeerTCP::STATUS_NONE) tcp_connection->disconnect_from_host(); @@ -273,7 +260,6 @@ void HTTPClient::close() { status = STATUS_DISCONNECTED; head_request = false; if (resolving != IP::RESOLVER_INVALID_ID) { - IP::get_singleton()->erase_resolve_item(resolving); resolving = IP::RESOLVER_INVALID_ID; } @@ -290,9 +276,7 @@ void HTTPClient::close() { } Error HTTPClient::poll() { - switch (status) { - case STATUS_RESOLVING: { ERR_FAIL_COND_V(resolving == IP::RESOLVER_INVALID_ID, ERR_BUG); @@ -302,7 +286,6 @@ Error HTTPClient::poll() { return OK; // Still resolving case IP::RESOLVER_STATUS_DONE: { - IP_Address host = IP::get_singleton()->get_resolve_item_address(resolving); Error err = tcp_connection->connect_to_host(host, conn_port); IP::get_singleton()->erase_resolve_item(resolving); @@ -316,7 +299,6 @@ Error HTTPClient::poll() { } break; case IP::RESOLVER_STATUS_NONE: case IP::RESOLVER_STATUS_ERROR: { - IP::get_singleton()->erase_resolve_item(resolving); resolving = IP::RESOLVER_INVALID_ID; close(); @@ -326,10 +308,8 @@ Error HTTPClient::poll() { } } break; case STATUS_CONNECTING: { - StreamPeerTCP::Status s = tcp_connection->get_status(); switch (s) { - case StreamPeerTCP::STATUS_CONNECTING: { return OK; } break; @@ -379,7 +359,6 @@ Error HTTPClient::poll() { } break; case StreamPeerTCP::STATUS_ERROR: case StreamPeerTCP::STATUS_NONE: { - close(); status = STATUS_CANT_CONNECT; return ERR_CANT_CONNECT; @@ -404,7 +383,6 @@ Error HTTPClient::poll() { return OK; } break; case STATUS_REQUESTING: { - while (true) { uint8_t byte; int rec = 0; @@ -423,7 +401,6 @@ Error HTTPClient::poll() { if ( (rs >= 2 && response_str[rs - 2] == '\n' && response_str[rs - 1] == '\n') || (rs >= 4 && response_str[rs - 4] == '\r' && response_str[rs - 3] == '\n' && response_str[rs - 2] == '\r' && response_str[rs - 1] == '\n')) { - // End of response, parse. response_str.push_back(0); String response; @@ -445,7 +422,6 @@ Error HTTPClient::poll() { bool keep_alive = true; for (int i = 0; i < responses.size(); i++) { - String header = responses[i].strip_edges(); String s = header.to_lower(); if (s.length() == 0) @@ -464,11 +440,9 @@ Error HTTPClient::poll() { } if (i == 0 && responses[i].begins_with("HTTP")) { - String num = responses[i].get_slicec(' ', 1); response_num = num.to_int(); } else { - response_headers.push_back(header); } } @@ -480,14 +454,11 @@ Error HTTPClient::poll() { } if (body_size != -1 || chunked) { - status = STATUS_BODY; } else if (!keep_alive) { - read_until_eof = true; status = STATUS_BODY; } else { - status = STATUS_CONNECTED; } return OK; @@ -513,21 +484,17 @@ Error HTTPClient::poll() { } int HTTPClient::get_response_body_length() const { - return body_size; } PackedByteArray HTTPClient::read_response_body_chunk() { - ERR_FAIL_COND_V(status != STATUS_BODY, PackedByteArray()); PackedByteArray ret; Error err = OK; if (chunked) { - while (true) { - if (chunk_trailer_part) { // We need to consume the trailer part too or keep-alive will break uint8_t b; @@ -569,7 +536,6 @@ PackedByteArray HTTPClient::read_response_body_chunk() { } if (chunk.size() > 2 && chunk[chunk.size() - 2] == '\r' && chunk[chunk.size() - 1] == '\n') { - int len = 0; for (int i = 0; i < chunk.size() - 2; i++) { char c = chunk[i]; @@ -605,7 +571,6 @@ PackedByteArray HTTPClient::read_response_body_chunk() { chunk.resize(chunk_left); } } else { - int rec = 0; err = _get_http_data(&chunk.write[chunk.size() - chunk_left], chunk_left, rec); if (rec == 0) { @@ -614,7 +579,6 @@ PackedByteArray HTTPClient::read_response_body_chunk() { chunk_left -= rec; if (chunk_left == 0) { - if (chunk[chunk.size() - 2] != '\r' || chunk[chunk.size() - 1] != '\n') { ERR_PRINT("HTTP Invalid chunk terminator (not \\r\\n)"); status = STATUS_CONNECTION_ERROR; @@ -632,7 +596,6 @@ PackedByteArray HTTPClient::read_response_body_chunk() { } } else { - int to_read = !read_until_eof ? MIN(body_left, read_chunk_size) : read_chunk_size; ret.resize(to_read); int _offset = 0; @@ -658,18 +621,14 @@ PackedByteArray HTTPClient::read_response_body_chunk() { } if (err != OK) { - close(); if (err == ERR_FILE_EOF) { - status = STATUS_DISCONNECTED; // Server disconnected } else { - status = STATUS_CONNECTION_ERROR; } } else if (body_left == 0 && !chunked && !read_until_eof) { - status = STATUS_CONNECTED; } @@ -677,24 +636,19 @@ PackedByteArray HTTPClient::read_response_body_chunk() { } HTTPClient::Status HTTPClient::get_status() const { - return status; } void HTTPClient::set_blocking_mode(bool p_enable) { - blocking = p_enable; } bool HTTPClient::is_blocking_mode_enabled() const { - return blocking; } Error HTTPClient::_get_http_data(uint8_t *p_buffer, int p_bytes, int &r_received) { - if (blocking) { - // We can't use StreamPeer.get_data, since when reaching EOF we will get an // error without knowing how many bytes we received. Error err = ERR_FILE_EOF; @@ -767,7 +721,6 @@ String HTTPClient::query_string_from_dict(const Dictionary &p_dict) { } Dictionary HTTPClient::_get_response_headers_as_dictionary() { - List<String> rh; get_response_headers(&rh); Dictionary ret; @@ -785,7 +738,6 @@ Dictionary HTTPClient::_get_response_headers_as_dictionary() { } PackedStringArray HTTPClient::_get_response_headers() { - List<String> rh; get_response_headers(&rh); PackedStringArray ret; @@ -799,7 +751,6 @@ PackedStringArray HTTPClient::_get_response_headers() { } void HTTPClient::_bind_methods() { - ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port", "use_ssl", "verify_host"), &HTTPClient::connect_to_host, DEFVAL(-1), DEFVAL(false), DEFVAL(true)); ClassDB::bind_method(D_METHOD("set_connection", "connection"), &HTTPClient::set_connection); ClassDB::bind_method(D_METHOD("get_connection"), &HTTPClient::get_connection); diff --git a/core/io/http_client.h b/core/io/http_client.h index 05690534ae..1dc1f3d76a 100644 --- a/core/io/http_client.h +++ b/core/io/http_client.h @@ -37,7 +37,6 @@ #include "core/reference.h" class HTTPClient : public Reference { - GDCLASS(HTTPClient, Reference); public: diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index 01e6bb5618..06e3cc029d 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -33,11 +33,9 @@ #include "core/print_string.h" bool ImageFormatLoader::recognize(const String &p_extension) const { - List<String> extensions; get_recognized_extensions(&extensions); for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - if (E->get().nocasecmp_to(p_extension) == 0) return true; } @@ -61,7 +59,6 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_c String extension = p_file.get_extension(); for (int i = 0; i < loader.size(); i++) { - if (!loader[i]->recognize(extension)) continue; Error err = loader[i]->load_image(p_image, f, p_force_linear, p_scale); @@ -70,7 +67,6 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_c } if (err != ERR_FILE_UNRECOGNIZED) { - if (!p_custom) memdelete(f); @@ -85,17 +81,13 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_c } void ImageLoader::get_recognized_extensions(List<String> *p_extensions) { - for (int i = 0; i < loader.size(); i++) { - loader[i]->get_recognized_extensions(p_extensions); } } ImageFormatLoader *ImageLoader::recognize(const String &p_extension) { - for (int i = 0; i < loader.size(); i++) { - if (loader[i]->recognize(p_extension)) return loader[i]; } @@ -106,22 +98,18 @@ ImageFormatLoader *ImageLoader::recognize(const String &p_extension) { Vector<ImageFormatLoader *> ImageLoader::loader; void ImageLoader::add_image_format_loader(ImageFormatLoader *p_loader) { - loader.push_back(p_loader); } void ImageLoader::remove_image_format_loader(ImageFormatLoader *p_loader) { - loader.erase(p_loader); } const Vector<ImageFormatLoader *> &ImageLoader::get_image_format_loaders() { - return loader; } void ImageLoader::cleanup() { - while (loader.size()) { remove_image_format_loader(loader[0]); } @@ -130,7 +118,6 @@ void ImageLoader::cleanup() { ///////////////// RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) { if (r_error) { @@ -192,16 +179,13 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_origin } void ResourceFormatLoaderImage::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("image"); } bool ResourceFormatLoaderImage::handles_type(const String &p_type) const { - return p_type == "Image"; } String ResourceFormatLoaderImage::get_resource_type(const String &p_path) const { - return p_path.get_extension().to_lower() == "image" ? "Image" : String(); } diff --git a/core/io/image_loader.h b/core/io/image_loader.h index 15ce6031d7..9682f144c7 100644 --- a/core/io/image_loader.h +++ b/core/io/image_loader.h @@ -53,7 +53,6 @@ public: }; class ImageLoader { - static Vector<ImageFormatLoader *> loader; friend class ResourceFormatLoaderImage; diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 5de7fb7186..642602d0bc 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -39,9 +39,7 @@ VARIANT_ENUM_CAST(IP::ResolverStatus); /************* RESOLVER ******************/ struct _IP_ResolverPrivate { - struct QueueItem { - volatile IP::ResolverStatus status; IP_Address response; String hostname; @@ -62,7 +60,6 @@ struct _IP_ResolverPrivate { QueueItem queue[IP::RESOLVER_MAX_QUERIES]; IP::ResolverID find_empty_id() const { - for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) { if (queue[i].status == IP::RESOLVER_STATUS_NONE) return i; @@ -78,9 +75,7 @@ struct _IP_ResolverPrivate { bool thread_abort; void resolve_queues() { - for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) { - if (queue[i].status != IP::RESOLVER_STATUS_WAITING) continue; queue[i].response = IP::get_singleton()->resolve_hostname(queue[i].hostname, queue[i].type); @@ -93,11 +88,9 @@ struct _IP_ResolverPrivate { } static void _thread_function(void *self) { - _IP_ResolverPrivate *ipr = (_IP_ResolverPrivate *)self; while (!ipr->thread_abort) { - ipr->sem.wait(); MutexLock lock(ipr->mutex); @@ -113,7 +106,6 @@ struct _IP_ResolverPrivate { }; IP_Address IP::resolve_hostname(const String &p_hostname, IP::Type p_type) { - MutexLock lock(resolver->mutex); String key = _IP_ResolverPrivate::get_cache_key(p_hostname, p_type); @@ -128,7 +120,6 @@ IP_Address IP::resolve_hostname(const String &p_hostname, IP::Type p_type) { } IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Type p_type) { - MutexLock lock(resolver->mutex); ResolverID id = resolver->find_empty_id(); @@ -157,7 +148,6 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Typ } IP::ResolverStatus IP::get_resolve_item_status(ResolverID p_id) const { - ERR_FAIL_INDEX_V(p_id, IP::RESOLVER_MAX_QUERIES, IP::RESOLVER_STATUS_NONE); MutexLock lock(resolver->mutex); @@ -171,7 +161,6 @@ IP::ResolverStatus IP::get_resolve_item_status(ResolverID p_id) const { } IP_Address IP::get_resolve_item_address(ResolverID p_id) const { - ERR_FAIL_INDEX_V(p_id, IP::RESOLVER_MAX_QUERIES, IP_Address()); MutexLock lock(resolver->mutex); @@ -186,7 +175,6 @@ IP_Address IP::get_resolve_item_address(ResolverID p_id) const { } void IP::erase_resolve_item(ResolverID p_id) { - ERR_FAIL_INDEX(p_id, IP::RESOLVER_MAX_QUERIES); MutexLock lock(resolver->mutex); @@ -195,7 +183,6 @@ void IP::erase_resolve_item(ResolverID p_id) { } void IP::clear_cache(const String &p_hostname) { - MutexLock lock(resolver->mutex); if (p_hostname.empty()) { @@ -209,7 +196,6 @@ void IP::clear_cache(const String &p_hostname) { } Array IP::_get_local_addresses() const { - Array addresses; List<IP_Address> ip_addresses; get_local_addresses(&ip_addresses); @@ -221,7 +207,6 @@ Array IP::_get_local_addresses() const { } Array IP::_get_local_interfaces() const { - Array results; Map<String, Interface_Info> interfaces; get_local_interfaces(&interfaces); @@ -245,7 +230,6 @@ Array IP::_get_local_interfaces() const { } void IP::get_local_addresses(List<IP_Address> *r_addresses) const { - Map<String, Interface_Info> interfaces; get_local_interfaces(&interfaces); for (Map<String, Interface_Info>::Element *E = interfaces.front(); E; E = E->next()) { @@ -256,7 +240,6 @@ void IP::get_local_addresses(List<IP_Address> *r_addresses) const { } void IP::_bind_methods() { - ClassDB::bind_method(D_METHOD("resolve_hostname", "host", "ip_type"), &IP::resolve_hostname, DEFVAL(IP::TYPE_ANY)); ClassDB::bind_method(D_METHOD("resolve_hostname_queue_item", "host", "ip_type"), &IP::resolve_hostname_queue_item, DEFVAL(IP::TYPE_ANY)); ClassDB::bind_method(D_METHOD("get_resolve_item_status", "id"), &IP::get_resolve_item_status); @@ -283,21 +266,18 @@ void IP::_bind_methods() { IP *IP::singleton = nullptr; IP *IP::get_singleton() { - return singleton; } IP *(*IP::_create)() = nullptr; IP *IP::create() { - ERR_FAIL_COND_V_MSG(singleton, nullptr, "IP singleton already exist."); ERR_FAIL_COND_V(!_create, nullptr); return _create(); } IP::IP() { - singleton = this; resolver = memnew(_IP_ResolverPrivate); @@ -312,7 +292,6 @@ IP::IP() { } IP::~IP() { - #ifndef NO_THREADS if (resolver->thread) { resolver->thread_abort = true; diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp index f5fd8ae205..817c2f060a 100644 --- a/core/io/ip_address.cpp +++ b/core/io/ip_address.cpp @@ -39,7 +39,6 @@ IP_Address::operator Variant() const { #include <string.h> IP_Address::operator String() const { - if (wildcard) return "*"; @@ -61,10 +60,8 @@ IP_Address::operator String() const { } static void _parse_hex(const String &p_string, int p_start, uint8_t *p_dst) { - uint16_t ret = 0; for (int i = p_start; i < p_start + 4; i++) { - if (i >= p_string.length()) { break; }; @@ -72,7 +69,6 @@ static void _parse_hex(const String &p_string, int p_start, uint8_t *p_dst) { int n = 0; CharType c = p_string[i]; if (c >= '0' && c <= '9') { - n = c - '0'; } else if (c >= 'a' && c <= 'f') { n = 10 + (c - 'a'); @@ -92,7 +88,6 @@ static void _parse_hex(const String &p_string, int p_start, uint8_t *p_dst) { }; void IP_Address::_parse_ipv6(const String &p_string) { - static const int parts_total = 8; int parts[parts_total] = { 0 }; int parts_count = 0; @@ -102,10 +97,8 @@ void IP_Address::_parse_ipv6(const String &p_string) { int parts_idx = 0; for (int i = 0; i < p_string.length(); i++) { - CharType c = p_string[i]; if (c == ':') { - if (i == 0) { continue; // next must be a ":" }; @@ -115,7 +108,6 @@ void IP_Address::_parse_ipv6(const String &p_string) { }; part_found = false; } else if (c == '.') { - part_ipv4 = true; } else if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) { @@ -136,9 +128,7 @@ void IP_Address::_parse_ipv6(const String &p_string) { int idx = 0; for (int i = 0; i < parts_idx; i++) { - if (parts[i] == -1) { - for (int j = 0; j < parts_extra; j++) { field16[idx++] = 0; }; @@ -154,7 +144,6 @@ void IP_Address::_parse_ipv6(const String &p_string) { }; void IP_Address::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret) { - String ip; if (p_start != 0) { ip = p_string.substr(p_start, p_string.length() - p_start); @@ -170,7 +159,6 @@ void IP_Address::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret }; void IP_Address::clear() { - memset(&field8[0], 0, sizeof(field8)); valid = false; wildcard = false; @@ -204,7 +192,6 @@ void IP_Address::set_ipv6(const uint8_t *p_buf) { } IP_Address::IP_Address(const String &p_string) { - clear(); if (p_string == "*") { @@ -228,7 +215,6 @@ IP_Address::IP_Address(const String &p_string) { } _FORCE_INLINE_ static void _32_to_buf(uint8_t *p_dst, uint32_t p_n) { - p_dst[0] = (p_n >> 24) & 0xff; p_dst[1] = (p_n >> 16) & 0xff; p_dst[2] = (p_n >> 8) & 0xff; @@ -236,7 +222,6 @@ _FORCE_INLINE_ static void _32_to_buf(uint8_t *p_dst, uint32_t p_n) { }; IP_Address::IP_Address(uint32_t p_a, uint32_t p_b, uint32_t p_c, uint32_t p_d, bool is_v6) { - clear(); valid = true; if (!is_v6) { @@ -247,7 +232,6 @@ IP_Address::IP_Address(uint32_t p_a, uint32_t p_b, uint32_t p_c, uint32_t p_d, b field8[14] = p_c; field8[15] = p_d; } else { - _32_to_buf(&field8[0], p_a); _32_to_buf(&field8[4], p_b); _32_to_buf(&field8[8], p_c); diff --git a/core/io/ip_address.h b/core/io/ip_address.h index a59178063d..39948ce211 100644 --- a/core/io/ip_address.h +++ b/core/io/ip_address.h @@ -34,7 +34,6 @@ #include "core/ustring.h" struct IP_Address { - private: union { uint8_t field8[16]; diff --git a/core/io/json.cpp b/core/io/json.cpp index 0186547dd2..baa62a4b0a 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -46,7 +46,6 @@ const char *JSON::tk_name[TK_MAX] = { }; static String _make_indent(const String &p_indent, int p_size) { - String indent_text = ""; if (!p_indent.empty()) { for (int i = 0; i < p_size; i++) @@ -56,7 +55,6 @@ static String _make_indent(const String &p_indent, int p_size) { } String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys) { - String colon = ":"; String end_statement = ""; @@ -66,7 +64,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_ } switch (p_var.get_type()) { - case Variant::NIL: return "null"; case Variant::BOOL: @@ -81,7 +78,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_ case Variant::PACKED_FLOAT64_ARRAY: case Variant::PACKED_STRING_ARRAY: case Variant::ARRAY: { - String s = "["; s += end_statement; Array a = p_var; @@ -96,7 +92,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_ return s; }; case Variant::DICTIONARY: { - String s = "{"; s += end_statement; Dictionary d = p_var; @@ -107,7 +102,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_ keys.sort(); for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { - if (E != keys.front()) { s += ","; s += end_statement; @@ -126,17 +120,13 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_ } String JSON::print(const Variant &p_var, const String &p_indent, bool p_sort_keys) { - return _print_var(p_var, p_indent, 0, p_sort_keys); } Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str) { - while (p_len > 0) { switch (p_str[index]) { - case '\n': { - line++; index++; break; @@ -146,43 +136,36 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to return OK; } break; case '{': { - r_token.type = TK_CURLY_BRACKET_OPEN; index++; return OK; }; case '}': { - r_token.type = TK_CURLY_BRACKET_CLOSE; index++; return OK; }; case '[': { - r_token.type = TK_BRACKET_OPEN; index++; return OK; }; case ']': { - r_token.type = TK_BRACKET_CLOSE; index++; return OK; }; case ':': { - r_token.type = TK_COLON; index++; return OK; }; case ',': { - r_token.type = TK_COMMA; index++; return OK; }; case '"': { - index++; String str; while (true) { @@ -203,7 +186,6 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to CharType res = 0; switch (next) { - case 'b': res = 8; break; @@ -228,7 +210,6 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to return ERR_PARSE_ERROR; } if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) { - r_err_str = "Malformed hex constant in string"; return ERR_PARSE_ERROR; } @@ -273,7 +254,6 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to } break; default: { - if (p_str[index] <= 32) { index++; break; @@ -289,11 +269,9 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to return OK; } else if ((p_str[index] >= 'A' && p_str[index] <= 'Z') || (p_str[index] >= 'a' && p_str[index] <= 'z')) { - String id; while ((p_str[index] >= 'A' && p_str[index] <= 'Z') || (p_str[index] >= 'a' && p_str[index] <= 'z')) { - id += p_str[index]; index++; } @@ -313,9 +291,7 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to } Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) { - if (token.type == TK_CURLY_BRACKET_OPEN) { - Dictionary d; Error err = _parse_object(d, p_str, index, p_len, line, r_err_str); if (err) @@ -323,7 +299,6 @@ Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, in value = d; return OK; } else if (token.type == TK_BRACKET_OPEN) { - Array a; Error err = _parse_array(a, p_str, index, p_len, line, r_err_str); if (err) @@ -332,7 +307,6 @@ Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, in return OK; } else if (token.type == TK_IDENTIFIER) { - String id = token.value; if (id == "true") value = true; @@ -347,11 +321,9 @@ Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, in return OK; } else if (token.type == TK_NUMBER) { - value = token.value; return OK; } else if (token.type == TK_STRING) { - value = token.value; return OK; } else { @@ -361,25 +333,20 @@ Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, in } Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) { - Token token; bool need_comma = false; while (index < p_len) { - Error err = _get_token(p_str, index, p_len, token, line, r_err_str); if (err != OK) return err; if (token.type == TK_BRACKET_CLOSE) { - return OK; } if (need_comma) { - if (token.type != TK_COMMA) { - r_err_str = "Expected ','"; return ERR_PARSE_ERROR; } else { @@ -401,29 +368,23 @@ Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_ } Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) { - bool at_key = true; String key; Token token; bool need_comma = false; while (index < p_len) { - if (at_key) { - Error err = _get_token(p_str, index, p_len, token, line, r_err_str); if (err != OK) return err; if (token.type == TK_CURLY_BRACKET_CLOSE) { - return OK; } if (need_comma) { - if (token.type != TK_COMMA) { - r_err_str = "Expected '}' or ','"; return ERR_PARSE_ERROR; } else { @@ -433,7 +394,6 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index, } if (token.type != TK_STRING) { - r_err_str = "Expected key"; return ERR_PARSE_ERROR; } @@ -443,13 +403,11 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index, if (err != OK) return err; if (token.type != TK_COLON) { - r_err_str = "Expected ':'"; return ERR_PARSE_ERROR; } at_key = false; } else { - Error err = _get_token(p_str, index, p_len, token, line, r_err_str); if (err != OK) return err; @@ -468,7 +426,6 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index, } Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line) { - const CharType *str = p_json.ptr(); int idx = 0; int len = p_json.length(); diff --git a/core/io/json.h b/core/io/json.h index 2e851afcf4..4fc5630a93 100644 --- a/core/io/json.h +++ b/core/io/json.h @@ -34,7 +34,6 @@ #include "core/variant.h" class JSON { - enum TokenType { TK_CURLY_BRACKET_OPEN, TK_CURLY_BRACKET_CLOSE, @@ -58,7 +57,6 @@ class JSON { }; struct Token { - TokenType type; Variant value; }; diff --git a/core/io/logger.h b/core/io/logger.h index 54f1a42da9..277be9ed35 100644 --- a/core/io/logger.h +++ b/core/io/logger.h @@ -62,7 +62,6 @@ public: * Writes messages to stdout/stderr. */ class StdLogger : public Logger { - public: virtual void logv(const char *p_format, va_list p_list, bool p_err) _PRINTF_FORMAT_ATTRIBUTE_2_0; virtual ~StdLogger() {} diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index abf27954b8..fc0b037b07 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -49,7 +49,6 @@ void EncodedObjectAsID::set_object_id(ObjectID p_id) { } ObjectID EncodedObjectAsID::get_object_id() const { - return id; } @@ -97,7 +96,6 @@ static Error _decode_string(const uint8_t *&buf, int &len, int *r_len, String &r } Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len, bool p_allow_objects) { - const uint8_t *buf = p_buffer; int len = p_len; @@ -113,13 +111,10 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = 4; switch (type & ENCODE_MASK) { - case Variant::NIL: { - r_variant = Variant(); } break; case Variant::BOOL: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); bool val = decode_uint32(buf); r_variant = val; @@ -127,7 +122,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int (*r_len) += 4; } break; case Variant::INT: { - if (type & ENCODE_FLAG_64) { ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); int64_t val = decode_uint64(buf); @@ -145,7 +139,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::FLOAT: { - if (type & ENCODE_FLAG_64) { ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); double val = decode_double(buf); @@ -162,7 +155,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::STRING: { - String str; Error err = _decode_string(buf, len, r_len, str); if (err) @@ -173,7 +165,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int // math types case Variant::VECTOR2: { - ERR_FAIL_COND_V(len < 4 * 2, ERR_INVALID_DATA); Vector2 val; val.x = decode_float(&buf[0]); @@ -185,7 +176,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::VECTOR2I: { - ERR_FAIL_COND_V(len < 4 * 2, ERR_INVALID_DATA); Vector2i val; val.x = decode_uint32(&buf[0]); @@ -197,7 +187,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::RECT2: { - ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); Rect2 val; val.position.x = decode_float(&buf[0]); @@ -211,7 +200,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::RECT2I: { - ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); Rect2i val; val.position.x = decode_uint32(&buf[0]); @@ -225,7 +213,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::VECTOR3: { - ERR_FAIL_COND_V(len < 4 * 3, ERR_INVALID_DATA); Vector3 val; val.x = decode_float(&buf[0]); @@ -238,7 +225,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::VECTOR3I: { - ERR_FAIL_COND_V(len < 4 * 3, ERR_INVALID_DATA); Vector3i val; val.x = decode_uint32(&buf[0]); @@ -251,12 +237,10 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::TRANSFORM2D: { - ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA); Transform2D val; for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - val.elements[i][j] = decode_float(&buf[(i * 2 + j) * 4]); } } @@ -268,7 +252,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::PLANE: { - ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); Plane val; val.normal.x = decode_float(&buf[0]); @@ -282,7 +265,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::QUAT: { - ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); Quat val; val.x = decode_float(&buf[0]); @@ -296,7 +278,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::AABB: { - ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA); AABB val; val.position.x = decode_float(&buf[0]); @@ -312,12 +293,10 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::BASIS: { - ERR_FAIL_COND_V(len < 4 * 9, ERR_INVALID_DATA); Basis val; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - val.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]); } } @@ -329,12 +308,10 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::TRANSFORM: { - ERR_FAIL_COND_V(len < 4 * 12, ERR_INVALID_DATA); Transform val; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - val.basis.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]); } } @@ -351,7 +328,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int // misc types case Variant::COLOR: { - ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); Color val; val.r = decode_float(&buf[0]); @@ -365,7 +341,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::STRING_NAME: { - String str; Error err = _decode_string(buf, len, r_len, str); if (err) @@ -375,7 +350,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::NODE_PATH: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t strlen = decode_uint32(buf); @@ -401,7 +375,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int (*r_len) += 12; for (uint32_t i = 0; i < total; i++) { - String str; Error err = _decode_string(buf, len, r_len, str); if (err) @@ -423,11 +396,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::_RID: { - r_variant = RID(); } break; case Variant::OBJECT: { - if (type & ENCODE_FLAG_OBJECT_AS_ID) { //this _is_ allowed ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); @@ -456,7 +427,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int if (str == String()) { r_variant = (Object *)nullptr; } else { - Object *obj = ClassDB::instance(str); ERR_FAIL_COND_V(!obj, ERR_UNAVAILABLE); @@ -470,7 +440,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } for (int i = 0; i < count; i++) { - str = String(); err = _decode_string(buf, len, r_len, str); if (err) @@ -502,16 +471,13 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::CALLABLE: { - r_variant = Callable(); } break; case Variant::SIGNAL: { - r_variant = Signal(); } break; case Variant::DICTIONARY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); // bool shared = count&0x80000000; @@ -527,7 +493,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Dictionary d; for (int i = 0; i < count; i++) { - Variant key, value; int used; @@ -556,7 +521,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); // bool shared = count&0x80000000; @@ -572,7 +536,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Array varr; for (int i = 0; i < count; i++) { - int used = 0; Variant v; Error err = decode_variant(v, buf, len, &used, p_allow_objects); @@ -591,7 +554,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int // arrays case Variant::PACKED_BYTE_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); buf += 4; @@ -604,7 +566,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int data.resize(count); uint8_t *w = data.ptrw(); for (int32_t i = 0; i < count; i++) { - w[i] = buf[i]; } } @@ -619,7 +580,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::PACKED_INT32_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); buf += 4; @@ -634,7 +594,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int data.resize(count); int32_t *w = data.ptrw(); for (int32_t i = 0; i < count; i++) { - w[i] = decode_uint32(&buf[i * 4]); } } @@ -645,7 +604,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::PACKED_INT64_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int64_t count = decode_uint64(buf); buf += 4; @@ -660,7 +618,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int data.resize(count); int64_t *w = data.ptrw(); for (int64_t i = 0; i < count; i++) { - w[i] = decode_uint64(&buf[i * 8]); } } @@ -671,7 +628,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::PACKED_FLOAT32_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); buf += 4; @@ -686,7 +642,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int data.resize(count); float *w = data.ptrw(); for (int32_t i = 0; i < count; i++) { - w[i] = decode_float(&buf[i * 4]); } } @@ -698,7 +653,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::PACKED_FLOAT64_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int64_t count = decode_uint64(buf); buf += 4; @@ -713,7 +667,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int data.resize(count); double *w = data.ptrw(); for (int64_t i = 0; i < count; i++) { - w[i] = decode_double(&buf[i * 8]); } } @@ -725,7 +678,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::PACKED_STRING_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); @@ -738,7 +690,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int //printf("string count: %i\n",count); for (int32_t i = 0; i < count; i++) { - String str; Error err = _decode_string(buf, len, r_len, str); if (err) @@ -751,7 +702,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::PACKED_VECTOR2_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); buf += 4; @@ -770,7 +720,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Vector2 *w = varray.ptrw(); for (int32_t i = 0; i < count; i++) { - w[i].x = decode_float(buf + i * 4 * 2 + 4 * 0); w[i].y = decode_float(buf + i * 4 * 2 + 4 * 1); } @@ -785,7 +734,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::PACKED_VECTOR3_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); buf += 4; @@ -805,7 +753,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Vector3 *w = varray.ptrw(); for (int32_t i = 0; i < count; i++) { - w[i].x = decode_float(buf + i * 4 * 3 + 4 * 0); w[i].y = decode_float(buf + i * 4 * 3 + 4 * 1); w[i].z = decode_float(buf + i * 4 * 3 + 4 * 2); @@ -821,7 +768,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::PACKED_COLOR_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); buf += 4; @@ -841,7 +787,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Color *w = carray.ptrw(); for (int32_t i = 0; i < count; i++) { - w[i].r = decode_float(buf + i * 4 * 4 + 4 * 0); w[i].g = decode_float(buf + i * 4 * 4 + 4 * 1); w[i].b = decode_float(buf + i * 4 * 4 + 4 * 2); @@ -866,7 +811,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) { - CharString utf8 = p_string.utf8(); if (buf) { @@ -886,7 +830,6 @@ static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) { } Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects) { - uint8_t *buf = r_buffer; r_len = 0; @@ -894,7 +837,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo uint32_t flags = 0; switch (p_variant.get_type()) { - case Variant::INT: { int64_t val = p_variant; if (val > (int64_t)INT_MAX || val < (int64_t)INT_MIN) { @@ -902,7 +844,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } } break; case Variant::FLOAT: { - double d = p_variant; float f = d; if (double(f) != d) { @@ -910,7 +851,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } } break; case Variant::OBJECT: { - // Test for potential wrong values sent by the debugger when it breaks. Object *obj = p_variant.get_validated_object(); if (!obj) { @@ -937,13 +877,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; switch (p_variant.get_type()) { - case Variant::NIL: { - //nothing to do } break; case Variant::BOOL: { - if (buf) { encode_uint32(p_variant.operator bool(), buf); } @@ -952,7 +889,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::INT: { - if (flags & ENCODE_FLAG_64) { //64 bits if (buf) { @@ -969,7 +905,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } } break; case Variant::FLOAT: { - if (flags & ENCODE_FLAG_64) { if (buf) { encode_double(p_variant.operator double(), buf); @@ -978,7 +913,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 8; } else { - if (buf) { encode_float(p_variant.operator float(), buf); } @@ -988,7 +922,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::NODE_PATH: { - NodePath np = p_variant; if (buf) { encode_uint32(uint32_t(np.get_name_count()) | 0x80000000, buf); //for compatibility with the old format @@ -1007,7 +940,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo int total = np.get_name_count() + np.get_subname_count(); for (int i = 0; i < total; i++) { - String str; if (i < np.get_name_count()) @@ -1034,19 +966,16 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::STRING: { - _encode_string(p_variant, buf, r_len); } break; case Variant::STRING_NAME: { - _encode_string(p_variant, buf, r_len); } break; // math types case Variant::VECTOR2: { - if (buf) { Vector2 v2 = p_variant; encode_float(v2.x, &buf[0]); @@ -1057,7 +986,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::VECTOR2I: { - if (buf) { Vector2i v2 = p_variant; encode_uint32(v2.x, &buf[0]); @@ -1068,7 +996,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::RECT2: { - if (buf) { Rect2 r2 = p_variant; encode_float(r2.position.x, &buf[0]); @@ -1080,7 +1007,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::RECT2I: { - if (buf) { Rect2i r2 = p_variant; encode_uint32(r2.position.x, &buf[0]); @@ -1092,7 +1018,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::VECTOR3: { - if (buf) { Vector3 v3 = p_variant; encode_float(v3.x, &buf[0]); @@ -1104,7 +1029,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::VECTOR3I: { - if (buf) { Vector3i v3 = p_variant; encode_uint32(v3.x, &buf[0]); @@ -1116,12 +1040,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::TRANSFORM2D: { - if (buf) { Transform2D val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - copymem(&buf[(i * 2 + j) * 4], &val.elements[i][j], sizeof(float)); } } @@ -1131,7 +1053,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::PLANE: { - if (buf) { Plane p = p_variant; encode_float(p.normal.x, &buf[0]); @@ -1144,7 +1065,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::QUAT: { - if (buf) { Quat q = p_variant; encode_float(q.x, &buf[0]); @@ -1157,7 +1077,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::AABB: { - if (buf) { AABB aabb = p_variant; encode_float(aabb.position.x, &buf[0]); @@ -1172,12 +1091,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::BASIS: { - if (buf) { Basis val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - copymem(&buf[(i * 3 + j) * 4], &val.elements[i][j], sizeof(float)); } } @@ -1187,12 +1104,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::TRANSFORM: { - if (buf) { Transform val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - copymem(&buf[(i * 3 + j) * 4], &val.basis.elements[i][j], sizeof(float)); } } @@ -1208,7 +1123,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo // misc types case Variant::COLOR: { - if (buf) { Color c = p_variant; encode_float(c.r, &buf[0]); @@ -1221,18 +1135,13 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::_RID: { - } break; case Variant::CALLABLE: { - } break; case Variant::SIGNAL: { - } break; case Variant::OBJECT: { - if (p_full_objects) { - Object *obj = p_variant; if (!obj) { if (buf) { @@ -1248,7 +1157,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo int pc = 0; for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) continue; pc++; @@ -1262,7 +1170,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) continue; @@ -1280,7 +1187,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } } else { if (buf) { - Object *obj = p_variant.get_validated_object(); ObjectID id; if (obj) { @@ -1295,7 +1201,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::DICTIONARY: { - Dictionary d = p_variant; if (buf) { @@ -1308,7 +1213,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo d.get_key_list(&keys); for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { - /* CharString utf8 = E->->utf8(); @@ -1339,7 +1243,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::ARRAY: { - Array v = p_variant; if (buf) { @@ -1350,7 +1253,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; for (int i = 0; i < v.size(); i++) { - int len; encode_variant(v.get(i), buf, len, p_full_objects); ERR_FAIL_COND_V(len % 4, ERR_BUG); @@ -1362,7 +1264,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; // arrays case Variant::PACKED_BYTE_ARRAY: { - Vector<uint8_t> data = p_variant; int datalen = data.size(); int datasize = sizeof(uint8_t); @@ -1384,7 +1285,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::PACKED_INT32_ARRAY: { - Vector<int32_t> data = p_variant; int datalen = data.size(); int datasize = sizeof(int32_t); @@ -1401,7 +1301,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::PACKED_INT64_ARRAY: { - Vector<int64_t> data = p_variant; int datalen = data.size(); int datasize = sizeof(int64_t); @@ -1418,7 +1317,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::PACKED_FLOAT32_ARRAY: { - Vector<float> data = p_variant; int datalen = data.size(); int datasize = sizeof(float); @@ -1435,7 +1333,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::PACKED_FLOAT64_ARRAY: { - Vector<double> data = p_variant; int datalen = data.size(); int datasize = sizeof(double); @@ -1452,7 +1349,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::PACKED_STRING_ARRAY: { - Vector<String> data = p_variant; int len = data.size(); @@ -1464,7 +1360,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; for (int i = 0; i < len; i++) { - CharString utf8 = data.get(i).utf8(); if (buf) { @@ -1484,7 +1379,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::PACKED_VECTOR2_ARRAY: { - Vector<Vector2> data = p_variant; int len = data.size(); @@ -1496,9 +1390,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; if (buf) { - for (int i = 0; i < len; i++) { - Vector2 v = data.get(i); encode_float(v.x, &buf[0]); @@ -1511,7 +1403,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::PACKED_VECTOR3_ARRAY: { - Vector<Vector3> data = p_variant; int len = data.size(); @@ -1523,9 +1414,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; if (buf) { - for (int i = 0; i < len; i++) { - Vector3 v = data.get(i); encode_float(v.x, &buf[0]); @@ -1539,7 +1428,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::PACKED_COLOR_ARRAY: { - Vector<Color> data = p_variant; int len = data.size(); @@ -1551,9 +1439,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; if (buf) { - for (int i = 0; i < len; i++) { - Color c = data.get(i); encode_float(c.r, &buf[0]); diff --git a/core/io/marshalls.h b/core/io/marshalls.h index 1ba786d5d9..279f782b1a 100644 --- a/core/io/marshalls.h +++ b/core/io/marshalls.h @@ -41,21 +41,17 @@ */ union MarshallFloat { - uint32_t i; ///< int float f; ///< float }; union MarshallDouble { - uint64_t l; ///< long long double d; ///< double }; static inline unsigned int encode_uint16(uint16_t p_uint, uint8_t *p_arr) { - for (int i = 0; i < 2; i++) { - *p_arr = p_uint & 0xFF; p_arr++; p_uint >>= 8; @@ -65,9 +61,7 @@ static inline unsigned int encode_uint16(uint16_t p_uint, uint8_t *p_arr) { } static inline unsigned int encode_uint32(uint32_t p_uint, uint8_t *p_arr) { - for (int i = 0; i < 4; i++) { - *p_arr = p_uint & 0xFF; p_arr++; p_uint >>= 8; @@ -77,7 +71,6 @@ static inline unsigned int encode_uint32(uint32_t p_uint, uint8_t *p_arr) { } static inline unsigned int encode_float(float p_float, uint8_t *p_arr) { - MarshallFloat mf; mf.f = p_float; encode_uint32(mf.i, p_arr); @@ -86,9 +79,7 @@ static inline unsigned int encode_float(float p_float, uint8_t *p_arr) { } static inline unsigned int encode_uint64(uint64_t p_uint, uint8_t *p_arr) { - for (int i = 0; i < 8; i++) { - *p_arr = p_uint & 0xFF; p_arr++; p_uint >>= 8; @@ -98,7 +89,6 @@ static inline unsigned int encode_uint64(uint64_t p_uint, uint8_t *p_arr) { } static inline unsigned int encode_double(double p_double, uint8_t *p_arr) { - MarshallDouble md; md.d = p_double; encode_uint64(md.l, p_arr); @@ -107,13 +97,10 @@ static inline unsigned int encode_double(double p_double, uint8_t *p_arr) { } static inline int encode_cstring(const char *p_string, uint8_t *p_data) { - int len = 0; while (*p_string) { - if (p_data) { - *p_data = (uint8_t)*p_string; p_data++; } @@ -127,11 +114,9 @@ static inline int encode_cstring(const char *p_string, uint8_t *p_data) { } static inline uint16_t decode_uint16(const uint8_t *p_arr) { - uint16_t u = 0; for (int i = 0; i < 2; i++) { - uint16_t b = *p_arr; b <<= (i * 8); u |= b; @@ -142,11 +127,9 @@ static inline uint16_t decode_uint16(const uint8_t *p_arr) { } static inline uint32_t decode_uint32(const uint8_t *p_arr) { - uint32_t u = 0; for (int i = 0; i < 4; i++) { - uint32_t b = *p_arr; b <<= (i * 8); u |= b; @@ -157,18 +140,15 @@ static inline uint32_t decode_uint32(const uint8_t *p_arr) { } static inline float decode_float(const uint8_t *p_arr) { - MarshallFloat mf; mf.i = decode_uint32(p_arr); return mf.f; } static inline uint64_t decode_uint64(const uint8_t *p_arr) { - uint64_t u = 0; for (int i = 0; i < 8; i++) { - uint64_t b = (*p_arr) & 0xFF; b <<= (i * 8); u |= b; @@ -179,7 +159,6 @@ static inline uint64_t decode_uint64(const uint8_t *p_arr) { } static inline double decode_double(const uint8_t *p_arr) { - MarshallDouble md; md.l = decode_uint64(p_arr); return md.d; diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index 998bcfd3f3..b819725155 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -45,9 +45,7 @@ #endif _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_master, bool &r_skip_rpc) { - switch (mode) { - case MultiplayerAPI::RPC_MODE_DISABLED: { // Do nothing. } break; @@ -78,7 +76,6 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas _FORCE_INLINE_ bool _can_call_mode(Node *p_node, MultiplayerAPI::RPCMode mode, int p_remote_id) { switch (mode) { - case MultiplayerAPI::RPC_MODE_DISABLED: { return false; } break; @@ -100,7 +97,6 @@ _FORCE_INLINE_ bool _can_call_mode(Node *p_node, MultiplayerAPI::RPCMode mode, i } void MultiplayerAPI::poll() { - if (!network_peer.is_valid() || network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED) return; @@ -110,7 +106,6 @@ void MultiplayerAPI::poll() { return; while (network_peer->get_available_packet_count()) { - int sender = network_peer->get_packet_peer(); const uint8_t *packet; int len; @@ -144,7 +139,6 @@ void MultiplayerAPI::set_root_node(Node *p_node) { } void MultiplayerAPI::set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_peer) { - if (p_peer == network_peer) return; // Nothing to do @@ -208,7 +202,6 @@ int get_packet_len(uint32_t p_node_target, int p_packet_len) { } void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_packet_len) { - ERR_FAIL_COND_MSG(root_node == nullptr, "Multiplayer root node was not initialized. If you are using custom multiplayer, remember to set the root node via MultiplayerAPI.set_root_node before using it."); ERR_FAIL_COND_MSG(p_packet_len < 1, "Invalid packet received. Size too small."); @@ -220,20 +213,16 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_ uint8_t packet_type = p_packet[0] & 7; switch (packet_type) { - case NETWORK_COMMAND_SIMPLIFY_PATH: { - _process_simplify_path(p_from, p_packet, p_packet_len); } break; case NETWORK_COMMAND_CONFIRM_PATH: { - _process_confirm_path(p_from, p_packet, p_packet_len); } break; case NETWORK_COMMAND_REMOTE_CALL: case NETWORK_COMMAND_REMOTE_SET: { - // Extract packet meta int packet_min_size = 1; int name_id_offset = 1; @@ -304,25 +293,21 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_ const int packet_len = get_packet_len(node_target, p_packet_len); if (packet_type == NETWORK_COMMAND_REMOTE_CALL) { - _process_rpc(node, name_id, p_from, p_packet, packet_len, packet_min_size); } else { - _process_rset(node, name_id, p_from, p_packet, packet_len, packet_min_size); } } break; case NETWORK_COMMAND_RAW: { - _process_raw(p_from, p_packet, p_packet_len); } break; } } Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, uint32_t p_node_target, int p_packet_len) { - Node *node = nullptr; if (p_node_target & 0x80000000) { @@ -362,7 +347,6 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, uin } void MultiplayerAPI::_process_rpc(Node *p_node, const uint16_t p_rpc_method_id, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) { - ERR_FAIL_COND_MSG(p_offset > p_packet_len, "Invalid packet received. Size too small."); // Check that remote can call the RPC on this node. @@ -415,7 +399,6 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const uint16_t p_rpc_method_id, p_offset += len; } else { for (int i = 0; i < argc; i++) { - ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small."); int vlen; @@ -438,7 +421,6 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const uint16_t p_rpc_method_id, } void MultiplayerAPI::_process_rset(Node *p_node, const uint16_t p_rpc_property_id, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) { - ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small."); // Check that remote can call the RSET on this node. @@ -472,7 +454,6 @@ void MultiplayerAPI::_process_rset(Node *p_node, const uint16_t p_rpc_property_i } void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet, int p_packet_len) { - ERR_FAIL_COND_MSG(p_packet_len < 38, "Invalid packet received. Size too small."); int ofs = 1; @@ -521,7 +502,6 @@ void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet, } void MultiplayerAPI::_process_confirm_path(int p_from, const uint8_t *p_packet, int p_packet_len) { - ERR_FAIL_COND_MSG(p_packet_len < 3, "Invalid packet received. Size too small."); const bool valid_rpc_checksum = p_packet[1]; @@ -548,7 +528,6 @@ bool MultiplayerAPI::_send_confirm_path(Node *p_node, NodePath p_path, PathSentC List<int> peers_to_add; // If one is missing, take note to add it. for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) { - if (p_target < 0 && E->get() == -p_target) continue; // Continue, excluded. @@ -569,7 +548,6 @@ bool MultiplayerAPI::_send_confirm_path(Node *p_node, NodePath p_path, PathSentC } if (peers_to_add.size() > 0) { - // Those that need to be added, send a message for this. // Encode function name. @@ -594,7 +572,6 @@ bool MultiplayerAPI::_send_confirm_path(Node *p_node, NodePath p_path, PathSentC ofs += encode_cstring(path.get_data(), &packet.write[ofs]); for (List<int>::Element *E = peers_to_add.front(); E; E = E->next()) { - network_peer->set_target_peer(E->get()); // To all of you. network_peer->set_transfer_mode(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE); network_peer->put_packet(packet.ptr(), packet.size()); @@ -619,7 +596,6 @@ bool MultiplayerAPI::_send_confirm_path(Node *p_node, NodePath p_path, PathSentC #define ENCODE_32 2 << 5 #define ENCODE_64 3 << 5 Error MultiplayerAPI::_encode_and_compress_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) { - // Unreachable because `VARIANT_MAX` == 27 and `ENCODE_VARIANT_MASK` == 31 CRASH_COND(p_variant.get_type() > VARIANT_META_TYPE_MASK); @@ -693,7 +669,6 @@ Error MultiplayerAPI::_encode_and_compress_variant(const Variant &p_variant, uin return OK; } Error MultiplayerAPI::_decode_and_decompress_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len) { - const uint8_t *buf = p_buffer; int len = p_len; @@ -755,7 +730,6 @@ Error MultiplayerAPI::_decode_and_decompress_variant(Variant &r_variant, const u } void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p_set, const StringName &p_name, const Variant **p_arg, int p_argcount) { - ERR_FAIL_COND_MSG(network_peer.is_null(), "Attempt to remote call/set when networking is not active in SceneTree."); ERR_FAIL_COND_MSG(network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_CONNECTING, "Attempt to remote call/set when networking is not connected yet in SceneTree."); @@ -841,7 +815,6 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p } if (p_set) { - // Take the rpc property ID uint16_t property_id = p_from->get_node_rset_property_id(p_name); if (property_id == UINT16_MAX && p_from->get_script_instance()) { @@ -934,7 +907,6 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p network_peer->set_transfer_mode(p_unreliable ? NetworkedMultiplayerPeer::TRANSFER_MODE_UNRELIABLE : NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE); if (has_all_peers) { - // They all have verified paths, so send fast. network_peer->set_target_peer(p_to); // To all of you. network_peer->put_packet(packet_cache.ptr(), ofs); // A message with love. @@ -951,7 +923,6 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p encode_cstring(pname.get_data(), &(packet_cache.write[ofs])); for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) { - if (p_to < 0 && E->get() == -p_to) continue; // Continue, excluded. @@ -998,22 +969,18 @@ void MultiplayerAPI::_del_peer(int p_id) { } void MultiplayerAPI::_connected_to_server() { - emit_signal("connected_to_server"); } void MultiplayerAPI::_connection_failed() { - emit_signal("connection_failed"); } void MultiplayerAPI::_server_disconnected() { - emit_signal("server_disconnected"); } void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_method, const Variant **p_arg, int p_argcount) { - ERR_FAIL_COND_MSG(!network_peer.is_valid(), "Trying to call an RPC while no network peer is active."); ERR_FAIL_COND_MSG(!p_node->is_inside_tree(), "Trying to call an RPC on a node which is not inside SceneTree."); ERR_FAIL_COND_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, "Trying to call an RPC via a network peer which is not connected."); @@ -1040,7 +1007,6 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const } if (!skip_rpc) { - #ifdef DEBUG_ENABLED _profile_node_data("out_rpc", p_node->get_instance_id()); #endif @@ -1081,7 +1047,6 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const } void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_property, const Variant &p_value) { - ERR_FAIL_COND_MSG(!network_peer.is_valid(), "Trying to RSET while no network peer is active."); ERR_FAIL_COND_MSG(!p_node->is_inside_tree(), "Trying to RSET on a node which is not inside SceneTree."); ERR_FAIL_COND_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, "Trying to send an RSET via a network peer which is not connected."); @@ -1146,7 +1111,6 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const } Error MultiplayerAPI::send_bytes(Vector<uint8_t> p_data, int p_to, NetworkedMultiplayerPeer::TransferMode p_mode) { - ERR_FAIL_COND_V_MSG(p_data.size() < 1, ERR_INVALID_DATA, "Trying to send an empty raw packet."); ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), ERR_UNCONFIGURED, "Trying to send a raw packet while no network peer is active."); ERR_FAIL_COND_V_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, ERR_UNCONFIGURED, "Trying to send a raw packet via a network peer which is not connected."); @@ -1163,7 +1127,6 @@ Error MultiplayerAPI::send_bytes(Vector<uint8_t> p_data, int p_to, NetworkedMult } void MultiplayerAPI::_process_raw(int p_from, const uint8_t *p_packet, int p_packet_len) { - ERR_FAIL_COND_MSG(p_packet_len < 2, "Invalid packet received. Size too small."); Vector<uint8_t> out; @@ -1177,32 +1140,27 @@ void MultiplayerAPI::_process_raw(int p_from, const uint8_t *p_packet, int p_pac } int MultiplayerAPI::get_network_unique_id() const { - ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), 0, "No network peer is assigned. Unable to get unique network ID."); return network_peer->get_unique_id(); } bool MultiplayerAPI::is_network_server() const { - // XXX Maybe fail silently? Maybe should actually return true to make development of both local and online multiplayer easier? ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), false, "No network peer is assigned. I can't be a server."); return network_peer->is_server(); } void MultiplayerAPI::set_refuse_new_network_connections(bool p_refuse) { - ERR_FAIL_COND_MSG(!network_peer.is_valid(), "No network peer is assigned. Unable to set 'refuse_new_connections'."); network_peer->set_refuse_new_connections(p_refuse); } bool MultiplayerAPI::is_refusing_new_network_connections() const { - ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), false, "No network peer is assigned. Unable to get 'refuse_new_connections'."); return network_peer->is_refusing_new_connections(); } Vector<int> MultiplayerAPI::get_network_connected_peers() const { - ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), Vector<int>(), "No network peer is assigned. Assume no peers are connected."); Vector<int> ret; @@ -1214,12 +1172,10 @@ Vector<int> MultiplayerAPI::get_network_connected_peers() const { } void MultiplayerAPI::set_allow_object_decoding(bool p_enable) { - allow_object_decoding = p_enable; } bool MultiplayerAPI::is_object_decoding_allowed() const { - return allow_object_decoding; } diff --git a/core/io/multiplayer_api.h b/core/io/multiplayer_api.h index 2603fb1e27..06eab7796c 100644 --- a/core/io/multiplayer_api.h +++ b/core/io/multiplayer_api.h @@ -35,7 +35,6 @@ #include "core/reference.h" class MultiplayerAPI : public Reference { - GDCLASS(MultiplayerAPI, Reference); private: diff --git a/core/io/net_socket.cpp b/core/io/net_socket.cpp index 838c674cec..e92bc705ce 100644 --- a/core/io/net_socket.cpp +++ b/core/io/net_socket.cpp @@ -33,7 +33,6 @@ NetSocket *(*NetSocket::_create)() = nullptr; NetSocket *NetSocket::create() { - if (_create) return _create(); diff --git a/core/io/net_socket.h b/core/io/net_socket.h index 376fd87a27..746945eced 100644 --- a/core/io/net_socket.h +++ b/core/io/net_socket.h @@ -35,7 +35,6 @@ #include "core/reference.h" class NetSocket : public Reference { - protected: static NetSocket *(*_create)(); diff --git a/core/io/networked_multiplayer_peer.cpp b/core/io/networked_multiplayer_peer.cpp index 332beb4c8c..f521f2bb79 100644 --- a/core/io/networked_multiplayer_peer.cpp +++ b/core/io/networked_multiplayer_peer.cpp @@ -31,7 +31,6 @@ #include "networked_multiplayer_peer.h" void NetworkedMultiplayerPeer::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_transfer_mode", "mode"), &NetworkedMultiplayerPeer::set_transfer_mode); ClassDB::bind_method(D_METHOD("get_transfer_mode"), &NetworkedMultiplayerPeer::get_transfer_mode); ClassDB::bind_method(D_METHOD("set_target_peer", "id"), &NetworkedMultiplayerPeer::set_target_peer); diff --git a/core/io/networked_multiplayer_peer.h b/core/io/networked_multiplayer_peer.h index 8792886ff3..dc76237f45 100644 --- a/core/io/networked_multiplayer_peer.h +++ b/core/io/networked_multiplayer_peer.h @@ -34,7 +34,6 @@ #include "core/io/packet_peer.h" class NetworkedMultiplayerPeer : public PacketPeer { - GDCLASS(NetworkedMultiplayerPeer, PacketPeer); protected: diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index 6d3e1341a7..34fb5510b9 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -36,7 +36,6 @@ /* helpers / binders */ void PacketPeer::set_encode_buffer_max_size(int p_max_size) { - ERR_FAIL_COND_MSG(p_max_size < 1024, "Max encode buffer must be at least 1024 bytes"); ERR_FAIL_COND_MSG(p_max_size > 256 * 1024 * 1024, "Max encode buffer cannot exceed 256 MiB"); encode_buffer_max_size = next_power_of_2(p_max_size); @@ -44,12 +43,10 @@ void PacketPeer::set_encode_buffer_max_size(int p_max_size) { } int PacketPeer::get_encode_buffer_max_size() const { - return encode_buffer_max_size; } Error PacketPeer::get_packet_buffer(Vector<uint8_t> &r_buffer) { - const uint8_t *buffer; int buffer_size; Error err = get_packet(&buffer, buffer_size); @@ -68,7 +65,6 @@ Error PacketPeer::get_packet_buffer(Vector<uint8_t> &r_buffer) { } Error PacketPeer::put_packet_buffer(const Vector<uint8_t> &p_buffer) { - int len = p_buffer.size(); if (len == 0) return OK; @@ -78,7 +74,6 @@ Error PacketPeer::put_packet_buffer(const Vector<uint8_t> &p_buffer) { } Error PacketPeer::get_var(Variant &r_variant, bool p_allow_objects) { - const uint8_t *buffer; int buffer_size; Error err = get_packet(&buffer, buffer_size); @@ -89,7 +84,6 @@ Error PacketPeer::get_var(Variant &r_variant, bool p_allow_objects) { } Error PacketPeer::put_var(const Variant &p_packet, bool p_full_objects) { - int len; Error err = encode_variant(p_packet, nullptr, len, p_full_objects); // compute len first if (err) @@ -124,19 +118,16 @@ Error PacketPeer::_put_packet(const Vector<uint8_t> &p_buffer) { return put_packet_buffer(p_buffer); } Vector<uint8_t> PacketPeer::_get_packet() { - Vector<uint8_t> raw; last_get_error = get_packet_buffer(raw); return raw; } Error PacketPeer::_get_packet_error() const { - return last_get_error; } void PacketPeer::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_var", "allow_objects"), &PacketPeer::_bnd_get_var, DEFVAL(false)); ClassDB::bind_method(D_METHOD("put_var", "var", "full_objects"), &PacketPeer::put_var, DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_packet"), &PacketPeer::_get_packet); @@ -153,13 +144,11 @@ void PacketPeer::_bind_methods() { /***************/ void PacketPeerStream::_set_stream_peer(REF p_peer) { - ERR_FAIL_COND_MSG(p_peer.is_null(), "It's not a reference to a valid Resource object."); set_stream_peer(p_peer); } void PacketPeerStream::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_stream_peer", "peer"), &PacketPeerStream::set_stream_peer); ClassDB::bind_method(D_METHOD("get_stream_peer"), &PacketPeerStream::get_stream_peer); ClassDB::bind_method(D_METHOD("set_input_buffer_max_size", "max_size_bytes"), &PacketPeerStream::set_input_buffer_max_size); @@ -173,7 +162,6 @@ void PacketPeerStream::_bind_methods() { } Error PacketPeerStream::_poll_buffer() const { - ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED); int read = 0; @@ -191,7 +179,6 @@ Error PacketPeerStream::_poll_buffer() const { } int PacketPeerStream::get_available_packet_count() const { - _poll_buffer(); uint32_t remaining = ring_buffer.data_left(); @@ -200,7 +187,6 @@ int PacketPeerStream::get_available_packet_count() const { int count = 0; while (remaining >= 4) { - uint8_t lbuf[4]; ring_buffer.copy(lbuf, ofs, 4); uint32_t len = decode_uint32(lbuf); @@ -217,7 +203,6 @@ int PacketPeerStream::get_available_packet_count() 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(); @@ -239,7 +224,6 @@ Error PacketPeerStream::get_packet(const uint8_t **r_buffer, int &r_buffer_size) } Error PacketPeerStream::put_packet(const uint8_t *p_buffer, int p_buffer_size) { - ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED); Error err = _poll_buffer(); //won't hurt to poll here too @@ -261,12 +245,10 @@ Error PacketPeerStream::put_packet(const uint8_t *p_buffer, int p_buffer_size) { } int PacketPeerStream::get_max_packet_size() const { - return output_buffer.size(); } void PacketPeerStream::set_stream_peer(const Ref<StreamPeer> &p_peer) { - //ERR_FAIL_COND(p_peer.is_null()); if (p_peer.ptr() != peer.ptr()) { @@ -277,12 +259,10 @@ void PacketPeerStream::set_stream_peer(const Ref<StreamPeer> &p_peer) { } Ref<StreamPeer> PacketPeerStream::get_stream_peer() const { - return peer; } void PacketPeerStream::set_input_buffer_max_size(int p_max_size) { - ERR_FAIL_COND_MSG(p_max_size < 0, "Max size of input buffer size cannot be smaller than 0."); //warning may lose packets ERR_FAIL_COND_MSG(ring_buffer.data_left(), "Buffer in use, resizing would cause loss of data."); @@ -291,22 +271,18 @@ void PacketPeerStream::set_input_buffer_max_size(int p_max_size) { } int PacketPeerStream::get_input_buffer_max_size() const { - return input_buffer.size() - 4; } void PacketPeerStream::set_output_buffer_max_size(int p_max_size) { - output_buffer.resize(next_power_of_2(p_max_size + 4)); } int PacketPeerStream::get_output_buffer_max_size() const { - return output_buffer.size() - 4; } PacketPeerStream::PacketPeerStream() { - int rbsize = GLOBAL_GET("network/limits/packet_peer_stream/max_buffer_po2"); ring_buffer.resize(rbsize); diff --git a/core/io/packet_peer.h b/core/io/packet_peer.h index b69efa531f..f0ba50087f 100644 --- a/core/io/packet_peer.h +++ b/core/io/packet_peer.h @@ -36,7 +36,6 @@ #include "core/ring_buffer.h" class PacketPeer : public Reference { - GDCLASS(PacketPeer, Reference); Variant _bnd_get_var(bool p_allow_objects = false); @@ -75,7 +74,6 @@ public: }; class PacketPeerStream : public PacketPeer { - GDCLASS(PacketPeerStream, PacketPeer); //the way the buffers work sucks, will change later diff --git a/core/io/packet_peer_dtls.cpp b/core/io/packet_peer_dtls.cpp index ada3cb10a2..67579c339a 100644 --- a/core/io/packet_peer_dtls.cpp +++ b/core/io/packet_peer_dtls.cpp @@ -36,7 +36,6 @@ PacketPeerDTLS *(*PacketPeerDTLS::_create)() = nullptr; bool PacketPeerDTLS::available = false; PacketPeerDTLS *PacketPeerDTLS::create() { - return _create(); } @@ -45,7 +44,6 @@ bool PacketPeerDTLS::is_available() { } void PacketPeerDTLS::_bind_methods() { - ClassDB::bind_method(D_METHOD("poll"), &PacketPeerDTLS::poll); ClassDB::bind_method(D_METHOD("connect_to_peer", "packet_peer", "validate_certs", "for_hostname", "valid_certificate"), &PacketPeerDTLS::connect_to_peer, DEFVAL(true), DEFVAL(String()), DEFVAL(Ref<X509Certificate>())); ClassDB::bind_method(D_METHOD("get_status"), &PacketPeerDTLS::get_status); diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp index 8b6bd7ef90..0640d56c47 100644 --- a/core/io/packet_peer_udp.cpp +++ b/core/io/packet_peer_udp.cpp @@ -33,7 +33,6 @@ #include "core/io/ip.h" void PacketPeerUDP::set_blocking_mode(bool p_enable) { - blocking = p_enable; } @@ -44,7 +43,6 @@ void PacketPeerUDP::set_broadcast_enabled(bool p_enabled) { } Error PacketPeerUDP::join_multicast_group(IP_Address p_multi_address, String p_if_name) { - ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(!p_multi_address.is_valid(), ERR_INVALID_PARAMETER); @@ -59,19 +57,16 @@ Error PacketPeerUDP::join_multicast_group(IP_Address p_multi_address, String p_i } Error PacketPeerUDP::leave_multicast_group(IP_Address p_multi_address, String p_if_name) { - ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(!_sock->is_open(), ERR_UNCONFIGURED); return _sock->leave_multicast_group(p_multi_address, p_if_name); } String PacketPeerUDP::_get_packet_ip() const { - return get_packet_address(); } Error PacketPeerUDP::_set_dest_address(const String &p_address, int p_port) { - IP_Address ip; if (p_address.is_valid_ip_address()) { ip = p_address; @@ -86,7 +81,6 @@ Error PacketPeerUDP::_set_dest_address(const String &p_address, int p_port) { } int PacketPeerUDP::get_available_packet_count() const { - // TODO we should deprecate this, and expose poll instead! Error err = const_cast<PacketPeerUDP *>(this)->_poll(); if (err != OK) @@ -96,7 +90,6 @@ int PacketPeerUDP::get_available_packet_count() const { } Error PacketPeerUDP::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { - Error err = _poll(); if (err != OK) return err; @@ -117,7 +110,6 @@ Error PacketPeerUDP::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { } Error PacketPeerUDP::put_packet(const uint8_t *p_buffer, int p_buffer_size) { - ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(!peer_addr.is_valid(), ERR_UNCONFIGURED); @@ -154,12 +146,10 @@ Error PacketPeerUDP::put_packet(const uint8_t *p_buffer, int p_buffer_size) { } int PacketPeerUDP::get_max_packet_size() const { - return 512; // uhm maybe not } Error PacketPeerUDP::listen(int p_port, const IP_Address &p_bind_address, int p_recv_buffer_size) { - ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); @@ -245,7 +235,6 @@ bool PacketPeerUDP::is_connected_to_host() const { } void PacketPeerUDP::close() { - if (_sock.is_valid()) _sock->close(); rb.resize(16); @@ -254,13 +243,11 @@ void PacketPeerUDP::close() { } Error PacketPeerUDP::wait() { - ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); return _sock->poll(NetSocket::POLL_TYPE_IN, -1); } Error PacketPeerUDP::_poll() { - ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); if (!_sock->is_open()) { @@ -305,29 +292,24 @@ Error PacketPeerUDP::_poll() { return OK; } bool PacketPeerUDP::is_listening() const { - return _sock.is_valid() && _sock->is_open(); } IP_Address PacketPeerUDP::get_packet_address() const { - return packet_ip; } int PacketPeerUDP::get_packet_port() const { - return packet_port; } void PacketPeerUDP::set_dest_address(const IP_Address &p_address, int p_port) { - ERR_FAIL_COND_MSG(connected, "Destination address cannot be set for connected sockets"); peer_addr = p_address; peer_port = p_port; } void PacketPeerUDP::_bind_methods() { - ClassDB::bind_method(D_METHOD("listen", "port", "bind_address", "recv_buf_size"), &PacketPeerUDP::listen, DEFVAL("*"), DEFVAL(65536)); ClassDB::bind_method(D_METHOD("close"), &PacketPeerUDP::close); ClassDB::bind_method(D_METHOD("wait"), &PacketPeerUDP::wait); @@ -348,6 +330,5 @@ PacketPeerUDP::PacketPeerUDP() : } PacketPeerUDP::~PacketPeerUDP() { - close(); } diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp index 124ac30b88..4863cd1dbb 100644 --- a/core/io/pck_packer.cpp +++ b/core/io/pck_packer.cpp @@ -35,7 +35,6 @@ #include "core/version.h" static uint64_t _align(uint64_t p_n, int p_alignment) { - if (p_alignment == 0) return p_n; @@ -47,22 +46,18 @@ static uint64_t _align(uint64_t p_n, int p_alignment) { }; static void _pad(FileAccess *p_file, int p_bytes) { - for (int i = 0; i < p_bytes; i++) { - p_file->store_8(0); }; }; void PCKPacker::_bind_methods() { - ClassDB::bind_method(D_METHOD("pck_start", "pck_name", "alignment"), &PCKPacker::pck_start, DEFVAL(0)); ClassDB::bind_method(D_METHOD("add_file", "pck_path", "source_path"), &PCKPacker::add_file); ClassDB::bind_method(D_METHOD("flush", "verbose"), &PCKPacker::flush, DEFVAL(false)); }; Error PCKPacker::pck_start(const String &p_file, int p_alignment) { - if (file != nullptr) { memdelete(file); } @@ -80,7 +75,6 @@ Error PCKPacker::pck_start(const String &p_file, int p_alignment) { file->store_32(VERSION_PATCH); for (int i = 0; i < 16; i++) { - file->store_32(0); // reserved }; @@ -90,7 +84,6 @@ Error PCKPacker::pck_start(const String &p_file, int p_alignment) { }; Error PCKPacker::add_file(const String &p_file, const String &p_src) { - FileAccess *f = FileAccess::open(p_src, FileAccess::READ); if (!f) { return ERR_FILE_CANT_OPEN; @@ -111,7 +104,6 @@ Error PCKPacker::add_file(const String &p_file, const String &p_src) { }; Error PCKPacker::flush(bool p_verbose) { - ERR_FAIL_COND_V_MSG(!file, ERR_INVALID_PARAMETER, "File must be opened before use."); // write the index @@ -119,7 +111,6 @@ Error PCKPacker::flush(bool p_verbose) { file->store_32(files.size()); for (int i = 0; i < files.size(); i++) { - file->store_pascal_string(files[i].path); files.write[i].offset_offset = file->get_position(); file->store_64(0); // offset @@ -142,11 +133,9 @@ Error PCKPacker::flush(bool p_verbose) { int count = 0; for (int i = 0; i < files.size(); i++) { - FileAccess *src = FileAccess::open(files[i].src_path, FileAccess::READ); uint64_t to_write = files[i].size; while (to_write > 0) { - int read = src->get_buffer(buf, MIN(to_write, buf_max)); file->store_buffer(buf, read); to_write -= read; diff --git a/core/io/pck_packer.h b/core/io/pck_packer.h index 2848ac3a65..2929967a68 100644 --- a/core/io/pck_packer.h +++ b/core/io/pck_packer.h @@ -36,7 +36,6 @@ class FileAccess; class PCKPacker : public Reference { - GDCLASS(PCKPacker, Reference); FileAccess *file = nullptr; @@ -45,7 +44,6 @@ class PCKPacker : public Reference { static void _bind_methods(); struct File { - String path; String src_path; int size; diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 8ce17bcfbe..77fe331929 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -94,7 +94,6 @@ enum { }; void ResourceLoaderBinary::_advance_padding(uint32_t p_len) { - uint32_t extra = 4 - (p_len % 4); if (extra < 4) { for (uint32_t i = 0; i < extra; i++) @@ -103,7 +102,6 @@ void ResourceLoaderBinary::_advance_padding(uint32_t p_len) { } StringName ResourceLoaderBinary::_get_string() { - uint32_t id = f->get_32(); if (id & 0x80000000) { uint32_t len = id & 0x7FFFFFFF; @@ -122,42 +120,32 @@ StringName ResourceLoaderBinary::_get_string() { } Error ResourceLoaderBinary::parse_variant(Variant &r_v) { - uint32_t type = f->get_32(); print_bl("find property of type: " + itos(type)); switch (type) { - case VARIANT_NIL: { - r_v = Variant(); } break; case VARIANT_BOOL: { - r_v = bool(f->get_32()); } break; case VARIANT_INT: { - r_v = int(f->get_32()); } break; case VARIANT_INT64: { - r_v = int64_t(f->get_64()); } break; case VARIANT_FLOAT: { - r_v = f->get_real(); } break; case VARIANT_DOUBLE: { - r_v = f->get_double(); } break; case VARIANT_STRING: { - r_v = get_unicode_string(); } break; case VARIANT_VECTOR2: { - Vector2 v; v.x = f->get_real(); v.y = f->get_real(); @@ -165,7 +153,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_VECTOR2I: { - Vector2i v; v.x = f->get_32(); v.y = f->get_32(); @@ -173,7 +160,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_RECT2: { - Rect2 v; v.position.x = f->get_real(); v.position.y = f->get_real(); @@ -183,7 +169,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_RECT2I: { - Rect2i v; v.position.x = f->get_32(); v.position.y = f->get_32(); @@ -193,7 +178,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_VECTOR3: { - Vector3 v; v.x = f->get_real(); v.y = f->get_real(); @@ -201,7 +185,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = v; } break; case VARIANT_VECTOR3I: { - Vector3i v; v.x = f->get_32(); v.y = f->get_32(); @@ -209,7 +192,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = v; } break; case VARIANT_PLANE: { - Plane v; v.normal.x = f->get_real(); v.normal.y = f->get_real(); @@ -227,7 +209,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_AABB: { - AABB v; v.position.x = f->get_real(); v.position.y = f->get_real(); @@ -239,7 +220,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_MATRIX32: { - Transform2D v; v.elements[0].x = f->get_real(); v.elements[0].y = f->get_real(); @@ -251,7 +231,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_MATRIX3: { - Basis v; v.elements[0].x = f->get_real(); v.elements[0].y = f->get_real(); @@ -266,7 +245,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_TRANSFORM: { - Transform v; v.basis.elements[0].x = f->get_real(); v.basis.elements[0].y = f->get_real(); @@ -283,7 +261,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = v; } break; case VARIANT_COLOR: { - Color v; v.r = f->get_real(); v.g = f->get_real(); @@ -293,12 +270,10 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_STRING_NAME: { - r_v = StringName(get_unicode_string()); } break; case VARIANT_NODE_PATH: { - Vector<StringName> names; Vector<StringName> subnames; bool absolute; @@ -322,15 +297,12 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_RID: { - r_v = f->get_32(); } break; case VARIANT_OBJECT: { - uint32_t objtype = f->get_32(); switch (objtype) { - case OBJECT_EMPTY: { //do none @@ -384,7 +356,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { WARN_PRINT("Broken external resource! (index out of size)"); r_v = Variant(); } else { - if (external_resources[erindex].cache.is_null()) { //cache not here yet, wait for it? if (use_sub_threads) { @@ -393,10 +364,8 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { if (err != OK || external_resources[erindex].cache.is_null()) { if (!ResourceLoader::get_abort_on_missing_resources()) { - ResourceLoader::notify_dependency_error(local_path, external_resources[erindex].path, external_resources[erindex].type); } else { - error = ERR_FILE_MISSING_DEPENDENCIES; ERR_FAIL_V_MSG(error, "Can't load dependency: " + external_resources[erindex].path + "."); } @@ -409,23 +378,19 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { } break; default: { - ERR_FAIL_V(ERR_FILE_CORRUPT); } break; } } break; case VARIANT_CALLABLE: { - r_v = Callable(); } break; case VARIANT_SIGNAL: { - r_v = Signal(); } break; case VARIANT_DICTIONARY: { - uint32_t len = f->get_32(); Dictionary d; //last bit means shared len &= 0x7FFFFFFF; @@ -441,7 +406,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = d; } break; case VARIANT_ARRAY: { - uint32_t len = f->get_32(); Array a; //last bit means shared len &= 0x7FFFFFFF; @@ -456,7 +420,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_RAW_ARRAY: { - uint32_t len = f->get_32(); Vector<uint8_t> array; @@ -469,7 +432,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_INT32_ARRAY: { - uint32_t len = f->get_32(); Vector<int32_t> array; @@ -480,7 +442,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { { uint32_t *ptr = (uint32_t *)w.ptr(); for (int i = 0; i < len; i++) { - ptr[i] = BSWAP32(ptr[i]); } } @@ -490,7 +451,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = array; } break; case VARIANT_INT64_ARRAY: { - uint32_t len = f->get_32(); Vector<int64_t> array; @@ -501,7 +461,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { { uint64_t *ptr = (uint64_t *)w.ptr(); for (int i = 0; i < len; i++) { - ptr[i] = BSWAP64(ptr[i]); } } @@ -511,7 +470,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = array; } break; case VARIANT_FLOAT32_ARRAY: { - uint32_t len = f->get_32(); Vector<float> array; @@ -522,7 +480,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { { uint32_t *ptr = (uint32_t *)w.ptr(); for (int i = 0; i < len; i++) { - ptr[i] = BSWAP32(ptr[i]); } } @@ -532,7 +489,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = array; } break; case VARIANT_FLOAT64_ARRAY: { - uint32_t len = f->get_32(); Vector<double> array; @@ -543,7 +499,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { { uint64_t *ptr = (uint64_t *)w.ptr(); for (int i = 0; i < len; i++) { - ptr[i] = BSWAP64(ptr[i]); } } @@ -553,7 +508,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = array; } break; case VARIANT_STRING_ARRAY: { - uint32_t len = f->get_32(); Vector<String> array; array.resize(len); @@ -565,7 +519,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_VECTOR2_ARRAY: { - uint32_t len = f->get_32(); Vector<Vector2> array; @@ -577,7 +530,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { { uint32_t *ptr = (uint32_t *)w.ptr(); for (int i = 0; i < len * 2; i++) { - ptr[i] = BSWAP32(ptr[i]); } } @@ -592,7 +544,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_VECTOR3_ARRAY: { - uint32_t len = f->get_32(); Vector<Vector3> array; @@ -604,7 +555,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { { uint32_t *ptr = (uint32_t *)w.ptr(); for (int i = 0; i < len * 3; i++) { - ptr[i] = BSWAP32(ptr[i]); } } @@ -619,7 +569,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_COLOR_ARRAY: { - uint32_t len = f->get_32(); Vector<Color> array; @@ -631,7 +580,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { { uint32_t *ptr = (uint32_t *)w.ptr(); for (int i = 0; i < len * 4; i++) { - ptr[i] = BSWAP32(ptr[i]); } } @@ -653,23 +601,19 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { } void ResourceLoaderBinary::set_local_path(const String &p_local_path) { - res_path = p_local_path; } Ref<Resource> ResourceLoaderBinary::get_resource() { - return resource; } Error ResourceLoaderBinary::load() { - if (error != OK) return error; int stage = 0; for (int i = 0; i < external_resources.size(); i++) { - String path = external_resources[i].path; if (remaps.has(path)) { @@ -688,10 +632,8 @@ Error ResourceLoaderBinary::load() { if (external_resources[i].cache.is_null()) { if (!ResourceLoader::get_abort_on_missing_resources()) { - ResourceLoader::notify_dependency_error(local_path, path, external_resources[i].type); } else { - error = ERR_FILE_MISSING_DEPENDENCIES; ERR_FAIL_V_MSG(error, "Can't load dependency: " + path + "."); } @@ -701,10 +643,8 @@ Error ResourceLoaderBinary::load() { Error err = ResourceLoader::load_threaded_request(path, external_resources[i].type, use_sub_threads, local_path); if (err != OK) { if (!ResourceLoader::get_abort_on_missing_resources()) { - ResourceLoader::notify_dependency_error(local_path, path, external_resources[i].type); } else { - error = ERR_FILE_MISSING_DEPENDENCIES; ERR_FAIL_V_MSG(error, "Can't load dependency: " + path + "."); } @@ -715,7 +655,6 @@ Error ResourceLoaderBinary::load() { } for (int i = 0; i < internal_resources.size(); i++) { - bool main = i == (internal_resources.size() - 1); //maybe it is loaded already @@ -723,7 +662,6 @@ Error ResourceLoaderBinary::load() { int subindex = 0; if (!main) { - path = internal_resources[i].path; if (path.begins_with("local://")) { @@ -733,7 +671,6 @@ Error ResourceLoaderBinary::load() { } if (!use_nocache) { - if (ResourceCache::has(path)) { //already loaded, don't do anything stage++; @@ -742,7 +679,6 @@ Error ResourceLoaderBinary::load() { } } } else { - if (!use_nocache && !ResourceCache::has(res_path)) path = res_path; } @@ -783,7 +719,6 @@ Error ResourceLoaderBinary::load() { //set properties for (int j = 0; j < pc; j++) { - StringName name = _get_string(); if (name == StringName()) { @@ -811,7 +746,6 @@ Error ResourceLoaderBinary::load() { resource_cache.push_back(res); if (main) { - f->close(); resource = res; resource->set_as_translation_remapped(translation_remapped); @@ -824,19 +758,16 @@ Error ResourceLoaderBinary::load() { } void ResourceLoaderBinary::set_translation_remapped(bool p_remapped) { - translation_remapped = p_remapped; } static void save_ustring(FileAccess *f, const String &p_string) { - CharString utf8 = p_string.utf8(); f->store_32(utf8.length() + 1); f->store_buffer((const uint8_t *)utf8.get_data(), utf8.length() + 1); } static String get_ustring(FileAccess *f) { - int len = f->get_32(); Vector<char> str_buf; str_buf.resize(len); @@ -847,7 +778,6 @@ static String get_ustring(FileAccess *f) { } String ResourceLoaderBinary::get_unicode_string() { - int len = f->get_32(); if (len > str_buf.size()) { str_buf.resize(len); @@ -861,13 +791,11 @@ String ResourceLoaderBinary::get_unicode_string() { } void ResourceLoaderBinary::get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types) { - open(p_f); if (error) return; for (int i = 0; i < external_resources.size(); i++) { - String dep = external_resources[i].path; if (p_add_types && external_resources[i].type != String()) { @@ -879,7 +807,6 @@ void ResourceLoaderBinary::get_dependencies(FileAccess *p_f, List<String> *p_dep } void ResourceLoaderBinary::open(FileAccess *p_f) { - error = OK; f = p_f; @@ -924,7 +851,6 @@ void ResourceLoaderBinary::open(FileAccess *p_f) { print_bl("format: " + itos(ver_format)); if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) { - f->close(); ERR_FAIL_MSG("File format '" + itos(FORMAT_VERSION) + "." + itos(ver_major) + "." + itos(ver_minor) + "' is too new! Please upgrade to a new engine version: " + local_path + "."); } @@ -940,7 +866,6 @@ void ResourceLoaderBinary::open(FileAccess *p_f) { uint32_t string_table_size = f->get_32(); string_map.resize(string_table_size); for (uint32_t i = 0; i < string_table_size; i++) { - StringName s = get_unicode_string(); string_map.write[i] = s; } @@ -949,7 +874,6 @@ void ResourceLoaderBinary::open(FileAccess *p_f) { uint32_t ext_resources_size = f->get_32(); for (uint32_t i = 0; i < ext_resources_size; i++) { - ExtResource er; er.type = get_unicode_string(); @@ -962,7 +886,6 @@ void ResourceLoaderBinary::open(FileAccess *p_f) { uint32_t int_resources_size = f->get_32(); for (uint32_t i = 0; i < int_resources_size; i++) { - IntResource ir; ir.path = get_unicode_string(); ir.offset = f->get_64(); @@ -972,7 +895,6 @@ void ResourceLoaderBinary::open(FileAccess *p_f) { print_bl("int resources: " + itos(int_resources_size)); if (f->eof_reached()) { - error = ERR_FILE_CORRUPT; f->close(); ERR_FAIL_MSG("Premature end of file (EOF): " + local_path + "."); @@ -980,7 +902,6 @@ void ResourceLoaderBinary::open(FileAccess *p_f) { } String ResourceLoaderBinary::recognize(FileAccess *p_f) { - error = OK; f = p_f; @@ -1014,7 +935,6 @@ String ResourceLoaderBinary::recognize(FileAccess *p_f) { uint32_t ver_format = f->get_32(); if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) { - f->close(); return ""; } @@ -1025,13 +945,11 @@ String ResourceLoaderBinary::recognize(FileAccess *p_f) { } ResourceLoaderBinary::~ResourceLoaderBinary() { - if (f) memdelete(f); } RES ResourceFormatLoaderBinary::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) *r_error = ERR_FILE_CANT_OPEN; @@ -1063,7 +981,6 @@ RES ResourceFormatLoaderBinary::load(const String &p_path, const String &p_origi } void ResourceFormatLoaderBinary::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const { - if (p_type == "") { get_recognized_extensions(p_extensions); return; @@ -1080,7 +997,6 @@ void ResourceFormatLoaderBinary::get_recognized_extensions_for_type(const String } } void ResourceFormatLoaderBinary::get_recognized_extensions(List<String> *p_extensions) const { - List<String> extensions; ClassDB::get_resource_base_extensions(&extensions); extensions.sort(); @@ -1092,12 +1008,10 @@ void ResourceFormatLoaderBinary::get_recognized_extensions(List<String> *p_exten } bool ResourceFormatLoaderBinary::handles_type(const String &p_type) const { - return true; //handles all } void ResourceFormatLoaderBinary::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) { - FileAccess *f = FileAccess::open(p_path, FileAccess::READ); ERR_FAIL_COND_MSG(!f, "Cannot open file '" + p_path + "'."); @@ -1109,7 +1023,6 @@ void ResourceFormatLoaderBinary::get_dependencies(const String &p_path, List<Str } Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, const Map<String, String> &p_map) { - //Error error=OK; FileAccess *f = FileAccess::open(p_path, FileAccess::READ); @@ -1175,7 +1088,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons uint32_t ver_format = f->get_32(); if (ver_format < FORMAT_VERSION_CAN_RENAME_DEPS) { - memdelete(f); memdelete(fw); DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); @@ -1207,7 +1119,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons } if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) { - memdelete(f); memdelete(fw); ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "File format '" + itos(FORMAT_VERSION) + "." + itos(ver_major) + "." + itos(ver_minor) + "' is too new! Please upgrade to a new engine version: " + local_path + "."); @@ -1236,7 +1147,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons fw->store_32(string_table_size); for (uint32_t i = 0; i < string_table_size; i++) { - String s = get_ustring(f); save_ustring(fw, s); } @@ -1245,7 +1155,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons uint32_t ext_resources_size = f->get_32(); fw->store_32(ext_resources_size); for (uint32_t i = 0; i < ext_resources_size; i++) { - String type = get_ustring(f); String path = get_ustring(f); @@ -1276,7 +1185,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons fw->store_32(int_resources_size); for (uint32_t i = 0; i < int_resources_size; i++) { - String path = get_ustring(f); uint64_t offset = f->get_64(); save_ustring(fw, path); @@ -1310,7 +1218,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons } String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const { - FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) { return ""; //could not rwead @@ -1329,7 +1236,6 @@ String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const /////////////////////////////////////////////////////////// void ResourceFormatSaverBinaryInstance::_pad_buffer(FileAccess *f, int p_bytes) { - int extra = 4 - (p_bytes % 4); if (extra < 4) { for (int i = 0; i < extra; i++) @@ -1338,27 +1244,21 @@ void ResourceFormatSaverBinaryInstance::_pad_buffer(FileAccess *f, int p_bytes) } void ResourceFormatSaverBinaryInstance::_write_variant(const Variant &p_property, const PropertyInfo &p_hint) { - write_variant(f, p_property, resource_set, external_resources, string_map, p_hint); } void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Variant &p_property, Set<RES> &resource_set, Map<RES, int> &external_resources, Map<StringName, int> &string_map, const PropertyInfo &p_hint) { - switch (p_property.get_type()) { - case Variant::NIL: { - f->store_32(VARIANT_NIL); // don't store anything } break; case Variant::BOOL: { - f->store_32(VARIANT_BOOL); bool val = p_property; f->store_32(val); } break; case Variant::INT: { - int64_t val = p_property; if (val > 0x7FFFFFFF || val < -(int64_t)0x80000000) { f->store_32(VARIANT_INT64); @@ -1371,28 +1271,24 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::FLOAT: { - double d = p_property; float fl = d; if (double(fl) != d) { f->store_32(VARIANT_DOUBLE); f->store_double(d); } else { - f->store_32(VARIANT_FLOAT); f->store_real(fl); } } break; case Variant::STRING: { - f->store_32(VARIANT_STRING); String val = p_property; save_unicode_string(f, val); } break; case Variant::VECTOR2: { - f->store_32(VARIANT_VECTOR2); Vector2 val = p_property; f->store_real(val.x); @@ -1400,7 +1296,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::VECTOR2I: { - f->store_32(VARIANT_VECTOR2I); Vector2i val = p_property; f->store_32(val.x); @@ -1408,7 +1303,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::RECT2: { - f->store_32(VARIANT_RECT2); Rect2 val = p_property; f->store_real(val.position.x); @@ -1418,7 +1312,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::RECT2I: { - f->store_32(VARIANT_RECT2I); Rect2i val = p_property; f->store_32(val.position.x); @@ -1428,7 +1321,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::VECTOR3: { - f->store_32(VARIANT_VECTOR3); Vector3 val = p_property; f->store_real(val.x); @@ -1437,7 +1329,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::VECTOR3I: { - f->store_32(VARIANT_VECTOR3I); Vector3i val = p_property; f->store_32(val.x); @@ -1446,7 +1337,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PLANE: { - f->store_32(VARIANT_PLANE); Plane val = p_property; f->store_real(val.normal.x); @@ -1456,7 +1346,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::QUAT: { - f->store_32(VARIANT_QUAT); Quat val = p_property; f->store_real(val.x); @@ -1466,7 +1355,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::AABB: { - f->store_32(VARIANT_AABB); AABB val = p_property; f->store_real(val.position.x); @@ -1478,7 +1366,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::TRANSFORM2D: { - f->store_32(VARIANT_MATRIX32); Transform2D val = p_property; f->store_real(val.elements[0].x); @@ -1490,7 +1377,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::BASIS: { - f->store_32(VARIANT_MATRIX3); Basis val = p_property; f->store_real(val.elements[0].x); @@ -1505,7 +1391,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::TRANSFORM: { - f->store_32(VARIANT_TRANSFORM); Transform val = p_property; f->store_real(val.basis.elements[0].x); @@ -1523,7 +1408,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::COLOR: { - f->store_32(VARIANT_COLOR); Color val = p_property; f->store_real(val.r); @@ -1533,7 +1417,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::STRING_NAME: { - f->store_32(VARIANT_STRING_NAME); String val = p_property; save_unicode_string(f, val); @@ -1565,14 +1448,12 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::_RID: { - f->store_32(VARIANT_RID); WARN_PRINT("Can't save RIDs."); RID val = p_property; f->store_32(val.get_id()); } break; case Variant::OBJECT: { - f->store_32(VARIANT_OBJECT); RES res = p_property; if (res.is_null()) { @@ -1584,7 +1465,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia f->store_32(OBJECT_EXTERNAL_RESOURCE_INDEX); f->store_32(external_resources[res]); } else { - if (!resource_set.has(res)) { f->store_32(OBJECT_EMPTY); ERR_FAIL_MSG("Resource was not pre cached for the resource section, most likely due to circular reference."); @@ -1597,18 +1477,15 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::CALLABLE: { - f->store_32(VARIANT_CALLABLE); WARN_PRINT("Can't save Callables."); } break; case Variant::SIGNAL: { - f->store_32(VARIANT_SIGNAL); WARN_PRINT("Can't save Signals."); } break; case Variant::DICTIONARY: { - f->store_32(VARIANT_DICTIONARY); Dictionary d = p_property; f->store_32(uint32_t(d.size())); @@ -1617,7 +1494,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia d.get_key_list(&keys); for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { - /* if (!_check_type(dict[E->get()])) continue; @@ -1629,18 +1505,15 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::ARRAY: { - f->store_32(VARIANT_ARRAY); Array a = p_property; f->store_32(uint32_t(a.size())); for (int i = 0; i < a.size(); i++) { - write_variant(f, a[i], resource_set, external_resources, string_map); } } break; case Variant::PACKED_BYTE_ARRAY: { - f->store_32(VARIANT_RAW_ARRAY); Vector<uint8_t> arr = p_property; int len = arr.size(); @@ -1651,7 +1524,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PACKED_INT32_ARRAY: { - f->store_32(VARIANT_INT32_ARRAY); Vector<int32_t> arr = p_property; int len = arr.size(); @@ -1662,7 +1534,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PACKED_INT64_ARRAY: { - f->store_32(VARIANT_INT64_ARRAY); Vector<int64_t> arr = p_property; int len = arr.size(); @@ -1673,7 +1544,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PACKED_FLOAT32_ARRAY: { - f->store_32(VARIANT_FLOAT32_ARRAY); Vector<float> arr = p_property; int len = arr.size(); @@ -1685,7 +1555,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PACKED_FLOAT64_ARRAY: { - f->store_32(VARIANT_FLOAT64_ARRAY); Vector<double> arr = p_property; int len = arr.size(); @@ -1697,7 +1566,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PACKED_STRING_ARRAY: { - f->store_32(VARIANT_STRING_ARRAY); Vector<String> arr = p_property; int len = arr.size(); @@ -1709,7 +1577,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PACKED_VECTOR3_ARRAY: { - f->store_32(VARIANT_VECTOR3_ARRAY); Vector<Vector3> arr = p_property; int len = arr.size(); @@ -1723,7 +1590,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PACKED_VECTOR2_ARRAY: { - f->store_32(VARIANT_VECTOR2_ARRAY); Vector<Vector2> arr = p_property; int len = arr.size(); @@ -1736,7 +1602,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PACKED_COLOR_ARRAY: { - f->store_32(VARIANT_COLOR_ARRAY); Vector<Color> arr = p_property; int len = arr.size(); @@ -1751,17 +1616,14 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; default: { - ERR_FAIL_MSG("Invalid variant."); } } } void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant, bool p_main) { - switch (p_variant.get_type()) { case Variant::OBJECT: { - RES res = p_variant; if (res.is_null() || external_resources.has(res)) @@ -1785,9 +1647,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant res->get_property_list(&property_list); for (List<PropertyInfo>::Element *E = property_list.front(); E; E = E->next()) { - if (E->get().usage & PROPERTY_USAGE_STORAGE) { - Variant value = res->get(E->get().name); if (E->get().usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT) { RES sres = value; @@ -1811,11 +1671,9 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant } break; case Variant::ARRAY: { - Array varray = p_variant; int len = varray.size(); for (int i = 0; i < len; i++) { - const Variant &v = varray.get(i); _find_resources(v); } @@ -1823,12 +1681,10 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant } break; case Variant::DICTIONARY: { - Dictionary d = p_variant; List<Variant> keys; d.get_key_list(&keys); for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { - _find_resources(E->get()); Variant v = d[E->get()]; _find_resources(v); @@ -1849,7 +1705,6 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant } void ResourceFormatSaverBinaryInstance::save_unicode_string(FileAccess *f, const String &p_string, bool p_bit_on_len) { - CharString utf8 = p_string.utf8(); if (p_bit_on_len) { f->store_32((utf8.length() + 1) | 0x80000000); @@ -1860,7 +1715,6 @@ void ResourceFormatSaverBinaryInstance::save_unicode_string(FileAccess *f, const } int ResourceFormatSaverBinaryInstance::get_string_index(const String &p_string) { - StringName s = p_string; if (string_map.has(s)) return string_map[s]; @@ -1871,7 +1725,6 @@ int ResourceFormatSaverBinaryInstance::get_string_index(const String &p_string) } Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - Error err; if (p_flags & ResourceSaver::FLAG_COMPRESS) { FileAccessCompressed *fac = memnew(FileAccessCompressed); @@ -1932,9 +1785,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p List<ResourceData> resources; { - for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) { - ResourceData &rd = resources.push_back(ResourceData())->get(); rd.type = E->get()->get_class(); @@ -1942,7 +1793,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p E->get()->get_property_list(&property_list); for (List<PropertyInfo>::Element *F = property_list.front(); F; F = F->next()) { - if (skip_editor && F->get().name.begins_with("__editor")) continue; if ((F->get().usage & PROPERTY_USAGE_STORAGE)) { @@ -1989,7 +1839,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p } for (int i = 0; i < save_order.size(); i++) { - save_unicode_string(f, save_order[i]->get_save_class()); String path = save_order[i]->get_path(); path = relative_paths ? local_path.path_to_file(path) : path; @@ -2001,10 +1850,8 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p Set<int> used_indices; for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) { - RES r = E->get(); if (r->get_path() == "" || r->get_path().find("::") != -1) { - if (r->get_subindex() != 0) { if (used_indices.has(r->get_subindex())) { r->set_subindex(0); //repeated @@ -2016,7 +1863,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p } for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) { - RES r = E->get(); if (r->get_path() == "" || r->get_path().find("::") != -1) { if (r->get_subindex() == 0) { @@ -2047,7 +1893,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p //now actually save the resources for (List<ResourceData>::Element *E = resources.front(); E; E = E->next()) { - ResourceData &rd = E->get(); ofs_table.push_back(f->get_position()); @@ -2055,7 +1900,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p f->store_32(rd.properties.size()); for (List<Property>::Element *F = rd.properties.front(); F; F = F->next()) { - Property &p = F->get(); f->store_32(p.name_idx); _write_variant(p.value, F->get().pi); @@ -2084,19 +1928,16 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p } Error ResourceFormatSaverBinary::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - String local_path = ProjectSettings::get_singleton()->localize_path(p_path); ResourceFormatSaverBinaryInstance saver; return saver.save(local_path, p_resource, p_flags); } bool ResourceFormatSaverBinary::recognize(const RES &p_resource) const { - return true; //all recognized } void ResourceFormatSaverBinary::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { - String base = p_resource->get_base_extension().to_lower(); p_extensions->push_back(base); if (base != "res") diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index 57aa086022..54cddca49e 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -36,7 +36,6 @@ #include "core/os/file_access.h" class ResourceLoaderBinary { - bool translation_remapped = false; String local_path; String res_path; @@ -114,7 +113,6 @@ public: }; class ResourceFormatSaverBinaryInstance { - String local_path; String path; @@ -147,7 +145,6 @@ class ResourceFormatSaverBinaryInstance { }; struct ResourceData { - String type; List<Property> properties; }; diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index 9e22bdced7..c2e27bc9c2 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -38,7 +38,6 @@ bool ResourceFormatImporter::SortImporterByName::operator()(const Ref<ResourceIm } Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndType &r_path_and_type, bool *r_valid) const { - Error err; FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err); @@ -64,7 +63,6 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy String error_text; bool path_found = false; //first match must have priority while (true) { - assign = Variant(); next_tag.fields.clear(); next_tag.name = String(); @@ -118,12 +116,10 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy } RES ResourceFormatImporter::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - PathAndType pat; Error err = _get_path_and_type(p_path, pat); if (err != OK) { - if (r_error) *r_error = err; @@ -143,7 +139,6 @@ RES ResourceFormatImporter::load(const String &p_path, const String &p_original_ } void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extensions) const { - Set<String> found; for (int i = 0; i < importers.size(); i++) { @@ -159,7 +154,6 @@ void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extension } void ResourceFormatImporter::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const { - if (p_type == "") { get_recognized_extensions(p_extensions); return; @@ -187,26 +181,21 @@ void ResourceFormatImporter::get_recognized_extensions_for_type(const String &p_ } bool ResourceFormatImporter::exists(const String &p_path) const { - return FileAccess::exists(p_path + ".import"); } bool ResourceFormatImporter::recognize_path(const String &p_path, const String &p_for_type) const { - return FileAccess::exists(p_path + ".import"); } 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); @@ -214,7 +203,6 @@ int ResourceFormatImporter::get_import_order(const String &p_path) const { importer = get_importer_by_name(pat.importer); } } else { - importer = get_importer_by_extension(p_path.get_extension().to_lower()); } @@ -225,9 +213,7 @@ int ResourceFormatImporter::get_import_order(const String &p_path) const { } bool ResourceFormatImporter::handles_type(const String &p_type) const { - for (int i = 0; i < importers.size(); i++) { - String res_type = importers[i]->get_resource_type(); if (res_type == String()) continue; @@ -239,12 +225,10 @@ bool ResourceFormatImporter::handles_type(const String &p_type) const { } String ResourceFormatImporter::get_internal_resource_path(const String &p_path) const { - PathAndType pat; Error err = _get_path_and_type(p_path, pat); if (err != OK) { - return String(); } @@ -252,7 +236,6 @@ String ResourceFormatImporter::get_internal_resource_path(const String &p_path) } void ResourceFormatImporter::get_internal_resource_path_list(const String &p_path, List<String> *r_paths) { - Error err; FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err); @@ -269,7 +252,6 @@ void ResourceFormatImporter::get_internal_resource_path_list(const String &p_pat int lines = 0; String error_text; while (true) { - assign = Variant(); next_tag.fields.clear(); next_tag.name = String(); @@ -298,7 +280,6 @@ void ResourceFormatImporter::get_internal_resource_path_list(const String &p_pat } String ResourceFormatImporter::get_import_group_file(const String &p_path) const { - bool valid = true; PathAndType pat; _get_path_and_type(p_path, pat, &valid); @@ -306,7 +287,6 @@ String ResourceFormatImporter::get_import_group_file(const String &p_path) const } bool ResourceFormatImporter::is_import_valid(const String &p_path) const { - bool valid = true; PathAndType pat; _get_path_and_type(p_path, pat, &valid); @@ -314,12 +294,10 @@ bool ResourceFormatImporter::is_import_valid(const String &p_path) const { } String ResourceFormatImporter::get_resource_type(const String &p_path) const { - PathAndType pat; Error err = _get_path_and_type(p_path, pat); if (err != OK) { - return ""; } @@ -331,7 +309,6 @@ Variant ResourceFormatImporter::get_resource_metadata(const String &p_path) cons Error err = _get_path_and_type(p_path, pat); if (err != OK) { - return Variant(); } @@ -339,12 +316,10 @@ Variant ResourceFormatImporter::get_resource_metadata(const String &p_path) cons } void ResourceFormatImporter::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) { - PathAndType pat; Error err = _get_path_and_type(p_path, pat); if (err != OK) { - return; } @@ -352,7 +327,6 @@ void ResourceFormatImporter::get_dependencies(const String &p_path, List<String> } Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String &p_name) const { - for (int i = 0; i < importers.size(); i++) { if (importers[i]->get_importer_name() == p_name) { return importers[i]; @@ -363,7 +337,6 @@ Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String } void ResourceFormatImporter::get_importers_for_extension(const String &p_extension, List<Ref<ResourceImporter>> *r_importers) { - for (int i = 0; i < importers.size(); i++) { List<String> local_exts; importers[i]->get_recognized_extensions(&local_exts); @@ -376,12 +349,10 @@ void ResourceFormatImporter::get_importers_for_extension(const String &p_extensi } Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const String &p_extension) const { - Ref<ResourceImporter> importer; float priority = 0; for (int i = 0; i < importers.size(); i++) { - List<String> local_exts; importers[i]->get_recognized_extensions(&local_exts); for (List<String>::Element *F = local_exts.front(); F; F = F->next()) { @@ -396,12 +367,10 @@ Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const St } String ResourceFormatImporter::get_import_base_path(const String &p_for_file) const { - return "res://.import/" + p_for_file.get_file() + "-" + p_for_file.md5_text(); } bool ResourceFormatImporter::are_import_settings_valid(const String &p_path) const { - bool valid = true; PathAndType pat; _get_path_and_type(p_path, pat, &valid); @@ -422,7 +391,6 @@ bool ResourceFormatImporter::are_import_settings_valid(const String &p_path) con } String ResourceFormatImporter::get_import_settings_hash() const { - Vector<Ref<ResourceImporter>> sorted_importers = importers; sorted_importers.sort_custom<SortImporterByName>(); diff --git a/core/io/resource_importer.h b/core/io/resource_importer.h index 6b76912494..d31a9a0194 100644 --- a/core/io/resource_importer.h +++ b/core/io/resource_importer.h @@ -36,7 +36,6 @@ class ResourceImporter; class ResourceFormatImporter : public ResourceFormatLoader { - struct PathAndType { String path; String type; @@ -93,7 +92,6 @@ public: }; class ResourceImporter : public Reference { - GDCLASS(ResourceImporter, Reference); public: diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index dc44be4e0b..361f40cbc6 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -49,7 +49,6 @@ Ref<ResourceFormatLoader> ResourceLoader::loader[ResourceLoader::MAX_LOADERS]; int ResourceLoader::loader_count = 0; bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_for_type) const { - String extension = p_path.get_extension(); List<String> extensions; @@ -60,7 +59,6 @@ bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_ } for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - if (E->get().nocasecmp_to(extension) == 0) return true; } @@ -69,7 +67,6 @@ bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_ } bool ResourceFormatLoader::handles_type(const String &p_type) const { - if (get_script_instance() && get_script_instance()->has_method("handles_type")) { // I guess custom loaders for custom resources should use "Resource" return get_script_instance()->call("handles_type", p_type); @@ -79,7 +76,6 @@ bool ResourceFormatLoader::handles_type(const String &p_type) const { } String ResourceFormatLoader::get_resource_type(const String &p_path) const { - if (get_script_instance() && get_script_instance()->has_method("get_resource_type")) { return get_script_instance()->call("get_resource_type", p_path); } @@ -88,13 +84,11 @@ String ResourceFormatLoader::get_resource_type(const String &p_path) const { } void ResourceFormatLoader::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const { - if (p_type == "" || handles_type(p_type)) get_recognized_extensions(p_extensions); } void ResourceLoader::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) { - for (int i = 0; i < loader_count; i++) { loader[i]->get_recognized_extensions_for_type(p_type, p_extensions); } @@ -105,7 +99,6 @@ bool ResourceFormatLoader::exists(const String &p_path) const { } void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions) const { - if (get_script_instance() && get_script_instance()->has_method("get_recognized_extensions")) { PackedStringArray exts = get_script_instance()->call("get_recognized_extensions"); @@ -119,17 +112,14 @@ void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions) } RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (get_script_instance() && get_script_instance()->has_method("load")) { Variant res = get_script_instance()->call("load", p_path, p_original_path, p_use_sub_threads); if (res.get_type() == Variant::INT) { - if (r_error) *r_error = (Error)res.operator int64_t(); } else { - if (r_error) *r_error = OK; return res; @@ -142,7 +132,6 @@ RES ResourceFormatLoader::load(const String &p_path, const String &p_original_pa } void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) { - if (get_script_instance() && get_script_instance()->has_method("get_dependencies")) { PackedStringArray deps = get_script_instance()->call("get_dependencies", p_path, p_add_types); @@ -156,9 +145,7 @@ void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> * } Error ResourceFormatLoader::rename_dependencies(const String &p_path, const Map<String, String> &p_map) { - if (get_script_instance() && get_script_instance()->has_method("rename_dependencies")) { - Dictionary deps_dict; for (Map<String, String>::Element *E = p_map.front(); E; E = E->next()) { deps_dict[E->key()] = E->value(); @@ -172,7 +159,6 @@ Error ResourceFormatLoader::rename_dependencies(const String &p_path, const Map< } void ResourceFormatLoader::_bind_methods() { - { MethodInfo info = MethodInfo(Variant::NIL, "load", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "original_path")); info.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; @@ -189,12 +175,10 @@ void ResourceFormatLoader::_bind_methods() { /////////////////////////////////// RES ResourceLoader::_load(const String &p_path, const String &p_original_path, const String &p_type_hint, bool p_no_cache, Error *r_error, bool p_use_sub_threads, float *r_progress) { - bool found = false; // Try all loaders and pick the first match for the type hint for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(p_path, p_type_hint)) { continue; } @@ -218,7 +202,6 @@ RES ResourceLoader::_load(const String &p_path, const String &p_original_path, c } void ResourceLoader::_thread_load_function(void *p_userdata) { - ThreadLoadTask &load_task = *(ThreadLoadTask *)p_userdata; load_task.loader_id = Thread::get_caller_id(); @@ -237,7 +220,6 @@ void ResourceLoader::_thread_load_function(void *p_userdata) { load_task.status = THREAD_LOAD_LOADED; } if (load_task.semaphore) { - if (load_task.start_next && thread_waiting_count > 0) { thread_waiting_count--; //thread loading count remains constant, this ends but another one begins @@ -279,7 +261,6 @@ void ResourceLoader::_thread_load_function(void *p_userdata) { thread_load_mutex->unlock(); } Error ResourceLoader::load_threaded_request(const String &p_path, const String &p_type_hint, bool p_use_sub_threads, const String &p_source_resource) { - String local_path; if (p_path.is_rel_path()) local_path = "res://" + p_path; @@ -387,7 +368,6 @@ Error ResourceLoader::load_threaded_request(const String &p_path, const String & } float ResourceLoader::_dependency_get_progress(const String &p_path) { - if (thread_load_tasks.has(p_path)) { ThreadLoadTask &load_task = thread_load_tasks[p_path]; int dep_count = load_task.sub_tasks.size(); @@ -410,7 +390,6 @@ float ResourceLoader::_dependency_get_progress(const String &p_path) { } ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const String &p_path, float *r_progress) { - String local_path; if (p_path.is_rel_path()) local_path = "res://" + p_path; @@ -434,7 +413,6 @@ ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const return status; } RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) { - String local_path; if (p_path.is_rel_path()) local_path = "res://" + p_path; @@ -516,7 +494,6 @@ RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) { } RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) { - if (r_error) *r_error = ERR_CANT_OPEN; @@ -527,7 +504,6 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p local_path = ProjectSettings::get_singleton()->localize_path(p_path); if (!p_no_cache) { - thread_load_mutex->lock(); //Is it already being loaded? poll until done @@ -592,7 +568,6 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p return load_threaded_get(p_path, r_error); } else { - bool xl_remapped = false; String path = _path_remap(local_path, &xl_remapped); @@ -627,7 +602,6 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p } bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) { - String local_path; if (p_path.is_rel_path()) local_path = "res://" + p_path; @@ -635,7 +609,6 @@ bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) { local_path = ProjectSettings::get_singleton()->localize_path(p_path); if (ResourceCache::has(local_path)) { - return true; // If cached, it probably exists } @@ -644,7 +617,6 @@ bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) { // Try all loaders and pick the first match for the type hint for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(path, p_type_hint)) { continue; } @@ -657,7 +629,6 @@ bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) { } void ResourceLoader::add_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader, bool p_at_front) { - ERR_FAIL_COND(p_format_loader.is_null()); ERR_FAIL_COND(loader_count >= MAX_LOADERS); @@ -673,7 +644,6 @@ void ResourceLoader::add_resource_format_loader(Ref<ResourceFormatLoader> p_form } void ResourceLoader::remove_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader) { - ERR_FAIL_COND(p_format_loader.is_null()); // Find loader @@ -694,7 +664,6 @@ void ResourceLoader::remove_resource_format_loader(Ref<ResourceFormatLoader> p_f } int ResourceLoader::get_import_order(const String &p_path) { - String path = _path_remap(p_path); String local_path; @@ -704,7 +673,6 @@ int ResourceLoader::get_import_order(const String &p_path) { local_path = ProjectSettings::get_singleton()->localize_path(path); for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) continue; /* @@ -728,7 +696,6 @@ String ResourceLoader::get_import_group_file(const String &p_path) { local_path = ProjectSettings::get_singleton()->localize_path(path); for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) continue; /* @@ -743,7 +710,6 @@ String ResourceLoader::get_import_group_file(const String &p_path) { } bool ResourceLoader::is_import_valid(const String &p_path) { - String path = _path_remap(p_path); String local_path; @@ -753,7 +719,6 @@ bool ResourceLoader::is_import_valid(const String &p_path) { local_path = ProjectSettings::get_singleton()->localize_path(path); for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) continue; /* @@ -768,7 +733,6 @@ bool ResourceLoader::is_import_valid(const String &p_path) { } bool ResourceLoader::is_imported(const String &p_path) { - String path = _path_remap(p_path); String local_path; @@ -778,7 +742,6 @@ bool ResourceLoader::is_imported(const String &p_path) { local_path = ProjectSettings::get_singleton()->localize_path(path); for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) continue; /* @@ -793,7 +756,6 @@ bool ResourceLoader::is_imported(const String &p_path) { } void ResourceLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) { - String path = _path_remap(p_path); String local_path; @@ -803,7 +765,6 @@ void ResourceLoader::get_dependencies(const String &p_path, List<String> *p_depe local_path = ProjectSettings::get_singleton()->localize_path(path); for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) continue; /* @@ -816,7 +777,6 @@ void ResourceLoader::get_dependencies(const String &p_path, List<String> *p_depe } Error ResourceLoader::rename_dependencies(const String &p_path, const Map<String, String> &p_map) { - String path = _path_remap(p_path); String local_path; @@ -826,7 +786,6 @@ Error ResourceLoader::rename_dependencies(const String &p_path, const Map<String local_path = ProjectSettings::get_singleton()->localize_path(path); for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) continue; /* @@ -841,7 +800,6 @@ Error ResourceLoader::rename_dependencies(const String &p_path, const Map<String } String ResourceLoader::get_resource_type(const String &p_path) { - String local_path; if (p_path.is_rel_path()) local_path = "res://" + p_path; @@ -849,7 +807,6 @@ String ResourceLoader::get_resource_type(const String &p_path) { local_path = ProjectSettings::get_singleton()->localize_path(p_path); for (int i = 0; i < loader_count; i++) { - String result = loader[i]->get_resource_type(local_path); if (result != "") { return result; @@ -860,7 +817,6 @@ String ResourceLoader::get_resource_type(const String &p_path) { } String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_remapped) { - String new_path = p_path; if (translation_remaps.has(p_path)) { @@ -919,7 +875,6 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem FileAccess *f = FileAccess::open(p_path + ".remap", FileAccess::READ, &err); if (f) { - VariantParser::StreamFile stream; stream.f = f; @@ -930,7 +885,6 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem int lines = 0; String error_text; while (true) { - assign = Variant(); next_tag.fields.clear(); next_tag.name = String(); @@ -959,9 +913,7 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem } String ResourceLoader::import_remap(const String &p_path) { - if (ResourceFormatImporter::get_singleton()->recognize_path(p_path)) { - return ResourceFormatImporter::get_singleton()->get_internal_resource_path(p_path); } @@ -973,7 +925,6 @@ String ResourceLoader::path_remap(const String &p_path) { } void ResourceLoader::reload_translation_remaps() { - if (ResourceCache::lock) { ResourceCache::lock->read_lock(); } @@ -998,7 +949,6 @@ void ResourceLoader::reload_translation_remaps() { } void ResourceLoader::load_translation_remaps() { - if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) return; @@ -1006,7 +956,6 @@ void ResourceLoader::load_translation_remaps() { List<Variant> keys; remaps.get_key_list(&keys); for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { - Array langs = remaps[E->get()]; Vector<String> lang_remaps; lang_remaps.resize(langs.size()); @@ -1023,7 +972,6 @@ void ResourceLoader::clear_translation_remaps() { } void ResourceLoader::load_path_remaps() { - if (!ProjectSettings::get_singleton()->has_setting("path_remap/remapped_paths")) return; @@ -1033,13 +981,11 @@ void ResourceLoader::load_path_remaps() { const String *r = remaps.ptr(); for (int i = 0; i < rc; i += 2) { - path_remaps[r[i]] = r[i + 1]; } } void ResourceLoader::clear_path_remaps() { - path_remaps.clear(); } @@ -1059,7 +1005,6 @@ Ref<ResourceFormatLoader> ResourceLoader::_find_custom_resource_format_loader(St } bool ResourceLoader::add_custom_resource_format_loader(String script_path) { - if (_find_custom_resource_format_loader(script_path).is_valid()) return false; @@ -1084,7 +1029,6 @@ bool ResourceLoader::add_custom_resource_format_loader(String script_path) { } void ResourceLoader::remove_custom_resource_format_loader(String script_path) { - Ref<ResourceFormatLoader> custom_loader = _find_custom_resource_format_loader(script_path); if (custom_loader.is_valid()) remove_resource_format_loader(custom_loader); @@ -1099,7 +1043,6 @@ void ResourceLoader::add_custom_loaders() { ScriptServer::get_global_class_list(&global_classes); for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) { - StringName class_name = E->get(); StringName base_class = ScriptServer::get_global_class_native_base(class_name); @@ -1111,7 +1054,6 @@ void ResourceLoader::add_custom_loaders() { } void ResourceLoader::remove_custom_loaders() { - Vector<Ref<ResourceFormatLoader>> custom_loaders; for (int i = 0; i < loader_count; ++i) { if (loader[i]->get_script_instance()) { @@ -1134,7 +1076,6 @@ void ResourceLoader::initialize() { } void ResourceLoader::finalize() { - memdelete(thread_load_mutex); memdelete(thread_load_semaphore); } diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index b10c08d693..7d1c4b5d90 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -36,7 +36,6 @@ #include "core/resource.h" class ResourceFormatLoader : public Reference { - GDCLASS(ResourceFormatLoader, Reference); protected: @@ -67,7 +66,6 @@ typedef Error (*ResourceLoaderImport)(const String &p_path); typedef void (*ResourceLoadedCallback)(RES p_resource, const String &p_path); class ResourceLoader { - enum { MAX_LOADERS = 64 }; diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 09128adb50..445f9d0c37 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -41,7 +41,6 @@ bool ResourceSaver::timestamp_on_save = false; ResourceSavedCallback ResourceSaver::save_callback = nullptr; Error ResourceFormatSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - if (get_script_instance() && get_script_instance()->has_method("save")) { return (Error)get_script_instance()->call("save", p_path, p_resource, p_flags).operator int64_t(); } @@ -50,7 +49,6 @@ Error ResourceFormatSaver::save(const String &p_path, const RES &p_resource, uin } bool ResourceFormatSaver::recognize(const RES &p_resource) const { - if (get_script_instance() && get_script_instance()->has_method("recognize")) { return get_script_instance()->call("recognize", p_resource); } @@ -59,7 +57,6 @@ bool ResourceFormatSaver::recognize(const RES &p_resource) const { } void ResourceFormatSaver::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { - if (get_script_instance() && get_script_instance()->has_method("get_recognized_extensions")) { PackedStringArray exts = get_script_instance()->call("get_recognized_extensions", p_resource); @@ -73,7 +70,6 @@ void ResourceFormatSaver::get_recognized_extensions(const RES &p_resource, List< } void ResourceFormatSaver::_bind_methods() { - { PropertyInfo arg0 = PropertyInfo(Variant::STRING, "path"); PropertyInfo arg1 = PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"); @@ -86,12 +82,10 @@ void ResourceFormatSaver::_bind_methods() { } Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - String extension = p_path.get_extension(); Error err = ERR_FILE_UNRECOGNIZED; for (int i = 0; i < saver_count; i++) { - if (!saver[i]->recognize(p_resource)) continue; @@ -100,7 +94,6 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t saver[i]->get_recognized_extensions(p_resource, &extensions); for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - if (E->get().nocasecmp_to(extension) == 0) recognized = true; } @@ -119,7 +112,6 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t err = saver[i]->save(p_path, p_resource, p_flags); if (err == OK) { - #ifdef TOOLS_ENABLED ((Resource *)p_resource.ptr())->set_edited(false); @@ -144,20 +136,16 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t } void ResourceSaver::set_save_callback(ResourceSavedCallback p_callback) { - save_callback = p_callback; } void ResourceSaver::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) { - for (int i = 0; i < saver_count; i++) { - saver[i]->get_recognized_extensions(p_resource, p_extensions); } } void ResourceSaver::add_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver, bool p_at_front) { - ERR_FAIL_COND_MSG(p_format_saver.is_null(), "It's not a reference to a valid ResourceFormatSaver object."); ERR_FAIL_COND(saver_count >= MAX_SAVERS); @@ -173,7 +161,6 @@ void ResourceSaver::add_resource_format_saver(Ref<ResourceFormatSaver> p_format_ } void ResourceSaver::remove_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver) { - ERR_FAIL_COND_MSG(p_format_saver.is_null(), "It's not a reference to a valid ResourceFormatSaver object."); // Find saver @@ -203,7 +190,6 @@ Ref<ResourceFormatSaver> ResourceSaver::_find_custom_resource_format_saver(Strin } bool ResourceSaver::add_custom_resource_format_saver(String script_path) { - if (_find_custom_resource_format_saver(script_path).is_valid()) return false; @@ -228,7 +214,6 @@ bool ResourceSaver::add_custom_resource_format_saver(String script_path) { } void ResourceSaver::remove_custom_resource_format_saver(String script_path) { - Ref<ResourceFormatSaver> custom_saver = _find_custom_resource_format_saver(script_path); if (custom_saver.is_valid()) remove_resource_format_saver(custom_saver); @@ -243,7 +228,6 @@ void ResourceSaver::add_custom_savers() { ScriptServer::get_global_class_list(&global_classes); for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) { - StringName class_name = E->get(); StringName base_class = ScriptServer::get_global_class_native_base(class_name); @@ -255,7 +239,6 @@ void ResourceSaver::add_custom_savers() { } void ResourceSaver::remove_custom_savers() { - Vector<Ref<ResourceFormatSaver>> custom_savers; for (int i = 0; i < saver_count; ++i) { if (saver[i]->get_script_instance()) { diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h index 2ddebf0581..8b4cdd86f8 100644 --- a/core/io/resource_saver.h +++ b/core/io/resource_saver.h @@ -50,7 +50,6 @@ public: typedef void (*ResourceSavedCallback)(Ref<Resource> p_resource, const String &p_path); class ResourceSaver { - enum { MAX_SAVERS = 64 }; diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp index 9bbe92096d..2e63adcae9 100644 --- a/core/io/stream_peer.cpp +++ b/core/io/stream_peer.cpp @@ -33,7 +33,6 @@ #include "core/io/marshalls.h" Error StreamPeer::_put_data(const Vector<uint8_t> &p_data) { - int len = p_data.size(); if (len == 0) return OK; @@ -42,7 +41,6 @@ Error StreamPeer::_put_data(const Vector<uint8_t> &p_data) { } Array StreamPeer::_put_partial_data(const Vector<uint8_t> &p_data) { - Array ret; int len = p_data.size(); @@ -65,13 +63,11 @@ Array StreamPeer::_put_partial_data(const Vector<uint8_t> &p_data) { } Array StreamPeer::_get_data(int p_bytes) { - Array ret; Vector<uint8_t> data; data.resize(p_bytes); if (data.size() != p_bytes) { - ret.push_back(ERR_OUT_OF_MEMORY); ret.push_back(Vector<uint8_t>()); return ret; @@ -86,13 +82,11 @@ Array StreamPeer::_get_data(int p_bytes) { } Array StreamPeer::_get_partial_data(int p_bytes) { - Array ret; Vector<uint8_t> data; data.resize(p_bytes); if (data.size() != p_bytes) { - ret.push_back(ERR_OUT_OF_MEMORY); ret.push_back(Vector<uint8_t>()); return ret; @@ -105,7 +99,6 @@ Array StreamPeer::_get_partial_data(int p_bytes) { if (err != OK) { data.resize(0); } else if (received != data.size()) { - data.resize(received); } @@ -115,12 +108,10 @@ Array StreamPeer::_get_partial_data(int p_bytes) { } void StreamPeer::set_big_endian(bool p_enable) { - big_endian = p_enable; } bool StreamPeer::is_big_endian_enabled() const { - return big_endian; } @@ -129,11 +120,9 @@ void StreamPeer::put_u8(uint8_t p_val) { } void StreamPeer::put_8(int8_t p_val) { - put_data((const uint8_t *)&p_val, 1); } void StreamPeer::put_u16(uint16_t p_val) { - if (big_endian) { p_val = BSWAP16(p_val); } @@ -142,7 +131,6 @@ void StreamPeer::put_u16(uint16_t p_val) { put_data(buf, 2); } void StreamPeer::put_16(int16_t p_val) { - if (big_endian) { p_val = BSWAP16(p_val); } @@ -151,7 +139,6 @@ void StreamPeer::put_16(int16_t p_val) { put_data(buf, 2); } void StreamPeer::put_u32(uint32_t p_val) { - if (big_endian) { p_val = BSWAP32(p_val); } @@ -160,7 +147,6 @@ void StreamPeer::put_u32(uint32_t p_val) { put_data(buf, 4); } void StreamPeer::put_32(int32_t p_val) { - if (big_endian) { p_val = BSWAP32(p_val); } @@ -169,7 +155,6 @@ void StreamPeer::put_32(int32_t p_val) { put_data(buf, 4); } void StreamPeer::put_u64(uint64_t p_val) { - if (big_endian) { p_val = BSWAP64(p_val); } @@ -178,7 +163,6 @@ void StreamPeer::put_u64(uint64_t p_val) { put_data(buf, 8); } void StreamPeer::put_64(int64_t p_val) { - if (big_endian) { p_val = BSWAP64(p_val); } @@ -187,7 +171,6 @@ void StreamPeer::put_64(int64_t p_val) { put_data(buf, 8); } void StreamPeer::put_float(float p_val) { - uint8_t buf[4]; encode_float(p_val, buf); @@ -199,7 +182,6 @@ void StreamPeer::put_float(float p_val) { put_data(buf, 4); } void StreamPeer::put_double(double p_val) { - uint8_t buf[8]; encode_double(p_val, buf); if (big_endian) { @@ -209,19 +191,16 @@ void StreamPeer::put_double(double p_val) { put_data(buf, 8); } void StreamPeer::put_string(const String &p_string) { - CharString cs = p_string.ascii(); put_u32(cs.length()); put_data((const uint8_t *)cs.get_data(), cs.length()); } void StreamPeer::put_utf8_string(const String &p_string) { - CharString cs = p_string.utf8(); put_u32(cs.length()); put_data((const uint8_t *)cs.get_data(), cs.length()); } void StreamPeer::put_var(const Variant &p_variant, bool p_full_objects) { - int len = 0; Vector<uint8_t> buf; encode_variant(p_variant, nullptr, len, p_full_objects); @@ -232,19 +211,16 @@ void StreamPeer::put_var(const Variant &p_variant, bool p_full_objects) { } uint8_t StreamPeer::get_u8() { - uint8_t buf[1]; get_data(buf, 1); return buf[0]; } int8_t StreamPeer::get_8() { - uint8_t buf[1]; get_data(buf, 1); return buf[0]; } uint16_t StreamPeer::get_u16() { - uint8_t buf[2]; get_data(buf, 2); uint16_t r = decode_uint16(buf); @@ -254,7 +230,6 @@ uint16_t StreamPeer::get_u16() { return r; } int16_t StreamPeer::get_16() { - uint8_t buf[2]; get_data(buf, 2); uint16_t r = decode_uint16(buf); @@ -264,7 +239,6 @@ int16_t StreamPeer::get_16() { return r; } uint32_t StreamPeer::get_u32() { - uint8_t buf[4]; get_data(buf, 4); uint32_t r = decode_uint32(buf); @@ -274,7 +248,6 @@ uint32_t StreamPeer::get_u32() { return r; } int32_t StreamPeer::get_32() { - uint8_t buf[4]; get_data(buf, 4); uint32_t r = decode_uint32(buf); @@ -284,7 +257,6 @@ int32_t StreamPeer::get_32() { return r; } uint64_t StreamPeer::get_u64() { - uint8_t buf[8]; get_data(buf, 8); uint64_t r = decode_uint64(buf); @@ -294,7 +266,6 @@ uint64_t StreamPeer::get_u64() { return r; } int64_t StreamPeer::get_64() { - uint8_t buf[8]; get_data(buf, 8); uint64_t r = decode_uint64(buf); @@ -304,7 +275,6 @@ int64_t StreamPeer::get_64() { return r; } float StreamPeer::get_float() { - uint8_t buf[4]; get_data(buf, 4); @@ -317,7 +287,6 @@ float StreamPeer::get_float() { } double StreamPeer::get_double() { - uint8_t buf[8]; get_data(buf, 8); @@ -329,7 +298,6 @@ double StreamPeer::get_double() { return decode_double(buf); } String StreamPeer::get_string(int p_bytes) { - if (p_bytes < 0) p_bytes = get_u32(); ERR_FAIL_COND_V(p_bytes < 0, String()); @@ -343,7 +311,6 @@ String StreamPeer::get_string(int p_bytes) { return buf.ptr(); } String StreamPeer::get_utf8_string(int p_bytes) { - if (p_bytes < 0) p_bytes = get_u32(); ERR_FAIL_COND_V(p_bytes < 0, String()); @@ -359,7 +326,6 @@ String StreamPeer::get_utf8_string(int p_bytes) { return ret; } Variant StreamPeer::get_var(bool p_allow_objects) { - int len = get_32(); Vector<uint8_t> var; Error err = var.resize(len); @@ -375,7 +341,6 @@ Variant StreamPeer::get_var(bool p_allow_objects) { } void StreamPeer::_bind_methods() { - ClassDB::bind_method(D_METHOD("put_data", "data"), &StreamPeer::_put_data); ClassDB::bind_method(D_METHOD("put_partial_data", "data"), &StreamPeer::_put_partial_data); @@ -420,7 +385,6 @@ void StreamPeer::_bind_methods() { //////////////////////////////// void StreamPeerBuffer::_bind_methods() { - 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_position"), &StreamPeerBuffer::get_position); @@ -434,7 +398,6 @@ void StreamPeerBuffer::_bind_methods() { } Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) { - if (p_bytes <= 0) return OK; @@ -450,13 +413,11 @@ Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) { } Error StreamPeerBuffer::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) { - r_sent = p_bytes; return put_data(p_data, p_bytes); } Error StreamPeerBuffer::get_data(uint8_t *p_buffer, int p_bytes) { - int recv; get_partial_data(p_buffer, p_bytes, recv); if (recv != p_bytes) @@ -466,7 +427,6 @@ Error StreamPeerBuffer::get_data(uint8_t *p_buffer, int p_bytes) { } Error StreamPeerBuffer::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) { - if (pointer + p_bytes > data.size()) { r_received = data.size() - pointer; if (r_received <= 0) { @@ -487,50 +447,41 @@ Error StreamPeerBuffer::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_ } int StreamPeerBuffer::get_available_bytes() const { - return data.size() - pointer; } void StreamPeerBuffer::seek(int p_pos) { - ERR_FAIL_COND(p_pos < 0); ERR_FAIL_COND(p_pos > data.size()); pointer = p_pos; } int StreamPeerBuffer::get_size() const { - return data.size(); } int StreamPeerBuffer::get_position() const { - return pointer; } void StreamPeerBuffer::resize(int p_size) { - data.resize(p_size); } void StreamPeerBuffer::set_data_array(const Vector<uint8_t> &p_data) { - data = p_data; pointer = 0; } Vector<uint8_t> StreamPeerBuffer::get_data_array() const { - return data; } void StreamPeerBuffer::clear() { - data.resize(0); pointer = 0; } Ref<StreamPeerBuffer> StreamPeerBuffer::duplicate() const { - Ref<StreamPeerBuffer> spb; spb.instance(); spb->data = data; diff --git a/core/io/stream_peer.h b/core/io/stream_peer.h index a390fdc325..ec0b989ed8 100644 --- a/core/io/stream_peer.h +++ b/core/io/stream_peer.h @@ -93,7 +93,6 @@ public: }; class StreamPeerBuffer : public StreamPeer { - GDCLASS(StreamPeerBuffer, StreamPeer); Vector<uint8_t> data; diff --git a/core/io/stream_peer_ssl.cpp b/core/io/stream_peer_ssl.cpp index 1d86c35578..92c775a565 100644 --- a/core/io/stream_peer_ssl.cpp +++ b/core/io/stream_peer_ssl.cpp @@ -35,7 +35,6 @@ StreamPeerSSL *(*StreamPeerSSL::_create)() = nullptr; StreamPeerSSL *StreamPeerSSL::create() { - if (_create) return _create(); return nullptr; @@ -56,7 +55,6 @@ bool StreamPeerSSL::is_blocking_handshake_enabled() const { } void StreamPeerSSL::_bind_methods() { - ClassDB::bind_method(D_METHOD("poll"), &StreamPeerSSL::poll); ClassDB::bind_method(D_METHOD("accept_stream", "stream", "private_key", "certificate", "chain"), &StreamPeerSSL::accept_stream, DEFVAL(Ref<X509Certificate>())); ClassDB::bind_method(D_METHOD("connect_to_stream", "stream", "validate_certs", "for_hostname", "valid_certificate"), &StreamPeerSSL::connect_to_stream, DEFVAL(false), DEFVAL(String()), DEFVAL(Ref<X509Certificate>())); diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index 6218b98758..fd7ffa8458 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -33,7 +33,6 @@ #include "core/project_settings.h" Error StreamPeerTCP::_poll_connection() { - ERR_FAIL_COND_V(status != STATUS_CONNECTING || !_sock.is_valid() || !_sock->is_open(), FAILED); Error err = _sock->connect_to_host(peer_host, peer_port); @@ -58,7 +57,6 @@ Error StreamPeerTCP::_poll_connection() { } void StreamPeerTCP::accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint16_t p_port) { - _sock = p_sock; _sock->set_blocking_enabled(false); @@ -70,7 +68,6 @@ void StreamPeerTCP::accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint } Error StreamPeerTCP::connect_to_host(const IP_Address &p_host, uint16_t p_port) { - ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_host.is_valid(), ERR_INVALID_PARAMETER); @@ -103,18 +100,14 @@ Error StreamPeerTCP::connect_to_host(const IP_Address &p_host, uint16_t p_port) } Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool p_block) { - ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); if (status == STATUS_NONE || status == STATUS_ERROR) { - return FAILED; } if (status != STATUS_CONNECTED) { - if (_poll_connection() != OK) { - return FAILED; } @@ -133,12 +126,10 @@ Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool int total_sent = 0; while (data_to_send) { - int sent_amount = 0; err = _sock->send(offset, data_to_send, sent_amount); if (err != OK) { - if (err != ERR_BUSY) { disconnect_from_host(); return FAILED; @@ -156,7 +147,6 @@ Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool return FAILED; } } else { - data_to_send -= sent_amount; offset += sent_amount; total_sent += sent_amount; @@ -169,16 +159,12 @@ Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool } Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool p_block) { - if (!is_connected_to_host()) { - return FAILED; } if (status == STATUS_CONNECTING) { - if (_poll_connection() != OK) { - return FAILED; } @@ -194,12 +180,10 @@ Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool r_received = 0; while (to_read) { - int read = 0; err = _sock->recv(p_buffer + total_read, to_read, read); if (err != OK) { - if (err != ERR_BUSY) { disconnect_from_host(); return FAILED; @@ -218,13 +202,11 @@ Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool } } else if (read == 0) { - disconnect_from_host(); r_received = total_read; return ERR_FILE_EOF; } else { - to_read -= read; total_read += read; @@ -241,18 +223,15 @@ Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool } void StreamPeerTCP::set_no_delay(bool p_enabled) { - ERR_FAIL_COND(!is_connected_to_host()); _sock->set_tcp_no_delay_enabled(p_enabled); } bool StreamPeerTCP::is_connected_to_host() const { - return _sock.is_valid() && _sock->is_open() && (status == STATUS_CONNECTED || status == STATUS_CONNECTING); } StreamPeerTCP::Status StreamPeerTCP::get_status() { - if (status == STATUS_CONNECTING) { _poll_connection(); } else if (status == STATUS_CONNECTED) { @@ -278,7 +257,6 @@ StreamPeerTCP::Status StreamPeerTCP::get_status() { } void StreamPeerTCP::disconnect_from_host() { - if (_sock.is_valid() && _sock->is_open()) _sock->close(); @@ -294,45 +272,37 @@ Error StreamPeerTCP::poll(NetSocket::PollType p_type, int timeout) { } Error StreamPeerTCP::put_data(const uint8_t *p_data, int p_bytes) { - int total; return write(p_data, p_bytes, total, true); } Error StreamPeerTCP::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) { - return write(p_data, p_bytes, r_sent, false); } Error StreamPeerTCP::get_data(uint8_t *p_buffer, int p_bytes) { - int total; return read(p_buffer, p_bytes, total, true); } Error StreamPeerTCP::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) { - return read(p_buffer, p_bytes, r_received, false); } int StreamPeerTCP::get_available_bytes() const { - ERR_FAIL_COND_V(!_sock.is_valid(), -1); return _sock->get_available_bytes(); } IP_Address StreamPeerTCP::get_connected_host() const { - return peer_host; } uint16_t StreamPeerTCP::get_connected_port() const { - return peer_port; } Error StreamPeerTCP::_connect(const String &p_address, int p_port) { - IP_Address ip; if (p_address.is_valid_ip_address()) { ip = p_address; @@ -346,7 +316,6 @@ Error StreamPeerTCP::_connect(const String &p_address, int p_port) { } void StreamPeerTCP::_bind_methods() { - ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port"), &StreamPeerTCP::_connect); ClassDB::bind_method(D_METHOD("is_connected_to_host"), &StreamPeerTCP::is_connected_to_host); ClassDB::bind_method(D_METHOD("get_status"), &StreamPeerTCP::get_status); @@ -366,6 +335,5 @@ StreamPeerTCP::StreamPeerTCP() : } StreamPeerTCP::~StreamPeerTCP() { - disconnect_from_host(); } diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h index 571f6b7c54..ab98d494d6 100644 --- a/core/io/stream_peer_tcp.h +++ b/core/io/stream_peer_tcp.h @@ -37,7 +37,6 @@ #include "core/io/stream_peer.h" class StreamPeerTCP : public StreamPeer { - GDCLASS(StreamPeerTCP, StreamPeer); OBJ_CATEGORY("Networking"); diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index 69c2ba7943..706c650d7e 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -31,7 +31,6 @@ #include "tcp_server.h" void TCP_Server::_bind_methods() { - ClassDB::bind_method(D_METHOD("listen", "port", "bind_address"), &TCP_Server::listen, DEFVAL("*")); ClassDB::bind_method(D_METHOD("is_connection_available"), &TCP_Server::is_connection_available); ClassDB::bind_method(D_METHOD("is_listening"), &TCP_Server::is_listening); @@ -40,7 +39,6 @@ void TCP_Server::_bind_methods() { } Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) { - ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); @@ -62,7 +60,6 @@ Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) { err = _sock->bind(p_bind_address, p_port); if (err != OK) { - _sock->close(); return ERR_ALREADY_IN_USE; } @@ -83,7 +80,6 @@ bool TCP_Server::is_listening() const { } bool TCP_Server::is_connection_available() const { - ERR_FAIL_COND_V(!_sock.is_valid(), false); if (!_sock->is_open()) @@ -94,7 +90,6 @@ bool TCP_Server::is_connection_available() const { } Ref<StreamPeerTCP> TCP_Server::take_connection() { - Ref<StreamPeerTCP> conn; if (!is_connection_available()) { return conn; @@ -113,7 +108,6 @@ Ref<StreamPeerTCP> TCP_Server::take_connection() { } void TCP_Server::stop() { - if (_sock.is_valid()) { _sock->close(); } @@ -124,6 +118,5 @@ TCP_Server::TCP_Server() : } TCP_Server::~TCP_Server() { - stop(); } diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h index ca52b13ba1..eb715a745c 100644 --- a/core/io/tcp_server.h +++ b/core/io/tcp_server.h @@ -37,7 +37,6 @@ #include "core/io/stream_peer_tcp.h" class TCP_Server : public Reference { - GDCLASS(TCP_Server, Reference); protected: diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp index 6f79e2554b..b47e634a5a 100644 --- a/core/io/translation_loader_po.cpp +++ b/core/io/translation_loader_po.cpp @@ -34,7 +34,6 @@ #include "core/translation.h" RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { - enum Status { STATUS_NONE, @@ -58,13 +57,11 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { bool is_eof = false; while (!is_eof) { - String l = f->get_line().strip_edges(); is_eof = f->eof_reached(); // If we reached last line and it's not a content line, break, otherwise let processing that last loop if (is_eof && l.empty()) { - if (status == STATUS_READING_ID) { memdelete(f); ERR_FAIL_V_MSG(RES(), f->get_path() + ":" + itos(line) + " Unexpected EOF while reading 'msgid' at file: "); @@ -74,9 +71,7 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { } if (l.begins_with("msgid")) { - if (status == STATUS_READING_ID) { - memdelete(f); ERR_FAIL_V_MSG(RES(), f->get_path() + ":" + itos(line) + " Unexpected 'msgid', was expecting 'msgstr' while parsing: "); } @@ -96,9 +91,7 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { } if (l.begins_with("msgstr")) { - if (status != STATUS_READING_ID) { - memdelete(f); ERR_FAIL_V_MSG(RES(), f->get_path() + ":" + itos(line) + " Unexpected 'msgstr', was expecting 'msgid' while parsing: "); } @@ -154,7 +147,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { memdelete(f); if (status == STATUS_READING_STRING) { - if (msg_id != "") { if (!skip_this) translation->add_message(msg_id, msg_str); @@ -166,7 +158,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { Vector<String> configs = config.split("\n"); for (int i = 0; i < configs.size(); i++) { - String c = configs[i].strip_edges(); int p = c.find(":"); if (p == -1) @@ -186,7 +177,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { } RES TranslationLoaderPO::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) *r_error = ERR_CANT_OPEN; @@ -197,17 +187,14 @@ RES TranslationLoaderPO::load(const String &p_path, const String &p_original_pat } void TranslationLoaderPO::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("po"); //p_extensions->push_back("mo"); //mo in the future... } bool TranslationLoaderPO::handles_type(const String &p_type) const { - return (p_type == "Translation"); } String TranslationLoaderPO::get_resource_type(const String &p_path) const { - if (p_path.get_extension().to_lower() == "po") return "Translation"; return ""; diff --git a/core/io/udp_server.cpp b/core/io/udp_server.cpp index 16b7863cdd..40180dcb09 100644 --- a/core/io/udp_server.cpp +++ b/core/io/udp_server.cpp @@ -31,7 +31,6 @@ #include "udp_server.h" void UDPServer::_bind_methods() { - ClassDB::bind_method(D_METHOD("listen", "port", "bind_address"), &UDPServer::listen, DEFVAL("*")); ClassDB::bind_method(D_METHOD("is_connection_available"), &UDPServer::is_connection_available); ClassDB::bind_method(D_METHOD("is_listening"), &UDPServer::is_listening); @@ -40,7 +39,6 @@ void UDPServer::_bind_methods() { } Error UDPServer::listen(uint16_t p_port, const IP_Address &p_bind_address) { - ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); @@ -76,7 +74,6 @@ bool UDPServer::is_listening() const { } bool UDPServer::is_connection_available() const { - ERR_FAIL_COND_V(!_sock.is_valid(), false); if (!_sock->is_open()) @@ -87,7 +84,6 @@ bool UDPServer::is_connection_available() const { } Ref<PacketPeerUDP> UDPServer::take_connection() { - Ref<PacketPeerUDP> conn; if (!is_connection_available()) { return conn; @@ -101,7 +97,6 @@ Ref<PacketPeerUDP> UDPServer::take_connection() { } void UDPServer::stop() { - if (_sock.is_valid()) { _sock->close(); } @@ -114,6 +109,5 @@ UDPServer::UDPServer() : } UDPServer::~UDPServer() { - stop(); } diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp index a4b64bf17c..2926f4c92a 100644 --- a/core/io/xml_parser.cpp +++ b/core/io/xml_parser.cpp @@ -48,7 +48,6 @@ static bool _equalsn(const CharType *str1, const CharType *str2, int len) { } String XMLParser::_replace_special_characters(const String &origstr) { - int pos = origstr.find("&"); int oldPos = 0; @@ -148,7 +147,6 @@ void XMLParser::_ignore_definition() { } bool XMLParser::_parse_cdata() { - if (*(P + 1) != '[') return false; @@ -190,7 +188,6 @@ bool XMLParser::_parse_cdata() { } void XMLParser::_parse_comment() { - node_type = NODE_COMMENT; P += 1; @@ -217,7 +214,6 @@ void XMLParser::_parse_comment() { } void XMLParser::_parse_opening_xml_element() { - node_type = NODE_ELEMENT; node_empty = false; attributes.clear(); @@ -304,7 +300,6 @@ void XMLParser::_parse_opening_xml_element() { } void XMLParser::_parse_current_node() { - char *start = P; node_offset = P - data; @@ -342,12 +337,10 @@ void XMLParser::_parse_current_node() { } uint64_t XMLParser::get_node_offset() const { - return node_offset; }; Error XMLParser::seek(uint64_t p_pos) { - ERR_FAIL_COND_V(!data, ERR_FILE_EOF); ERR_FAIL_COND_V(p_pos >= length, ERR_FILE_EOF); @@ -357,7 +350,6 @@ Error XMLParser::seek(uint64_t p_pos) { }; void XMLParser::_bind_methods() { - ClassDB::bind_method(D_METHOD("read"), &XMLParser::read); ClassDB::bind_method(D_METHOD("get_node_type"), &XMLParser::get_node_type); ClassDB::bind_method(D_METHOD("get_node_name"), &XMLParser::get_node_name); @@ -386,7 +378,6 @@ void XMLParser::_bind_methods() { }; Error XMLParser::read() { - // if not end reached, parse the node if (P && (P - data) < (int64_t)length - 1 && *P != 0) { _parse_current_node(); @@ -397,11 +388,9 @@ Error XMLParser::read() { } XMLParser::NodeType XMLParser::get_node_type() { - return node_type; } String XMLParser::get_node_data() const { - ERR_FAIL_COND_V(node_type != NODE_TEXT, ""); return node_name; } @@ -411,21 +400,17 @@ String XMLParser::get_node_name() const { return node_name; } int XMLParser::get_attribute_count() const { - return attributes.size(); } String XMLParser::get_attribute_name(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, attributes.size(), ""); return attributes[p_idx].name; } String XMLParser::get_attribute_value(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, attributes.size(), ""); return attributes[p_idx].value; } bool XMLParser::has_attribute(const String &p_name) const { - for (int i = 0; i < attributes.size(); i++) { if (attributes[i].name == p_name) return true; @@ -434,7 +419,6 @@ bool XMLParser::has_attribute(const String &p_name) const { return false; } String XMLParser::get_attribute_value(const String &p_name) const { - int idx = -1; for (int i = 0; i < attributes.size(); i++) { if (attributes[i].name == p_name) { @@ -449,7 +433,6 @@ String XMLParser::get_attribute_value(const String &p_name) const { } String XMLParser::get_attribute_value_safe(const String &p_name) const { - int idx = -1; for (int i = 0; i < attributes.size(); i++) { if (attributes[i].name == p_name) { @@ -463,12 +446,10 @@ String XMLParser::get_attribute_value_safe(const String &p_name) const { return attributes[idx].value; } bool XMLParser::is_empty() const { - return node_empty; } Error XMLParser::open_buffer(const Vector<uint8_t> &p_buffer) { - ERR_FAIL_COND_V(p_buffer.size() == 0, ERR_INVALID_DATA); if (data) { @@ -484,7 +465,6 @@ Error XMLParser::open_buffer(const Vector<uint8_t> &p_buffer) { } Error XMLParser::open(const String &p_path) { - Error err; FileAccess *file = FileAccess::open(p_path, FileAccess::READ, &err); @@ -508,7 +488,6 @@ Error XMLParser::open(const String &p_path) { } void XMLParser::skip_section() { - // skip if this element is empty anyway. if (is_empty()) return; @@ -526,7 +505,6 @@ void XMLParser::skip_section() { } void XMLParser::close() { - if (data) memdelete_arr(data); data = nullptr; @@ -538,7 +516,6 @@ void XMLParser::close() { } int XMLParser::get_current_line() const { - return 0; } @@ -550,7 +527,6 @@ XMLParser::XMLParser() { special_characters.push_back("'apos;"); } XMLParser::~XMLParser() { - if (data) memdelete_arr(data); } diff --git a/core/io/xml_parser.h b/core/io/xml_parser.h index 42b7d6e0d4..ee2174d52c 100644 --- a/core/io/xml_parser.h +++ b/core/io/xml_parser.h @@ -41,7 +41,6 @@ */ class XMLParser : public Reference { - GDCLASS(XMLParser, Reference); public: diff --git a/core/io/zip_io.cpp b/core/io/zip_io.cpp index 3a2a207d22..68dd633e70 100644 --- a/core/io/zip_io.cpp +++ b/core/io/zip_io.cpp @@ -33,7 +33,6 @@ #include "core/os/copymem.h" void *zipio_open(void *data, const char *p_fname, int mode) { - FileAccess *&f = *(FileAccess **)data; String fname; @@ -42,7 +41,6 @@ void *zipio_open(void *data, const char *p_fname, int mode) { if (mode & ZLIB_FILEFUNC_MODE_WRITE) { f = FileAccess::open(fname, FileAccess::WRITE); } else { - f = FileAccess::open(fname, FileAccess::READ); } @@ -53,31 +51,26 @@ void *zipio_open(void *data, const char *p_fname, int mode) { } uLong zipio_read(void *data, void *fdata, void *buf, uLong size) { - FileAccess *f = *(FileAccess **)data; return f->get_buffer((uint8_t *)buf, size); } uLong zipio_write(voidpf opaque, voidpf stream, const void *buf, uLong size) { - FileAccess *f = *(FileAccess **)opaque; f->store_buffer((uint8_t *)buf, size); return size; } long zipio_tell(voidpf opaque, voidpf stream) { - FileAccess *f = *(FileAccess **)opaque; return f->get_position(); } long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) { - FileAccess *f = *(FileAccess **)opaque; int pos = offset; switch (origin) { - case ZLIB_FILEFUNC_SEEK_CUR: pos = f->get_position() + offset; break; @@ -93,7 +86,6 @@ long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) { } int zipio_close(voidpf opaque, voidpf stream) { - FileAccess *&f = *(FileAccess **)opaque; if (f) { f->close(); @@ -104,25 +96,21 @@ int zipio_close(voidpf opaque, voidpf stream) { } int zipio_testerror(voidpf opaque, voidpf stream) { - FileAccess *f = *(FileAccess **)opaque; return (f && f->get_error() != OK) ? 1 : 0; } voidpf zipio_alloc(voidpf opaque, uInt items, uInt size) { - voidpf ptr = memalloc(items * size); zeromem(ptr, items * size); return ptr; } void zipio_free(voidpf opaque, voidpf address) { - memfree(address); } zlib_filefunc_def zipio_create_io_from_file(FileAccess **p_file) { - zlib_filefunc_def io; io.opaque = p_file; io.zopen_file = zipio_open; diff --git a/core/list.h b/core/list.h index 7fbf3e50fc..fc943790de 100644 --- a/core/list.h +++ b/core/list.h @@ -49,7 +49,6 @@ class List { public: class Element { - private: friend class List<T, A>; @@ -63,14 +62,12 @@ public: * Get NEXT Element iterator, for constant lists. */ _FORCE_INLINE_ const Element *next() const { - return next_ptr; }; /** * Get NEXT Element iterator, */ _FORCE_INLINE_ Element *next() { - return next_ptr; }; @@ -78,14 +75,12 @@ public: * Get PREV Element iterator, for constant lists. */ _FORCE_INLINE_ const Element *prev() const { - return prev_ptr; }; /** * Get PREV Element iterator, */ _FORCE_INLINE_ Element *prev() { - return prev_ptr; }; @@ -99,7 +94,6 @@ public: * operator->, for using as iterator->, when iterators are defined on stack, for constant lists. */ _FORCE_INLINE_ const T *operator->() const { - return &value; }; /** @@ -135,7 +129,6 @@ public: }; void erase() { - data->erase(this); } @@ -144,13 +137,11 @@ public: private: struct _Data { - Element *first; Element *last; int size_cache; bool erase(const Element *p_I) { - ERR_FAIL_COND_V(!p_I, false); ERR_FAIL_COND_V(p_I->data != this, false); @@ -181,7 +172,6 @@ public: * return a const iterator to the beginning of the list. */ _FORCE_INLINE_ const Element *front() const { - return _data ? _data->first : nullptr; }; @@ -196,7 +186,6 @@ public: * return a const iterator to the last member of the list. */ _FORCE_INLINE_ const Element *back() const { - return _data ? _data->last : nullptr; }; @@ -204,7 +193,6 @@ public: * return an iterator to the last member of the list. */ _FORCE_INLINE_ Element *back() { - return _data ? _data->last : nullptr; }; @@ -212,9 +200,7 @@ public: * store a new element at the end of the list */ Element *push_back(const T &value) { - if (!_data) { - _data = memnew_allocator(_Data, A); _data->first = nullptr; _data->last = nullptr; @@ -229,7 +215,6 @@ public: n->data = _data; if (_data->last) { - _data->last->next_ptr = n; } @@ -244,7 +229,6 @@ public: }; void pop_back() { - if (_data && _data->last) erase(_data->last); } @@ -253,9 +237,7 @@ public: * store a new element at the beginning of the list */ Element *push_front(const T &value) { - if (!_data) { - _data = memnew_allocator(_Data, A); _data->first = nullptr; _data->last = nullptr; @@ -269,7 +251,6 @@ public: n->data = _data; if (_data->first) { - _data->first->prev_ptr = n; } @@ -284,7 +265,6 @@ public: }; void pop_front() { - if (_data && _data->first) erase(_data->first); } @@ -346,7 +326,6 @@ public: */ template <class T_v> Element *find(const T_v &p_val) { - Element *it = front(); while (it) { if (it->value == p_val) @@ -361,7 +340,6 @@ public: * erase an element in the list, by iterator pointing to it. Return true if it was found/erased. */ bool erase(const Element *p_I) { - if (_data) { bool ret = _data->erase(p_I); @@ -380,7 +358,6 @@ public: * erase the first element in the list, that contains value */ bool erase(const T &value) { - Element *I = find(value); return erase(I); }; @@ -389,7 +366,6 @@ public: * return whether the list is empty */ _FORCE_INLINE_ bool empty() const { - return (!_data || !_data->size_cache); } @@ -397,19 +373,16 @@ public: * clear the list */ void clear() { - while (front()) { erase(front()); }; }; _FORCE_INLINE_ int size() const { - return _data ? _data->size_cache : 0; } void swap(Element *p_A, Element *p_B) { - ERR_FAIL_COND(!p_A || !p_B); ERR_FAIL_COND(p_A->data != _data); ERR_FAIL_COND(p_B->data != _data); @@ -437,18 +410,15 @@ public: * copy the list */ void operator=(const List &p_list) { - clear(); const Element *it = p_list.front(); while (it) { - push_back(it->get()); it = it->next(); } } T &operator[](int p_index) { - CRASH_BAD_INDEX(p_index, size()); Element *I = front(); @@ -462,7 +432,6 @@ public: } const T &operator[](int p_index) const { - CRASH_BAD_INDEX(p_index, size()); const Element *I = front(); @@ -476,7 +445,6 @@ public: } void move_to_back(Element *p_I) { - ERR_FAIL_COND(p_I->data != _data); if (!p_I->next_ptr) return; @@ -500,12 +468,10 @@ public: } void invert() { - int s = size() / 2; Element *F = front(); Element *B = back(); for (int i = 0; i < s; i++) { - SWAP(F->value, B->value); F = F->next(); B = B->prev(); @@ -513,7 +479,6 @@ public: } void move_to_front(Element *p_I) { - ERR_FAIL_COND(p_I->data != _data); if (!p_I->prev_ptr) return; @@ -537,7 +502,6 @@ public: } void move_before(Element *value, Element *where) { - if (value->prev_ptr) { value->prev_ptr->next_ptr = value->next_ptr; } else { @@ -572,13 +536,11 @@ public: */ void sort() { - sort_custom<Comparator<T>>(); } template <class C> void sort_custom_inplace() { - if (size() < 2) return; @@ -587,18 +549,15 @@ public: Element *to = from; while (current) { - Element *next = current->next_ptr; if (from != current) { - current->prev_ptr = nullptr; current->next_ptr = from; Element *find = from; C less; while (find && less(find->value, current->value)) { - current->prev_ptr = find; current->next_ptr = find->next_ptr; find = find->next_ptr; @@ -614,7 +573,6 @@ public: else to = current; } else { - current->prev_ptr = nullptr; current->next_ptr = nullptr; } @@ -627,17 +585,14 @@ public: template <class C> struct AuxiliaryComparator { - C compare; _FORCE_INLINE_ bool operator()(const Element *a, const Element *b) const { - return compare(a->value, b->value); } }; template <class C> void sort_custom() { - //this version uses auxiliary memory for speed. //if you don't want to use auxiliary memory, use the in_place version @@ -649,7 +604,6 @@ public: int idx = 0; for (Element *E = front(); E; E = E->next_ptr) { - aux_buffer[idx] = E; idx++; } @@ -666,7 +620,6 @@ public: aux_buffer[s - 1]->next_ptr = nullptr; for (int i = 1; i < s - 1; i++) { - aux_buffer[i]->prev_ptr = aux_buffer[i - 1]; aux_buffer[i]->next_ptr = aux_buffer[i + 1]; } @@ -682,10 +635,8 @@ public: * copy constructor for the list */ List(const List &p_list) { - const Element *it = p_list.front(); while (it) { - push_back(it->get()); it = it->next(); } @@ -696,7 +647,6 @@ public: ~List() { clear(); if (_data) { - ERR_FAIL_COND(_data->size_cache); memdelete_allocator<_Data, A>(_data); } diff --git a/core/local_vector.h b/core/local_vector.h index 0b0ef6dfdc..e8b02fe661 100644 --- a/core/local_vector.h +++ b/core/local_vector.h @@ -81,7 +81,6 @@ public: } void invert() { - for (U i = 0; i < count / 2; i++) { SWAP(data[i], data[count - i - 1]); } @@ -108,9 +107,7 @@ public: _FORCE_INLINE_ U size() const { return count; } void resize(U p_size) { - if (p_size < count) { - if (!__has_trivial_destructor(T) && !force_trivial) { for (U i = p_size; i < count; i++) { data[i].~T(); @@ -118,7 +115,6 @@ public: } count = p_size; } else if (p_size > count) { - if (unlikely(p_size > capacity)) { if (capacity == 0) { capacity = 1; @@ -160,7 +156,6 @@ public: } int64_t find(const T &p_val, U p_from = 0) const { - for (U i = 0; i < count; i++) { if (data[i] == p_val) { return int64_t(i); @@ -171,7 +166,6 @@ public: template <class C> void sort_custom() { - U len = count; if (len == 0) return; @@ -181,15 +175,12 @@ public: } void sort() { - sort_custom<_DefaultComparator<T>>(); } void ordered_insert(T p_val) { - U i; for (i = 0; i < count; i++) { - if (p_val < data[i]) { break; }; @@ -236,7 +227,6 @@ public: } _FORCE_INLINE_ ~LocalVector() { - if (data) { reset(); } diff --git a/core/map.h b/core/map.h index 621b6c2842..f9321f90b3 100644 --- a/core/map.h +++ b/core/map.h @@ -39,7 +39,6 @@ template <class K, class V, class C = Comparator<K>, class A = DefaultAllocator> class Map { - enum Color { RED, BLACK @@ -48,7 +47,6 @@ class Map { public: class Element { - private: friend class Map<K, V, C, A>; int color = RED; @@ -63,19 +61,15 @@ public: public: const Element *next() const { - return _next; } Element *next() { - return _next; } const Element *prev() const { - return _prev; } Element *prev() { - return _prev; } const K &key() const { @@ -98,7 +92,6 @@ public: private: struct _Data { - Element *_root = nullptr; Element *_nil; int size_cache = 0; @@ -114,14 +107,12 @@ private: } void _create_root() { - _root = memnew_allocator(Element, A); _root->parent = _root->left = _root->right = _nil; _root->color = BLACK; } void _free_root() { - if (_root) { memdelete_allocator<Element, A>(_root); _root = nullptr; @@ -129,7 +120,6 @@ private: } ~_Data() { - _free_root(); #ifdef GLOBALNIL_DISABLED @@ -141,13 +131,11 @@ private: _Data _data; inline void _set_color(Element *p_node, int p_color) { - 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; p_node->right = r->left; if (r->left != _data._nil) @@ -163,7 +151,6 @@ private: } inline void _rotate_right(Element *p_node) { - Element *l = p_node->left; p_node->left = l->right; if (l->right != _data._nil) @@ -179,18 +166,15 @@ private: } inline Element *_successor(Element *p_node) const { - Element *node = p_node; if (node->right != _data._nil) { - node = node->right; while (node->left != _data._nil) { /* returns the minimum of the right subtree of node */ node = node->left; } return node; } else { - while (node == node->parent->right) { node = node->parent; } @@ -205,14 +189,12 @@ private: Element *node = p_node; if (node->left != _data._nil) { - node = node->left; while (node->right != _data._nil) { /* returns the minimum of the left subtree of node */ node = node->right; } return node; } else { - while (node == node->parent->left) { node = node->parent; } @@ -224,7 +206,6 @@ private: } Element *_find(const K &p_key) const { - Element *node = _data._root->left; C less; @@ -241,7 +222,6 @@ private: } Element *_find_closest(const K &p_key) const { - Element *node = _data._root->left; Element *prev = nullptr; C less; @@ -267,7 +247,6 @@ private: } void _insert_rb_fix(Element *p_new_node) { - Element *node = p_new_node; Element *nparent = node->parent; Element *ngrand_parent; @@ -316,13 +295,11 @@ private: } Element *_insert(const K &p_key, const V &p_value) { - Element *new_parent = _data._root; Element *node = _data._root->left; C less; while (node != _data._nil) { - new_parent = node; if (less(p_key, node->_key)) @@ -362,7 +339,6 @@ private: } void _erase_fix_rb(Element *p_node) { - Element *root = _data._root->left; Element *node = _data._nil; Element *sibling = p_node; @@ -424,7 +400,6 @@ private: } void _erase(Element *p_node) { - 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; @@ -445,7 +420,6 @@ private: } if (rp != p_node) { - ERR_FAIL_COND(rp == _data._nil); rp->left = p_node->left; @@ -475,7 +449,6 @@ private: } void _calculate_depth(Element *p_element, int &max_d, int d) const { - if (p_element == _data._nil) return; @@ -487,7 +460,6 @@ private: } void _cleanup_tree(Element *p_element) { - if (p_element == _data._nil) return; @@ -497,18 +469,15 @@ private: } void _copy_from(const Map &p_map) { - clear(); // not the fastest way, but safeset to write. for (Element *I = p_map.front(); I; I = I->next()) { - insert(I->key(), I->value()); } } public: const Element *find(const K &p_key) const { - if (!_data._root) return nullptr; @@ -517,7 +486,6 @@ public: } Element *find(const K &p_key) { - if (!_data._root) return nullptr; @@ -526,7 +494,6 @@ public: } const Element *find_closest(const K &p_key) const { - if (!_data._root) return nullptr; @@ -535,7 +502,6 @@ public: } Element *find_closest(const K &p_key) { - if (!_data._root) return nullptr; @@ -544,19 +510,16 @@ public: } bool has(const K &p_key) const { - return find(p_key) != nullptr; } Element *insert(const K &p_key, const V &p_value) { - if (!_data._root) _data._create_root(); return _insert(p_key, p_value); } void erase(Element *p_element) { - if (!_data._root || !p_element) return; @@ -566,7 +529,6 @@ public: } bool erase(const K &p_key) { - if (!_data._root) return false; @@ -581,7 +543,6 @@ public: } const V &operator[](const K &p_key) const { - CRASH_COND(!_data._root); const Element *e = find(p_key); CRASH_COND(!e); @@ -589,7 +550,6 @@ public: } V &operator[](const K &p_key) { - if (!_data._root) _data._create_root(); @@ -601,7 +561,6 @@ public: } Element *front() const { - if (!_data._root) return nullptr; @@ -616,7 +575,6 @@ public: } Element *back() const { - if (!_data._root) return nullptr; @@ -644,7 +602,6 @@ public: } void clear() { - if (!_data._root) return; @@ -655,19 +612,16 @@ public: } void operator=(const Map &p_map) { - _copy_from(p_map); } Map(const Map &p_map) { - _copy_from(p_map); } _FORCE_INLINE_ Map() {} ~Map() { - clear(); } }; diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index d6d6101402..a85a0e9db9 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -35,7 +35,6 @@ #include "scene/scene_string_names.h" int AStar::get_available_point_id() const { - if (points.empty()) { return 1; } @@ -54,7 +53,6 @@ int AStar::get_available_point_id() const { } void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) { - ERR_FAIL_COND(p_id < 0); ERR_FAIL_COND(p_weight_scale < 1); @@ -78,7 +76,6 @@ void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) { } Vector3 AStar::get_point_position(int p_id) const { - Point *p; bool p_exists = points.lookup(p_id, p); ERR_FAIL_COND_V(!p_exists, Vector3()); @@ -87,7 +84,6 @@ Vector3 AStar::get_point_position(int p_id) const { } void AStar::set_point_position(int p_id, const Vector3 &p_pos) { - Point *p; bool p_exists = points.lookup(p_id, p); ERR_FAIL_COND(!p_exists); @@ -96,7 +92,6 @@ void AStar::set_point_position(int p_id, const Vector3 &p_pos) { } real_t AStar::get_point_weight_scale(int p_id) const { - Point *p; bool p_exists = points.lookup(p_id, p); ERR_FAIL_COND_V(!p_exists, 0); @@ -105,7 +100,6 @@ real_t AStar::get_point_weight_scale(int p_id) const { } void AStar::set_point_weight_scale(int p_id, real_t p_weight_scale) { - Point *p; bool p_exists = points.lookup(p_id, p); ERR_FAIL_COND(!p_exists); @@ -115,13 +109,11 @@ void AStar::set_point_weight_scale(int p_id, real_t p_weight_scale) { } void AStar::remove_point(int p_id) { - Point *p; bool p_exists = points.lookup(p_id, p); ERR_FAIL_COND(!p_exists); for (OAHashMap<int, Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) { - Segment s(p_id, (*it.key)); segments.erase(s); @@ -130,7 +122,6 @@ void AStar::remove_point(int p_id) { } for (OAHashMap<int, Point *>::Iterator it = p->unlinked_neighbours.iter(); it.valid; it = p->unlinked_neighbours.next_iter(it)) { - Segment s(p_id, (*it.key)); segments.erase(s); @@ -144,7 +135,6 @@ void AStar::remove_point(int p_id) { } void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) { - ERR_FAIL_COND(p_id == p_with_id); Point *a; @@ -182,7 +172,6 @@ void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) { } void AStar::disconnect_points(int p_id, int p_with_id, bool bidirectional) { - Point *a; bool a_exists = points.lookup(p_id, a); ERR_FAIL_COND(!a_exists); @@ -221,12 +210,10 @@ void AStar::disconnect_points(int p_id, int p_with_id, bool bidirectional) { } bool AStar::has_point(int p_id) const { - return points.has(p_id); } Array AStar::get_points() { - Array point_list; for (OAHashMap<int, Point *>::Iterator it = points.iter(); it.valid; it = points.next_iter(it)) { @@ -237,7 +224,6 @@ Array AStar::get_points() { } Vector<int> AStar::get_point_connections(int p_id) { - Point *p; bool p_exists = points.lookup(p_id, p); ERR_FAIL_COND_V(!p_exists, Vector<int>()); @@ -252,7 +238,6 @@ Vector<int> AStar::get_point_connections(int p_id) { } bool AStar::are_points_connected(int p_id, int p_with_id, bool bidirectional) const { - Segment s(p_id, p_with_id); const Set<Segment>::Element *element = segments.find(s); @@ -261,7 +246,6 @@ bool AStar::are_points_connected(int p_id, int p_with_id, bool bidirectional) co } void AStar::clear() { - last_free_id = 0; for (OAHashMap<int, Point *>::Iterator it = points.iter(); it.valid; it = points.next_iter(it)) { memdelete(*(it.value)); @@ -285,12 +269,10 @@ void AStar::reserve_space(int p_num_nodes) { } int AStar::get_closest_point(const Vector3 &p_point, bool p_include_disabled) const { - int closest_id = -1; real_t closest_dist = 1e20; for (OAHashMap<int, Point *>::Iterator it = points.iter(); it.valid; it = points.next_iter(it)) { - if (!p_include_disabled && !(*it.value)->enabled) continue; // Disabled points should not be considered. @@ -305,13 +287,11 @@ int AStar::get_closest_point(const Vector3 &p_point, bool p_include_disabled) co } Vector3 AStar::get_closest_position_in_segment(const Vector3 &p_point) const { - bool found = false; real_t closest_dist = 1e20; Vector3 closest_point; for (const Set<Segment>::Element *E = segments.front(); E; E = E->next()) { - Point *from_point = nullptr, *to_point = nullptr; points.lookup(E->get().u, from_point); points.lookup(E->get().v, to_point); @@ -328,7 +308,6 @@ Vector3 AStar::get_closest_position_in_segment(const Vector3 &p_point) const { Vector3 p = Geometry::get_closest_point_to_segment(p_point, segment); real_t d = p_point.distance_squared_to(p); if (!found || d < closest_dist) { - closest_point = p; closest_dist = d; found = true; @@ -339,7 +318,6 @@ Vector3 AStar::get_closest_position_in_segment(const Vector3 &p_point) const { } bool AStar::_solve(Point *begin_point, Point *end_point) { - pass++; if (!end_point->enabled) @@ -355,7 +333,6 @@ bool AStar::_solve(Point *begin_point, Point *end_point) { open_list.push_back(begin_point); while (!open_list.empty()) { - Point *p = open_list[0]; // The currently processed point if (p == end_point) { @@ -368,7 +345,6 @@ bool AStar::_solve(Point *begin_point, Point *end_point) { p->closed_pass = pass; // Mark the point as closed for (OAHashMap<int, Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) { - Point *e = *(it.value); // The neighbour point if (!e->enabled || e->closed_pass == pass) { @@ -403,7 +379,6 @@ bool AStar::_solve(Point *begin_point, Point *end_point) { } real_t AStar::_estimate_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost)) return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id); @@ -419,7 +394,6 @@ real_t AStar::_estimate_cost(int p_from_id, int p_to_id) { } real_t AStar::_compute_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost)) return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id); @@ -435,7 +409,6 @@ real_t AStar::_compute_cost(int p_from_id, int p_to_id) { } Vector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) { - Point *a; bool from_exists = points.lookup(p_from_id, a); ERR_FAIL_COND_V(!from_exists, Vector<Vector3>()); @@ -484,7 +457,6 @@ Vector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) { } Vector<int> AStar::get_id_path(int p_from_id, int p_to_id) { - Point *a; bool from_exists = points.lookup(p_from_id, a); ERR_FAIL_COND_V(!from_exists, Vector<int>()); @@ -533,7 +505,6 @@ Vector<int> AStar::get_id_path(int p_from_id, int p_to_id) { } void AStar::set_point_disabled(int p_id, bool p_disabled) { - Point *p; bool p_exists = points.lookup(p_id, p); ERR_FAIL_COND(!p_exists); @@ -542,7 +513,6 @@ void AStar::set_point_disabled(int p_id, bool p_disabled) { } bool AStar::is_point_disabled(int p_id) const { - Point *p; bool p_exists = points.lookup(p_id, p); ERR_FAIL_COND_V(!p_exists, false); @@ -551,7 +521,6 @@ bool AStar::is_point_disabled(int p_id) const { } 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", "position", "weight_scale"), &AStar::add_point, DEFVAL(1.0)); ClassDB::bind_method(D_METHOD("get_point_position", "id"), &AStar::get_point_position); @@ -678,7 +647,6 @@ Vector2 AStar2D::get_closest_position_in_segment(const Vector2 &p_point) const { } real_t AStar2D::_estimate_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost)) return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id); @@ -694,7 +662,6 @@ real_t AStar2D::_estimate_cost(int p_from_id, int p_to_id) { } real_t AStar2D::_compute_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost)) return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id); @@ -710,7 +677,6 @@ real_t AStar2D::_compute_cost(int p_from_id, int p_to_id) { } Vector<Vector2> AStar2D::get_point_path(int p_from_id, int p_to_id) { - AStar::Point *a; bool from_exists = astar.points.lookup(p_from_id, a); ERR_FAIL_COND_V(!from_exists, Vector<Vector2>()); @@ -759,7 +725,6 @@ Vector<Vector2> AStar2D::get_point_path(int p_from_id, int p_to_id) { } Vector<int> AStar2D::get_id_path(int p_from_id, int p_to_id) { - AStar::Point *a; bool from_exists = astar.points.lookup(p_from_id, a); ERR_FAIL_COND_V(!from_exists, Vector<int>()); @@ -808,7 +773,6 @@ Vector<int> AStar2D::get_id_path(int p_from_id, int p_to_id) { } bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) { - astar.pass++; if (!end_point->enabled) @@ -824,7 +788,6 @@ bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) { open_list.push_back(begin_point); while (!open_list.empty()) { - AStar::Point *p = open_list[0]; // The currently processed point if (p == end_point) { @@ -837,7 +800,6 @@ bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) { p->closed_pass = astar.pass; // Mark the point as closed for (OAHashMap<int, AStar::Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) { - AStar::Point *e = *(it.value); // The neighbour point if (!e->enabled || e->closed_pass == astar.pass) { @@ -872,7 +834,6 @@ bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) { } void AStar2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_available_point_id"), &AStar2D::get_available_point_id); ClassDB::bind_method(D_METHOD("add_point", "id", "position", "weight_scale"), &AStar2D::add_point, DEFVAL(1.0)); ClassDB::bind_method(D_METHOD("get_point_position", "id"), &AStar2D::get_point_position); diff --git a/core/math/a_star.h b/core/math/a_star.h index ffb437ee04..ba1c3033b8 100644 --- a/core/math/a_star.h +++ b/core/math/a_star.h @@ -41,12 +41,10 @@ */ class AStar : public Reference { - GDCLASS(AStar, Reference); friend class AStar2D; struct Point { - Point() {} int id; diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp index 19d60fea72..588ee84f58 100644 --- a/core/math/aabb.cpp +++ b/core/math/aabb.cpp @@ -33,21 +33,17 @@ #include "core/print_string.h" real_t AABB::get_area() const { - return size.x * size.y * size.z; } bool AABB::operator==(const AABB &p_rval) const { - return ((position == p_rval.position) && (size == p_rval.size)); } bool AABB::operator!=(const AABB &p_rval) const { - return ((position != p_rval.position) || (size != p_rval.size)); } void AABB::merge_with(const AABB &p_aabb) { - Vector3 beg_1, beg_2; Vector3 end_1, end_2; Vector3 min, max; @@ -70,12 +66,10 @@ void AABB::merge_with(const AABB &p_aabb) { } bool AABB::is_equal_approx(const AABB &p_aabb) const { - return position.is_equal_approx(p_aabb.position) && size.is_equal_approx(p_aabb.size); } AABB AABB::intersection(const AABB &p_aabb) const { - Vector3 src_min = position; Vector3 src_max = position + size; Vector3 dst_min = p_aabb.position; @@ -86,7 +80,6 @@ AABB AABB::intersection(const AABB &p_aabb) const { if (src_min.x > dst_max.x || src_max.x < dst_min.x) return AABB(); else { - min.x = (src_min.x > dst_min.x) ? src_min.x : dst_min.x; max.x = (src_max.x < dst_max.x) ? src_max.x : dst_max.x; } @@ -94,7 +87,6 @@ AABB AABB::intersection(const AABB &p_aabb) const { if (src_min.y > dst_max.y || src_max.y < dst_min.y) return AABB(); else { - min.y = (src_min.y > dst_min.y) ? src_min.y : dst_min.y; max.y = (src_max.y < dst_max.y) ? src_max.y : dst_max.y; } @@ -102,7 +94,6 @@ AABB AABB::intersection(const AABB &p_aabb) const { if (src_min.z > dst_max.z || src_max.z < dst_min.z) return AABB(); else { - min.z = (src_min.z > dst_min.z) ? src_min.z : dst_min.z; max.z = (src_max.z < dst_max.z) ? src_max.z : dst_max.z; } @@ -111,7 +102,6 @@ AABB AABB::intersection(const AABB &p_aabb) const { } bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip, Vector3 *r_normal) const { - Vector3 c1, c2; Vector3 end = position + size; real_t near = -1e20; @@ -154,7 +144,6 @@ bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 * } bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_clip, Vector3 *r_normal) const { - real_t min = 0, max = 1; int axis = 0; real_t sign = 0; @@ -168,7 +157,6 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector real_t csign; if (seg_from < seg_to) { - if (seg_from > box_end || seg_to < box_begin) return false; real_t length = seg_to - seg_from; @@ -177,7 +165,6 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector csign = -1.0; } else { - if (seg_to > box_end || seg_from < box_begin) return false; real_t length = seg_to - seg_from; @@ -212,7 +199,6 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector } bool AABB::intersects_plane(const Plane &p_plane) const { - Vector3 points[8] = { Vector3(position.x, position.y, position.z), Vector3(position.x, position.y, position.z + size.z), @@ -228,7 +214,6 @@ bool AABB::intersects_plane(const Plane &p_plane) const { bool under = false; for (int i = 0; i < 8; i++) { - if (p_plane.distance_to(points[i]) > 0) over = true; else @@ -239,7 +224,6 @@ bool AABB::intersects_plane(const Plane &p_plane) const { } Vector3 AABB::get_longest_axis() const { - Vector3 axis(1, 0, 0); real_t max_size = size.x; @@ -255,7 +239,6 @@ Vector3 AABB::get_longest_axis() const { return axis; } int AABB::get_longest_axis_index() const { - int axis = 0; real_t max_size = size.x; @@ -272,7 +255,6 @@ int AABB::get_longest_axis_index() const { } Vector3 AABB::get_shortest_axis() const { - Vector3 axis(1, 0, 0); real_t max_size = size.x; @@ -288,7 +270,6 @@ Vector3 AABB::get_shortest_axis() const { return axis; } int AABB::get_shortest_axis_index() const { - int axis = 0; real_t max_size = size.x; @@ -305,7 +286,6 @@ int AABB::get_shortest_axis_index() const { } AABB AABB::merge(const AABB &p_with) const { - AABB aabb = *this; aabb.merge_with(p_with); return aabb; @@ -316,24 +296,19 @@ AABB AABB::expand(const Vector3 &p_vector) const { return aabb; } AABB AABB::grow(real_t p_by) const { - AABB aabb = *this; aabb.grow_by(p_by); return aabb; } void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const { - ERR_FAIL_INDEX(p_edge, 12); switch (p_edge) { - case 0: { - r_from = Vector3(position.x + size.x, position.y, position.z); r_to = Vector3(position.x, position.y, position.z); } break; case 1: { - r_from = Vector3(position.x + size.x, position.y, position.z + size.z); r_to = Vector3(position.x + size.x, position.y, position.z); } break; @@ -343,18 +318,15 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const { } break; case 3: { - r_from = Vector3(position.x, position.y, position.z); r_to = Vector3(position.x, position.y, position.z + size.z); } break; case 4: { - r_from = Vector3(position.x, position.y + size.y, position.z); r_to = Vector3(position.x + size.x, position.y + size.y, position.z); } break; case 5: { - r_from = Vector3(position.x + size.x, position.y + size.y, position.z); r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z); } break; @@ -364,31 +336,26 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const { } break; case 7: { - r_from = Vector3(position.x, position.y + size.y, position.z + size.z); r_to = Vector3(position.x, position.y + size.y, position.z); } break; case 8: { - r_from = Vector3(position.x, position.y, position.z + size.z); r_to = Vector3(position.x, position.y + size.y, position.z + size.z); } break; case 9: { - r_from = Vector3(position.x, position.y, position.z); r_to = Vector3(position.x, position.y + size.y, position.z); } break; case 10: { - r_from = Vector3(position.x + size.x, position.y, position.z); r_to = Vector3(position.x + size.x, position.y + size.y, position.z); } break; case 11: { - r_from = Vector3(position.x + size.x, position.y, position.z + size.z); r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z); @@ -397,6 +364,5 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const { } AABB::operator String() const { - return String() + position + " - " + size; } diff --git a/core/math/aabb.h b/core/math/aabb.h index f87fced12d..a2dd50f4f3 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -47,12 +47,10 @@ public: real_t get_area() const; /// get area _FORCE_INLINE_ bool has_no_area() const { - return (size.x <= 0 || size.y <= 0 || size.z <= 0); } _FORCE_INLINE_ bool has_no_surface() const { - return (size.x <= 0 && size.y <= 0 && size.z <= 0); } @@ -111,7 +109,6 @@ public: }; inline bool AABB::intersects(const AABB &p_aabb) const { - if (position.x >= (p_aabb.position.x + p_aabb.size.x)) return false; if ((position.x + size.x) <= p_aabb.position.x) @@ -129,7 +126,6 @@ inline bool AABB::intersects(const AABB &p_aabb) const { } inline bool AABB::intersects_inclusive(const AABB &p_aabb) const { - if (position.x > (p_aabb.position.x + p_aabb.size.x)) return false; if ((position.x + size.x) < p_aabb.position.x) @@ -147,7 +143,6 @@ inline bool AABB::intersects_inclusive(const AABB &p_aabb) const { } inline bool AABB::encloses(const AABB &p_aabb) const { - Vector3 src_min = position; Vector3 src_max = position + size; Vector3 dst_min = p_aabb.position; @@ -163,7 +158,6 @@ inline bool AABB::encloses(const AABB &p_aabb) const { } Vector3 AABB::get_support(const Vector3 &p_normal) const { - Vector3 half_extents = size * 0.5; Vector3 ofs = position + half_extents; @@ -175,7 +169,6 @@ Vector3 AABB::get_support(const Vector3 &p_normal) const { } Vector3 AABB::get_endpoint(int p_point) const { - switch (p_point) { case 0: return Vector3(position.x, position.y, position.z); @@ -199,7 +192,6 @@ Vector3 AABB::get_endpoint(int p_point) const { } bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count) const { - Vector3 half_extents = size * 0.5; Vector3 ofs = position + half_extents; @@ -220,7 +212,6 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, con int bad_point_counts_negative[3] = { 0 }; for (int k = 0; k < 3; k++) { - for (int i = 0; i < p_point_count; i++) { if (p_points[i].coord[k] > ofs.coord[k] + half_extents.coord[k]) { bad_point_counts_positive[k]++; @@ -242,7 +233,6 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, con } bool AABB::inside_convex_shape(const Plane *p_planes, int p_plane_count) const { - Vector3 half_extents = size * 0.5; Vector3 ofs = position + half_extents; @@ -261,7 +251,6 @@ bool AABB::inside_convex_shape(const Plane *p_planes, int p_plane_count) const { } bool AABB::has_point(const Vector3 &p_point) const { - if (p_point.x < position.x) return false; if (p_point.y < position.y) @@ -279,7 +268,6 @@ bool AABB::has_point(const Vector3 &p_point) const { } inline void AABB::expand_to(const Vector3 &p_vector) { - Vector3 begin = position; Vector3 end = position + size; @@ -302,7 +290,6 @@ inline void AABB::expand_to(const Vector3 &p_vector) { } void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const { - Vector3 half_extents(size.x * 0.5, size.y * 0.5, size.z * 0.5); Vector3 center(position.x + half_extents.x, position.y + half_extents.y, position.z + half_extents.z); @@ -313,7 +300,6 @@ void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r } inline real_t AABB::get_longest_axis_size() const { - real_t max_size = size.x; if (size.y > max_size) { @@ -328,7 +314,6 @@ inline real_t AABB::get_longest_axis_size() const { } inline real_t AABB::get_shortest_axis_size() const { - real_t max_size = size.x; if (size.y < max_size) { @@ -343,7 +328,6 @@ inline real_t AABB::get_shortest_axis_size() const { } bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const { - real_t divx = 1.0 / p_dir.x; real_t divy = 1.0 / p_dir.y; real_t divz = 1.0 / p_dir.z; @@ -387,7 +371,6 @@ bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real } void AABB::grow_by(real_t p_amount) { - position.x -= p_amount; position.y -= p_amount; position.z -= p_amount; diff --git a/core/math/audio_frame.h b/core/math/audio_frame.h index 4665311059..91f533eafb 100644 --- a/core/math/audio_frame.h +++ b/core/math/audio_frame.h @@ -48,7 +48,6 @@ static inline float undenormalise(volatile float f) { } struct AudioFrame { - //left and right samples float l, r; @@ -105,7 +104,6 @@ struct AudioFrame { } _FORCE_INLINE_ AudioFrame lerp(const AudioFrame &p_b, float p_t) const { - AudioFrame res = *this; res.l += (p_t * (p_b.l - l)); diff --git a/core/math/basis.cpp b/core/math/basis.cpp index 6218b7e248..e6bf6110f7 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -38,16 +38,13 @@ (elements[row1][col1] * elements[row2][col2] - elements[row1][col2] * elements[row2][col1]) void Basis::from_z(const Vector3 &p_z) { - if (Math::abs(p_z.z) > Math_SQRT12) { - // choose p in y-z plane real_t a = p_z[1] * p_z[1] + p_z[2] * p_z[2]; real_t k = 1.0 / Math::sqrt(a); elements[0] = Vector3(0, -p_z[2] * k, p_z[1] * k); elements[1] = Vector3(a * k, -p_z[0] * elements[0][2], p_z[0] * elements[0][1]); } else { - // choose p in x-y plane real_t a = p_z.x * p_z.x + p_z.y * p_z.y; real_t k = 1.0 / Math::sqrt(a); @@ -58,7 +55,6 @@ void Basis::from_z(const Vector3 &p_z) { } void Basis::invert() { - real_t co[3] = { cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1) }; @@ -76,7 +72,6 @@ void Basis::invert() { } void Basis::orthonormalize() { - // Gram-Schmidt Process Vector3 x = get_axis(0); @@ -95,7 +90,6 @@ void Basis::orthonormalize() { } Basis Basis::orthonormalized() const { - Basis c = *this; c.orthonormalize(); return c; @@ -120,7 +114,6 @@ bool Basis::is_rotation() const { } bool Basis::is_symmetric() const { - if (!Math::is_equal_approx_ratio(elements[0][1], elements[1][0], UNIT_EPSILON)) return false; if (!Math::is_equal_approx_ratio(elements[0][2], elements[2][0], UNIT_EPSILON)) @@ -132,7 +125,6 @@ bool Basis::is_symmetric() const { } Basis Basis::diagonalize() { - //NOTE: only implemented for symmetric matrices //with the Jacobi iterative method method #ifdef MATH_CHECKS @@ -193,21 +185,18 @@ Basis Basis::diagonalize() { } Basis Basis::inverse() const { - Basis inv = *this; inv.invert(); return inv; } void Basis::transpose() { - SWAP(elements[0][1], elements[1][0]); SWAP(elements[0][2], elements[2][0]); SWAP(elements[1][2], elements[2][1]); } Basis Basis::transposed() const { - Basis tr = *this; tr.transpose(); return tr; @@ -216,7 +205,6 @@ Basis Basis::transposed() const { // Multiplies the matrix from left by the scaling matrix: M -> S.M // See the comment for Basis::rotated for further explanation. void Basis::scale(const Vector3 &p_scale) { - elements[0][0] *= p_scale.x; elements[0][1] *= p_scale.x; elements[0][2] *= p_scale.x; @@ -260,7 +248,6 @@ Basis Basis::scaled_local(const Vector3 &p_scale) const { } Vector3 Basis::get_scale_abs() const { - return Vector3( Vector3(elements[0][0], elements[1][0], elements[2][0]).length(), Vector3(elements[0][1], elements[1][1], elements[2][1]).length(), @@ -341,7 +328,6 @@ 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); } @@ -430,7 +416,6 @@ void Basis::get_rotation_axis_angle_local(Vector3 &p_axis, real_t &p_angle) cons // the angles in the decomposition R = X(a1).Y(a2).Z(a3) where Z(a) rotates // around the z-axis by a and so on. Vector3 Basis::get_euler_xyz() const { - // Euler angles in XYZ convention. // See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix // @@ -474,7 +459,6 @@ Vector3 Basis::get_euler_xyz() const { // and similar for other axes. // The current implementation uses XYZ convention (Z is the first rotation). void Basis::set_euler_xyz(const Vector3 &p_euler) { - real_t c, s; c = Math::cos(p_euler.x); @@ -497,7 +481,6 @@ void Basis::set_euler_xyz(const Vector3 &p_euler) { // as in first-Z, then-X, last-Y. The angles for X, Y, and Z rotations are returned // as the x, y, and z components of a Vector3 respectively. Vector3 Basis::get_euler_yxz() const { - /* checking this is a bad idea, because obtaining from scaled transform is a valid use case #ifdef MATH_CHECKS ERR_FAIL_COND(!is_rotation()); @@ -546,7 +529,6 @@ Vector3 Basis::get_euler_yxz() const { // and similar for other axes. // The current implementation uses YXZ convention (Z is the first rotation). void Basis::set_euler_yxz(const Vector3 &p_euler) { - real_t c, s; c = Math::cos(p_euler.x); @@ -566,12 +548,10 @@ void Basis::set_euler_yxz(const Vector3 &p_euler) { } bool Basis::is_equal_approx(const Basis &p_basis) const { - return elements[0].is_equal_approx(p_basis.elements[0]) && elements[1].is_equal_approx(p_basis.elements[1]) && elements[2].is_equal_approx(p_basis.elements[2]); } bool Basis::is_equal_approx_ratio(const Basis &a, const Basis &b, real_t p_epsilon) const { - for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (!Math::is_equal_approx_ratio(a.elements[i][j], b.elements[i][j], p_epsilon)) @@ -583,7 +563,6 @@ bool Basis::is_equal_approx_ratio(const Basis &a, const Basis &b, real_t p_epsil } bool Basis::operator==(const Basis &p_matrix) const { - for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (elements[i][j] != p_matrix.elements[i][j]) @@ -595,17 +574,13 @@ bool Basis::operator==(const Basis &p_matrix) const { } bool Basis::operator!=(const Basis &p_matrix) const { - return (!(*this == p_matrix)); } Basis::operator String() const { - String mtx; for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { - if (i != 0 || j != 0) mtx += ", "; @@ -617,7 +592,6 @@ Basis::operator String() const { } Quat Basis::get_quat() const { - #ifdef MATH_CHECKS ERR_FAIL_COND_V_MSG(!is_rotation(), Quat(), "Basis must be normalized in order to be casted to a Quaternion. Use get_rotation_quat() or call orthonormalized() instead."); #endif @@ -681,12 +655,10 @@ static const Basis _ortho_bases[24] = { }; int Basis::get_orthogonal_index() const { - //could be sped up if i come up with a way Basis orth = *this; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - real_t v = orth[i][j]; if (v > 0.5) v = 1.0; @@ -700,7 +672,6 @@ int Basis::get_orthogonal_index() const { } for (int i = 0; i < 24; i++) { - if (_ortho_bases[i] == orth) return i; } @@ -709,7 +680,6 @@ int Basis::get_orthogonal_index() const { } void Basis::set_orthogonal_index(int p_index) { - //there only exist 24 orthogonal bases in r3 ERR_FAIL_INDEX(p_index, 24); @@ -794,7 +764,6 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const { } void Basis::set_quat(const Quat &p_quat) { - real_t d = p_quat.length_squared(); real_t s = 2.0 / d; real_t xs = p_quat.x * s, ys = p_quat.y * s, zs = p_quat.z * s; @@ -866,7 +835,6 @@ void Basis::set_diagonal(const Vector3 &p_diag) { } Basis Basis::slerp(const Basis &target, const real_t &t) const { - //consider scale Quat from(*this); Quat to(target); @@ -880,7 +848,6 @@ Basis Basis::slerp(const Basis &target, const real_t &t) const { } void Basis::rotate_sh(real_t *p_values) { - // code by John Hable // http://filmicworlds.com/blog/simple-and-fast-spherical-harmonic-rotation/ // this code is Public Domain diff --git a/core/math/basis.h b/core/math/basis.h index 2924a0ddbd..d870a6b099 100644 --- a/core/math/basis.h +++ b/core/math/basis.h @@ -39,11 +39,9 @@ public: Vector3 elements[3]; _FORCE_INLINE_ const Vector3 &operator[](int axis) const { - return elements[axis]; } _FORCE_INLINE_ Vector3 &operator[](int axis) { - return elements[axis]; } @@ -166,7 +164,6 @@ public: /* create / set */ _FORCE_INLINE_ void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) { - elements[0][0] = xx; elements[0][1] = xy; elements[0][2] = xz; @@ -178,18 +175,15 @@ public: elements[2][2] = zz; } _FORCE_INLINE_ void set(const Vector3 &p_x, const Vector3 &p_y, const Vector3 &p_z) { - set_axis(0, p_x); set_axis(1, p_y); set_axis(2, p_z); } _FORCE_INLINE_ Vector3 get_column(int i) const { - return Vector3(elements[0][i], elements[1][i], elements[2][i]); } _FORCE_INLINE_ Vector3 get_row(int i) const { - return Vector3(elements[i][0], elements[i][1], elements[i][2]); } _FORCE_INLINE_ Vector3 get_main_diagonal() const { @@ -221,7 +215,6 @@ public: elements[0].z * m[0].z + elements[1].z * m[1].z + elements[2].z * m[2].z); } Basis(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) { - set(xx, xy, xz, yx, yy, yz, zx, zy, zz); } @@ -249,7 +242,6 @@ public: } _FORCE_INLINE_ Basis() { - elements[0][0] = 1; elements[0][1] = 0; elements[0][2] = 0; @@ -263,7 +255,6 @@ public: }; _FORCE_INLINE_ void Basis::operator*=(const Basis &p_matrix) { - set( p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]), p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]), @@ -271,7 +262,6 @@ _FORCE_INLINE_ void Basis::operator*=(const Basis &p_matrix) { } _FORCE_INLINE_ Basis Basis::operator*(const Basis &p_matrix) const { - return Basis( p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]), p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]), @@ -279,49 +269,42 @@ _FORCE_INLINE_ Basis Basis::operator*(const Basis &p_matrix) const { } _FORCE_INLINE_ void Basis::operator+=(const Basis &p_matrix) { - elements[0] += p_matrix.elements[0]; elements[1] += p_matrix.elements[1]; elements[2] += p_matrix.elements[2]; } _FORCE_INLINE_ Basis Basis::operator+(const Basis &p_matrix) const { - Basis ret(*this); ret += p_matrix; return ret; } _FORCE_INLINE_ void Basis::operator-=(const Basis &p_matrix) { - elements[0] -= p_matrix.elements[0]; elements[1] -= p_matrix.elements[1]; elements[2] -= p_matrix.elements[2]; } _FORCE_INLINE_ Basis Basis::operator-(const Basis &p_matrix) const { - Basis ret(*this); ret -= p_matrix; return ret; } _FORCE_INLINE_ void Basis::operator*=(real_t p_val) { - elements[0] *= p_val; elements[1] *= p_val; elements[2] *= p_val; } _FORCE_INLINE_ Basis Basis::operator*(real_t p_val) const { - Basis ret(*this); ret *= p_val; return ret; } Vector3 Basis::xform(const Vector3 &p_vector) const { - return Vector3( elements[0].dot(p_vector), elements[1].dot(p_vector), @@ -329,7 +312,6 @@ Vector3 Basis::xform(const Vector3 &p_vector) const { } Vector3 Basis::xform_inv(const Vector3 &p_vector) const { - return Vector3( (elements[0][0] * p_vector.x) + (elements[1][0] * p_vector.y) + (elements[2][0] * p_vector.z), (elements[0][1] * p_vector.x) + (elements[1][1] * p_vector.y) + (elements[2][1] * p_vector.z), @@ -337,7 +319,6 @@ Vector3 Basis::xform_inv(const Vector3 &p_vector) const { } real_t Basis::determinant() const { - return elements[0][0] * (elements[1][1] * elements[2][2] - elements[2][1] * elements[1][2]) - elements[1][0] * (elements[0][1] * elements[2][2] - elements[2][1] * elements[0][2]) + elements[2][0] * (elements[0][1] * elements[1][2] - elements[1][1] * elements[0][2]); diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index 5d3ebc9f6d..4b147bd987 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -34,7 +34,6 @@ #include "core/print_string.h" float CameraMatrix::determinant() const { - return matrix[0][3] * matrix[1][2] * matrix[2][1] * matrix[3][0] - matrix[0][2] * matrix[1][3] * matrix[2][1] * matrix[3][0] - matrix[0][3] * matrix[1][1] * matrix[2][2] * matrix[3][0] + matrix[0][1] * matrix[1][3] * matrix[2][2] * matrix[3][0] + matrix[0][2] * matrix[1][1] * matrix[2][3] * matrix[3][0] - matrix[0][1] * matrix[1][2] * matrix[2][3] * matrix[3][0] - @@ -50,29 +49,22 @@ float CameraMatrix::determinant() const { } void CameraMatrix::set_identity() { - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - matrix[i][j] = (i == j) ? 1 : 0; } } } void CameraMatrix::set_zero() { - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - matrix[i][j] = 0; } } } Plane CameraMatrix::xform4(const Plane &p_vec4) const { - Plane ret; ret.normal.x = matrix[0][0] * p_vec4.normal.x + matrix[1][0] * p_vec4.normal.y + matrix[2][0] * p_vec4.normal.z + matrix[3][0] * p_vec4.d; @@ -83,7 +75,6 @@ Plane CameraMatrix::xform4(const Plane &p_vec4) const { } void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov) { - if (p_flip_fov) { p_fovy_degrees = get_fovy(p_fovy_degrees, 1.0 / p_aspect); } @@ -176,7 +167,6 @@ void CameraMatrix::set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_ }; void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar) { - set_identity(); matrix[0][0] = 2.0 / (p_right - p_left); @@ -189,7 +179,6 @@ void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom } void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov) { - if (!p_flip_fov) { p_size *= p_aspect; } @@ -198,7 +187,6 @@ void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear } void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far) { - ERR_FAIL_COND(p_right <= p_left); ERR_FAIL_COND(p_top <= p_bottom); ERR_FAIL_COND(p_far <= p_near); @@ -239,7 +227,6 @@ void CameraMatrix::set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, } real_t CameraMatrix::get_z_far() const { - const real_t *matrix = (const real_t *)this->matrix; Plane new_plane = Plane(matrix[3] - matrix[2], matrix[7] - matrix[6], @@ -252,7 +239,6 @@ real_t CameraMatrix::get_z_far() const { return new_plane.d; } real_t CameraMatrix::get_z_near() const { - const real_t *matrix = (const real_t *)this->matrix; Plane new_plane = Plane(matrix[3] + matrix[2], matrix[7] + matrix[6], @@ -264,7 +250,6 @@ real_t CameraMatrix::get_z_near() const { } Vector2 CameraMatrix::get_viewport_half_extents() const { - const real_t *matrix = (const real_t *)this->matrix; ///////--- Near Plane ---/////// Plane near_plane = Plane(matrix[3] + matrix[2], @@ -293,7 +278,6 @@ Vector2 CameraMatrix::get_viewport_half_extents() const { } void CameraMatrix::get_far_plane_size(real_t &r_width, real_t &r_height) const { - const real_t *matrix = (const real_t *)this->matrix; ///////--- Far Plane ---/////// Plane far_plane = Plane(matrix[3] - matrix[2], @@ -323,7 +307,6 @@ void CameraMatrix::get_far_plane_size(real_t &r_width, real_t &r_height) const { } bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8points) const { - Vector<Plane> planes = get_projection_planes(Transform()); const Planes intersections[8][3] = { { PLANE_FAR, PLANE_LEFT, PLANE_TOP }, @@ -337,7 +320,6 @@ bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8point }; for (int i = 0; i < 8; i++) { - Vector3 point; bool res = planes[intersections[i][0]].intersect_3(planes[intersections[i][1]], planes[intersections[i][2]], &point); ERR_FAIL_COND_V(!res, false); @@ -348,7 +330,6 @@ bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8point } Vector<Plane> CameraMatrix::get_projection_planes(const Transform &p_transform) const { - /** Fast Plane Extraction from combined modelview/projection matrices. * References: * https://web.archive.org/web/20011221205252/http://www.markmorley.com/opengl/frustumculling.html @@ -431,14 +412,12 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform &p_transform) } CameraMatrix CameraMatrix::inverse() const { - CameraMatrix cm = *this; cm.invert(); return cm; } void CameraMatrix::invert() { - int i, j, k; int pvt_i[4], pvt_j[4]; /* Locations of pivot matrix */ real_t pvt_val; /* Value of current pivot element */ @@ -541,12 +520,10 @@ void CameraMatrix::flip_y() { } CameraMatrix::CameraMatrix() { - set_identity(); } CameraMatrix CameraMatrix::operator*(const CameraMatrix &p_matrix) const { - CameraMatrix new_matrix; for (int j = 0; j < 4; j++) { @@ -562,7 +539,6 @@ CameraMatrix CameraMatrix::operator*(const CameraMatrix &p_matrix) const { } void CameraMatrix::set_depth_correction(bool p_flip_y) { - real_t *m = &matrix[0][0]; m[0] = 1; @@ -584,7 +560,6 @@ void CameraMatrix::set_depth_correction(bool p_flip_y) { } void CameraMatrix::set_light_bias() { - real_t *m = &matrix[0][0]; m[0] = 0.5; @@ -606,7 +581,6 @@ void CameraMatrix::set_light_bias() { } void CameraMatrix::set_light_atlas_rect(const Rect2 &p_rect) { - real_t *m = &matrix[0][0]; m[0] = p_rect.size.width; @@ -628,7 +602,6 @@ void CameraMatrix::set_light_atlas_rect(const Rect2 &p_rect) { } CameraMatrix::operator String() const { - String str; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) @@ -638,20 +611,17 @@ CameraMatrix::operator String() const { } real_t CameraMatrix::get_aspect() const { - Vector2 vp_he = get_viewport_half_extents(); return vp_he.x / vp_he.y; } int CameraMatrix::get_pixels_per_meter(int p_for_pixel_width) const { - Vector3 result = xform(Vector3(1, 0, -1)); return int((result.x * 0.5 + 0.5) * p_for_pixel_width); } bool CameraMatrix::is_orthogonal() const { - return matrix[3][3] == 1.0; } @@ -679,7 +649,6 @@ real_t CameraMatrix::get_fov() const { } void CameraMatrix::make_scale(const Vector3 &p_scale) { - set_identity(); matrix[0][0] = p_scale.x; matrix[1][1] = p_scale.y; @@ -687,7 +656,6 @@ void CameraMatrix::make_scale(const Vector3 &p_scale) { } void CameraMatrix::scale_translate_to_fit(const AABB &p_aabb) { - Vector3 min = p_aabb.position; Vector3 max = p_aabb.position + p_aabb.size; @@ -713,7 +681,6 @@ void CameraMatrix::scale_translate_to_fit(const AABB &p_aabb) { } CameraMatrix::operator Transform() const { - Transform tr; const real_t *m = &matrix[0][0]; @@ -737,7 +704,6 @@ CameraMatrix::operator Transform() const { } CameraMatrix::CameraMatrix(const Transform &p_transform) { - const Transform &tr = p_transform; real_t *m = &matrix[0][0]; diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h index 5420fa2984..49fdecae02 100644 --- a/core/math/camera_matrix.h +++ b/core/math/camera_matrix.h @@ -35,7 +35,6 @@ #include "core/math/transform.h" struct CameraMatrix { - enum Planes { PLANE_NEAR, PLANE_FAR, @@ -62,7 +61,6 @@ struct CameraMatrix { void set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, real_t p_near, real_t p_far, bool p_flip_fov = false); static real_t get_fovy(real_t p_fovx, real_t p_aspect) { - return Math::rad2deg(Math::atan(p_aspect * Math::tan(Math::deg2rad(p_fovx) * 0.5)) * 2.0); } @@ -116,7 +114,6 @@ struct CameraMatrix { }; Vector3 CameraMatrix::xform(const Vector3 &p_vec3) const { - Vector3 ret; ret.x = matrix[0][0] * p_vec3.x + matrix[1][0] * p_vec3.y + matrix[2][0] * p_vec3.z + matrix[3][0]; ret.y = matrix[0][1] * p_vec3.x + matrix[1][1] * p_vec3.y + matrix[2][1] * p_vec3.z + matrix[3][1]; diff --git a/core/math/delaunay_2d.h b/core/math/delaunay_2d.h index 66b2f8f573..d637671686 100644 --- a/core/math/delaunay_2d.h +++ b/core/math/delaunay_2d.h @@ -57,7 +57,6 @@ public: }; static bool circum_circle_contains(const Vector<Vector2> &p_vertices, const Triangle &p_triangle, int p_vertex) { - Vector2 p1 = p_vertices[p_triangle.points[0]]; Vector2 p2 = p_vertices[p_triangle.points[1]]; Vector2 p3 = p_vertices[p_triangle.points[2]]; @@ -89,7 +88,6 @@ public: } static Vector<Triangle> triangulate(const Vector<Vector2> &p_points) { - Vector<Vector2> points = p_points; Vector<Triangle> triangles; @@ -112,7 +110,6 @@ public: triangles.push_back(Triangle(p_points.size() + 0, p_points.size() + 1, p_points.size() + 2)); for (int i = 0; i < p_points.size(); i++) { - Vector<Edge> polygon; for (int j = 0; j < triangles.size(); j++) { @@ -141,7 +138,6 @@ public: } for (int j = 0; j < polygon.size(); j++) { - if (polygon[j].bad) { continue; } diff --git a/core/math/delaunay_3d.h b/core/math/delaunay_3d.h index 0976d8556f..8fdb52556f 100644 --- a/core/math/delaunay_3d.h +++ b/core/math/delaunay_3d.h @@ -55,7 +55,6 @@ class Delaunay3D { }; struct Simplex { - uint32_t points[4]; R128 circum_center_x; R128 circum_center_y; @@ -104,7 +103,6 @@ class Delaunay3D { }; _FORCE_INLINE_ static void circum_sphere_compute(const Vector3 *p_points, Simplex *p_simplex) { - // the only part in the algorithm where there may be precision errors is this one, so ensure that // we do it as maximum precision as possible @@ -164,7 +162,6 @@ class Delaunay3D { } _FORCE_INLINE_ static bool simplex_contains(const Vector3 *p_points, const Simplex &p_simplex, uint32_t p_vertex) { - R128 v_x = p_points[p_vertex].x; R128 v_y = p_points[p_vertex].y; R128 v_z = p_points[p_vertex].z; @@ -179,7 +176,6 @@ class Delaunay3D { } static bool simplex_is_coplanar(const Vector3 *p_points, const Simplex &p_simplex) { - Plane p(p_points[p_simplex.points[0]], p_points[p_simplex.points[1]], p_points[p_simplex.points[2]]); if (ABS(p.distance_to(p_points[p_simplex.points[3]])) < CMP_EPSILON) { return true; @@ -216,7 +212,6 @@ public: }; static Vector<OutputSimplex> tetrahedralize(const Vector<Vector3> &p_points) { - uint32_t point_count = p_points.size(); Vector3 *points = (Vector3 *)memalloc(sizeof(Vector3) * (point_count + 4)); @@ -273,7 +268,6 @@ public: LocalVector<Triangle> triangles; for (uint32_t i = 0; i < point_count; i++) { - bool unique = true; for (uint32_t j = i + 1; j < point_count; j++) { if (points[i].is_equal_approx(points[j])) { @@ -296,7 +290,6 @@ public: Simplex *simplex = E->get(); if (simplex_contains(points, *simplex, i)) { - static const uint32_t triangle_order[4][3] = { { 0, 1, 2 }, { 0, 1, 3 }, @@ -329,7 +322,6 @@ public: uint32_t good_triangles = 0; for (uint32_t j = 0; j < triangles.size(); j++) { - if (triangles[j].bad) { continue; } diff --git a/core/math/disjoint_set.h b/core/math/disjoint_set.h index 32b9875e4c..4d93a0035b 100644 --- a/core/math/disjoint_set.h +++ b/core/math/disjoint_set.h @@ -41,7 +41,6 @@ /* This DisjointSet class uses Find with path compression and Union by rank */ template <typename T, class C = Comparator<T>, class AL = DefaultAllocator> class DisjointSet { - struct Element { T object; Element *parent = nullptr; @@ -103,7 +102,6 @@ typename DisjointSet<T, C, AL>::Element *DisjointSet<T, C, AL>::insert_or_get(T template <typename T, class C, class AL> void DisjointSet<T, C, AL>::create_union(T a, T b) { - Element *x = insert_or_get(a); Element *y = insert_or_get(b); diff --git a/core/math/expression.cpp b/core/math/expression.cpp index c43831ddee..7bfebded6a 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -110,7 +110,6 @@ const char *Expression::func_name[Expression::FUNC_MAX] = { }; Expression::BuiltinFunc Expression::find_function(const String &p_string) { - for (int i = 0; i < FUNC_MAX; i++) { if (p_string == func_name[i]) return BuiltinFunc(i); @@ -120,15 +119,12 @@ Expression::BuiltinFunc Expression::find_function(const String &p_string) { } String Expression::get_func_name(BuiltinFunc p_func) { - ERR_FAIL_INDEX_V(p_func, FUNC_MAX, String()); return func_name[p_func]; } int Expression::get_func_argument_count(BuiltinFunc p_func) { - switch (p_func) { - case MATH_RANDOMIZE: case MATH_RAND: case MATH_RANDF: @@ -220,194 +216,157 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant r_error.error = Callable::CallError::CALL_OK; switch (p_func) { case MATH_SIN: { - VALIDATE_ARG_NUM(0); *r_return = Math::sin((double)*p_inputs[0]); } break; case MATH_COS: { - VALIDATE_ARG_NUM(0); *r_return = Math::cos((double)*p_inputs[0]); } break; case MATH_TAN: { - VALIDATE_ARG_NUM(0); *r_return = Math::tan((double)*p_inputs[0]); } break; case MATH_SINH: { - VALIDATE_ARG_NUM(0); *r_return = Math::sinh((double)*p_inputs[0]); } break; case MATH_COSH: { - VALIDATE_ARG_NUM(0); *r_return = Math::cosh((double)*p_inputs[0]); } break; case MATH_TANH: { - VALIDATE_ARG_NUM(0); *r_return = Math::tanh((double)*p_inputs[0]); } break; case MATH_ASIN: { - VALIDATE_ARG_NUM(0); *r_return = Math::asin((double)*p_inputs[0]); } break; case MATH_ACOS: { - VALIDATE_ARG_NUM(0); *r_return = Math::acos((double)*p_inputs[0]); } break; case MATH_ATAN: { - VALIDATE_ARG_NUM(0); *r_return = Math::atan((double)*p_inputs[0]); } break; case MATH_ATAN2: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::atan2((double)*p_inputs[0], (double)*p_inputs[1]); } break; case MATH_SQRT: { - VALIDATE_ARG_NUM(0); *r_return = Math::sqrt((double)*p_inputs[0]); } break; case MATH_FMOD: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::fmod((double)*p_inputs[0], (double)*p_inputs[1]); } break; case MATH_FPOSMOD: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::fposmod((double)*p_inputs[0], (double)*p_inputs[1]); } break; case MATH_POSMOD: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::posmod((int)*p_inputs[0], (int)*p_inputs[1]); } break; case MATH_FLOOR: { - VALIDATE_ARG_NUM(0); *r_return = Math::floor((double)*p_inputs[0]); } break; case MATH_CEIL: { - VALIDATE_ARG_NUM(0); *r_return = Math::ceil((double)*p_inputs[0]); } break; case MATH_ROUND: { - VALIDATE_ARG_NUM(0); *r_return = Math::round((double)*p_inputs[0]); } break; case MATH_ABS: { - if (p_inputs[0]->get_type() == Variant::INT) { - int64_t i = *p_inputs[0]; *r_return = ABS(i); } else if (p_inputs[0]->get_type() == Variant::FLOAT) { - real_t r = *p_inputs[0]; *r_return = Math::abs(r); } else { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::FLOAT; } } break; case MATH_SIGN: { - if (p_inputs[0]->get_type() == Variant::INT) { - int64_t i = *p_inputs[0]; *r_return = i < 0 ? -1 : (i > 0 ? +1 : 0); } else if (p_inputs[0]->get_type() == Variant::FLOAT) { - real_t r = *p_inputs[0]; *r_return = r < 0.0 ? -1.0 : (r > 0.0 ? +1.0 : 0.0); } else { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::FLOAT; } } break; case MATH_POW: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::pow((double)*p_inputs[0], (double)*p_inputs[1]); } break; case MATH_LOG: { - VALIDATE_ARG_NUM(0); *r_return = Math::log((double)*p_inputs[0]); } break; case MATH_EXP: { - VALIDATE_ARG_NUM(0); *r_return = Math::exp((double)*p_inputs[0]); } break; case MATH_ISNAN: { - VALIDATE_ARG_NUM(0); *r_return = Math::is_nan((double)*p_inputs[0]); } break; case MATH_ISINF: { - VALIDATE_ARG_NUM(0); *r_return = Math::is_inf((double)*p_inputs[0]); } break; case MATH_EASE: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::ease((double)*p_inputs[0], (double)*p_inputs[1]); } break; case MATH_STEP_DECIMALS: { - VALIDATE_ARG_NUM(0); *r_return = Math::step_decimals((double)*p_inputs[0]); } break; case MATH_STEPIFY: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::stepify((double)*p_inputs[0], (double)*p_inputs[1]); } break; case MATH_LERP: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); *r_return = Math::lerp((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case MATH_LERP_ANGLE: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); *r_return = Math::lerp_angle((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case MATH_INVERSE_LERP: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); *r_return = Math::inverse_lerp((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case MATH_RANGE_LERP: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); @@ -422,14 +381,12 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant *r_return = Math::smoothstep((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case MATH_MOVE_TOWARD: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); *r_return = Math::move_toward((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case MATH_DECTIME: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); @@ -446,20 +403,17 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant *r_return = Math::randf(); } break; case MATH_RANDOM: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::random((double)*p_inputs[0], (double)*p_inputs[1]); } break; case MATH_SEED: { - VALIDATE_ARG_NUM(0); uint64_t seed = *p_inputs[0]; Math::seed(seed); } break; case MATH_RANDSEED: { - VALIDATE_ARG_NUM(0); uint64_t seed = *p_inputs[0]; int ret = Math::rand_from_seed(&seed); @@ -470,22 +424,18 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } break; case MATH_DEG2RAD: { - VALIDATE_ARG_NUM(0); *r_return = Math::deg2rad((double)*p_inputs[0]); } break; case MATH_RAD2DEG: { - VALIDATE_ARG_NUM(0); *r_return = Math::rad2deg((double)*p_inputs[0]); } break; case MATH_LINEAR2DB: { - VALIDATE_ARG_NUM(0); *r_return = Math::linear2db((double)*p_inputs[0]); } break; case MATH_DB2LINEAR: { - VALIDATE_ARG_NUM(0); *r_return = Math::db2linear((double)*p_inputs[0]); } break; @@ -516,9 +466,7 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant *r_return = Math::wrapf((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case LOGIC_MAX: { - if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT) { - int64_t a = *p_inputs[0]; int64_t b = *p_inputs[1]; *r_return = MAX(a, b); @@ -534,9 +482,7 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } break; case LOGIC_MIN: { - if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT) { - int64_t a = *p_inputs[0]; int64_t b = *p_inputs[1]; *r_return = MIN(a, b); @@ -551,9 +497,7 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } } break; case LOGIC_CLAMP: { - if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT && p_inputs[2]->get_type() == Variant::INT) { - int64_t a = *p_inputs[0]; int64_t b = *p_inputs[1]; int64_t c = *p_inputs[2]; @@ -571,15 +515,12 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } } break; case LOGIC_NEAREST_PO2: { - VALIDATE_ARG_NUM(0); int64_t num = *p_inputs[0]; *r_return = next_power_of_2(num); } break; case OBJ_WEAKREF: { - if (p_inputs[0]->get_type() != Variant::OBJECT) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::OBJECT; @@ -588,10 +529,8 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } if (p_inputs[0]->is_ref()) { - REF r = *p_inputs[0]; if (!r.is_valid()) { - return; } @@ -601,7 +540,6 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } else { Object *obj = *p_inputs[0]; if (!obj) { - return; } Ref<WeakRef> wref = memnew(WeakRef); @@ -611,9 +549,7 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } break; case FUNC_FUNCREF: { - if (p_inputs[0]->get_type() != Variant::OBJECT) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::OBJECT; @@ -621,7 +557,6 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant return; } if (p_inputs[1]->get_type() != Variant::STRING && p_inputs[1]->get_type() != Variant::NODE_PATH) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 1; r_error.expected = Variant::STRING; @@ -638,11 +573,9 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } break; case TYPE_CONVERT: { - VALIDATE_ARG_NUM(1); int type = *p_inputs[1]; if (type < 0 || type >= Variant::VARIANT_MAX) { - r_error_str = RTR("Invalid type argument to convert(), use TYPE_* constants."); r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; @@ -650,31 +583,25 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant return; } else { - *r_return = Variant::construct(Variant::Type(type), p_inputs, 1, r_error); } } break; case TYPE_OF: { - *r_return = p_inputs[0]->get_type(); } break; case TYPE_EXISTS: { - *r_return = ClassDB::class_exists(*p_inputs[0]); } break; case TEXT_CHAR: { - CharType result[2] = { *p_inputs[0], 0 }; *r_return = String(result); } break; case TEXT_ORD: { - if (p_inputs[0]->get_type() != Variant::STRING) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::STRING; @@ -685,7 +612,6 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant String str = *p_inputs[0]; if (str.length() != 1) { - r_error_str = RTR("Expected a string of length 1 (a character)."); r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; @@ -698,39 +624,33 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } break; case TEXT_STR: { - String str = *p_inputs[0]; *r_return = str; } break; case TEXT_PRINT: { - String str = *p_inputs[0]; print_line(str); } break; case TEXT_PRINTERR: { - String str = *p_inputs[0]; print_error(str); } break; case TEXT_PRINTRAW: { - String str = *p_inputs[0]; OS::get_singleton()->print("%s", str.utf8().get_data()); } break; case VAR_TO_STR: { - String vars; VariantWriter::write_to_string(*p_inputs[0], vars); *r_return = vars; } break; case STR_TO_VAR: { - if (p_inputs[0]->get_type() != Variant::STRING) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; @@ -756,7 +676,6 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } break; case VAR_TO_BYTES: { - PackedByteArray barr; bool full_objects = *p_inputs[1]; int len; @@ -777,7 +696,6 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant *r_return = barr; } break; case BYTES_TO_VAR: { - if (p_inputs[0]->get_type() != Variant::PACKED_BYTE_ARRAY) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; @@ -805,7 +723,6 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } break; case COLORN: { - VALIDATE_ARG_NUM(1); Color color = Color::named(*p_inputs[0]); @@ -826,60 +743,49 @@ static bool _is_number(CharType c) { } Error Expression::_get_token(Token &r_token) { - while (true) { #define GET_CHAR() (str_ofs >= expression.length() ? 0 : expression[str_ofs++]) CharType cchar = GET_CHAR(); switch (cchar) { - case 0: { r_token.type = TK_EOF; return OK; }; case '{': { - r_token.type = TK_CURLY_BRACKET_OPEN; return OK; }; case '}': { - r_token.type = TK_CURLY_BRACKET_CLOSE; return OK; }; case '[': { - r_token.type = TK_BRACKET_OPEN; return OK; }; case ']': { - r_token.type = TK_BRACKET_CLOSE; return OK; }; case '(': { - r_token.type = TK_PARENTHESIS_OPEN; return OK; }; case ')': { - r_token.type = TK_PARENTHESIS_CLOSE; return OK; }; case ',': { - r_token.type = TK_COMMA; return OK; }; case ':': { - r_token.type = TK_COLON; return OK; }; case '$': { - r_token.type = TK_INPUT; int index = 0; do { @@ -898,7 +804,6 @@ Error Expression::_get_token(Token &r_token) { return OK; }; case '=': { - cchar = GET_CHAR(); if (cchar == '=') { r_token.type = TK_OP_EQUAL; @@ -910,7 +815,6 @@ Error Expression::_get_token(Token &r_token) { return OK; }; case '!': { - if (expression[str_ofs] == '=') { r_token.type = TK_OP_NOT_EQUAL; str_ofs++; @@ -920,7 +824,6 @@ Error Expression::_get_token(Token &r_token) { return OK; }; case '>': { - if (expression[str_ofs] == '=') { r_token.type = TK_OP_GREATER_EQUAL; str_ofs++; @@ -933,7 +836,6 @@ Error Expression::_get_token(Token &r_token) { return OK; }; case '<': { - if (expression[str_ofs] == '=') { r_token.type = TK_OP_LESS_EQUAL; str_ofs++; @@ -966,7 +868,6 @@ Error Expression::_get_token(Token &r_token) { return OK; }; case '&': { - if (expression[str_ofs] == '&') { r_token.type = TK_OP_AND; str_ofs++; @@ -976,7 +877,6 @@ Error Expression::_get_token(Token &r_token) { return OK; }; case '|': { - if (expression[str_ofs] == '|') { r_token.type = TK_OP_OR; str_ofs++; @@ -986,22 +886,18 @@ Error Expression::_get_token(Token &r_token) { return OK; }; case '^': { - r_token.type = TK_OP_BIT_XOR; return OK; }; case '~': { - r_token.type = TK_OP_BIT_INVERT; return OK; }; case '"': { - String str; while (true) { - CharType ch = GET_CHAR(); if (ch == 0) { @@ -1022,7 +918,6 @@ Error Expression::_get_token(Token &r_token) { CharType res = 0; switch (next) { - case 'b': res = 8; break; @@ -1049,7 +944,6 @@ Error Expression::_get_token(Token &r_token) { return ERR_PARSE_ERROR; } if (!(_is_number(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) { - _set_error("Malformed hex constant in string"); r_token.type = TK_ERROR; return ERR_PARSE_ERROR; @@ -1091,7 +985,6 @@ Error Expression::_get_token(Token &r_token) { } break; default: { - if (cchar <= 32) { break; } @@ -1114,10 +1007,8 @@ Error Expression::_get_token(Token &r_token) { bool is_float = false; while (true) { - switch (reading) { case READING_INT: { - if (_is_number(c)) { //pass } else if (c == '.') { @@ -1131,9 +1022,7 @@ Error Expression::_get_token(Token &r_token) { } break; case READING_DEC: { - if (_is_number(c)) { - } else if (c == 'e') { reading = READING_EXP; @@ -1143,7 +1032,6 @@ Error Expression::_get_token(Token &r_token) { } break; case READING_EXP: { - if (_is_number(c)) { exp_beg = true; @@ -1175,12 +1063,10 @@ Error Expression::_get_token(Token &r_token) { return OK; } else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') { - String id; bool first = true; while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && _is_number(cchar))) { - id += String::chr(cchar); cchar = GET_CHAR(); first = false; @@ -1220,7 +1106,6 @@ Error Expression::_get_token(Token &r_token) { } else if (id == "self") { r_token.type = TK_SELF; } else { - for (int i = 0; i < Variant::VARIANT_MAX; i++) { if (id == Variant::get_type_name(Variant::Type(i))) { r_token.type = TK_BASIC_TYPE; @@ -1303,7 +1188,6 @@ const char *Expression::token_name[TK_MAX] = { }; Expression::ENode *Expression::_parse_expression() { - Vector<ExpressionNode> expression; while (true) { @@ -1321,7 +1205,6 @@ Expression::ENode *Expression::_parse_expression() { DictionaryNode *dn = alloc_node<DictionaryNode>(); while (true) { - int cofs = str_ofs; _get_token(tk); if (tk.type == TK_CURLY_BRACKET_CLOSE) { @@ -1365,7 +1248,6 @@ Expression::ENode *Expression::_parse_expression() { ArrayNode *an = alloc_node<ArrayNode>(); while (true) { - int cofs = str_ofs; _get_token(tk); if (tk.type == TK_BRACKET_CLOSE) { @@ -1406,7 +1288,6 @@ Expression::ENode *Expression::_parse_expression() { } break; case TK_IDENTIFIER: { - String identifier = tk.value; int cofs = str_ofs; @@ -1419,7 +1300,6 @@ Expression::ENode *Expression::_parse_expression() { func_call->base = self_node; while (true) { - int cofs2 = str_ofs; _get_token(tk); if (tk.type == TK_PARENTHESIS_CLOSE) { @@ -1462,7 +1342,6 @@ Expression::ENode *Expression::_parse_expression() { input->index = input_index; expr = input; } else { - NamedIndexNode *index = alloc_node<NamedIndexNode>(); SelfNode *self_node = alloc_node<SelfNode>(); index->base = self_node; @@ -1472,13 +1351,11 @@ Expression::ENode *Expression::_parse_expression() { } } break; case TK_INPUT: { - InputNode *input = alloc_node<InputNode>(); input->index = tk.value; expr = input; } break; case TK_SELF: { - SelfNode *self = alloc_node<SelfNode>(); expr = self; } break; @@ -1501,7 +1378,6 @@ Expression::ENode *Expression::_parse_expression() { constructor->data_type = bt; while (true) { - int cofs = str_ofs; _get_token(tk); if (tk.type == TK_PARENTHESIS_CLOSE) { @@ -1542,7 +1418,6 @@ Expression::ENode *Expression::_parse_expression() { bifunc->func = BuiltinFunc(int(tk.value)); while (true) { - int cofs = str_ofs; _get_token(tk); if (tk.type == TK_PARENTHESIS_CLOSE) { @@ -1576,7 +1451,6 @@ Expression::ENode *Expression::_parse_expression() { } break; case TK_OP_SUB: { - ExpressionNode e; e.is_op = true; e.op = Variant::OP_NEGATE; @@ -1584,7 +1458,6 @@ Expression::ENode *Expression::_parse_expression() { continue; } break; case TK_OP_NOT: { - ExpressionNode e; e.is_op = true; e.op = Variant::OP_NOT; @@ -1648,7 +1521,6 @@ Expression::ENode *Expression::_parse_expression() { func_call->base = expr; while (true) { - int cofs3 = str_ofs; _get_token(tk); if (tk.type == TK_PARENTHESIS_CLOSE) { @@ -1797,15 +1669,12 @@ Expression::ENode *Expression::_parse_expression() { /* Reduce the set set of expressions and place them in an operator tree, respecting precedence */ while (expression.size() > 1) { - int next_op = -1; int min_priority = 0xFFFFF; bool is_unary = false; for (int i = 0; i < expression.size(); i++) { - if (!expression[i].is_op) { - continue; } @@ -1814,7 +1683,6 @@ Expression::ENode *Expression::_parse_expression() { bool unary = false; switch (expression[i].op) { - case Variant::OP_BIT_NEGATE: priority = 0; unary = true; @@ -1910,17 +1778,14 @@ Expression::ENode *Expression::_parse_expression() { } if (next_op == -1) { - _set_error("Yet another parser bug...."); ERR_FAIL_V(nullptr); } // OK! create operator.. if (is_unary) { - int expr_pos = next_op; while (expression[expr_pos].is_op) { - expr_pos++; if (expr_pos == expression.size()) { //can happen.. @@ -1931,7 +1796,6 @@ Expression::ENode *Expression::_parse_expression() { //consecutively do unary operators for (int i = expr_pos - 1; i >= next_op; i--) { - OperatorNode *op = alloc_node<OperatorNode>(); op->op = expression[i].op; op->nodes[0] = expression[i + 1].node; @@ -1942,7 +1806,6 @@ Expression::ENode *Expression::_parse_expression() { } } else { - if (next_op < 1 || next_op >= (expression.size() - 1)) { _set_error("Parser bug..."); ERR_FAIL_V(nullptr); @@ -1952,7 +1815,6 @@ Expression::ENode *Expression::_parse_expression() { op->op = expression[next_op].op; if (expression[next_op - 1].is_op) { - _set_error("Parser bug..."); ERR_FAIL_V(nullptr); } @@ -1981,7 +1843,6 @@ Expression::ENode *Expression::_parse_expression() { } bool Expression::_compile_expression() { - if (!expression_dirty) return error_set; @@ -2011,10 +1872,8 @@ bool Expression::_compile_expression() { } bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression::ENode *p_node, Variant &r_ret, String &r_error_str) { - switch (p_node->type) { case Expression::ENode::TYPE_INPUT: { - const Expression::InputNode *in = static_cast<const Expression::InputNode *>(p_node); if (in->index < 0 || in->index >= p_inputs.size()) { r_error_str = vformat(RTR("Invalid input %i (not passed) in expression"), in->index); @@ -2023,13 +1882,11 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: r_ret = p_inputs[in->index]; } break; case Expression::ENode::TYPE_CONSTANT: { - const Expression::ConstantNode *c = static_cast<const Expression::ConstantNode *>(p_node); r_ret = c->value; } break; case Expression::ENode::TYPE_SELF: { - if (!p_instance) { r_error_str = RTR("self can't be used because instance is null (not passed)"); return true; @@ -2037,7 +1894,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: r_ret = p_instance; } break; case Expression::ENode::TYPE_OPERATOR: { - const Expression::OperatorNode *op = static_cast<const Expression::OperatorNode *>(p_node); Variant a; @@ -2062,7 +1918,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: } break; case Expression::ENode::TYPE_INDEX: { - const Expression::IndexNode *index = static_cast<const Expression::IndexNode *>(p_node); Variant base; @@ -2085,7 +1940,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: } break; case Expression::ENode::TYPE_NAMED_INDEX: { - const Expression::NamedIndexNode *index = static_cast<const Expression::NamedIndexNode *>(p_node); Variant base; @@ -2107,7 +1961,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: Array arr; arr.resize(array->array.size()); for (int i = 0; i < array->array.size(); i++) { - Variant value; bool ret = _execute(p_inputs, p_instance, array->array[i], value, r_error_str); @@ -2124,7 +1977,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: Dictionary d; for (int i = 0; i < dictionary->dict.size(); i += 2) { - Variant key; bool ret = _execute(p_inputs, p_instance, dictionary->dict[i + 0], key, r_error_str); @@ -2142,7 +1994,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: r_ret = d; } break; case Expression::ENode::TYPE_CONSTRUCTOR: { - const Expression::ConstructorNode *constructor = static_cast<const Expression::ConstructorNode *>(p_node); Vector<Variant> arr; @@ -2151,7 +2002,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: argp.resize(constructor->arguments.size()); for (int i = 0; i < constructor->arguments.size(); i++) { - Variant value; bool ret = _execute(p_inputs, p_instance, constructor->arguments[i], value, r_error_str); @@ -2171,7 +2021,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: } break; case Expression::ENode::TYPE_BUILTIN_FUNC: { - const Expression::BuiltinFuncNode *bifunc = static_cast<const Expression::BuiltinFuncNode *>(p_node); Vector<Variant> arr; @@ -2180,7 +2029,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: argp.resize(bifunc->arguments.size()); for (int i = 0; i < bifunc->arguments.size(); i++) { - Variant value; bool ret = _execute(p_inputs, p_instance, bifunc->arguments[i], value, r_error_str); if (ret) @@ -2199,7 +2047,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: } break; case Expression::ENode::TYPE_CALL: { - const Expression::CallNode *call = static_cast<const Expression::CallNode *>(p_node); Variant base; @@ -2214,7 +2061,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: argp.resize(call->arguments.size()); for (int i = 0; i < call->arguments.size(); i++) { - Variant value; ret = _execute(p_inputs, p_instance, call->arguments[i], value, r_error_str); @@ -2238,7 +2084,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: } Error Expression::parse(const String &p_expression, const Vector<String> &p_input_names) { - if (nodes) { memdelete(nodes); nodes = nullptr; @@ -2266,7 +2111,6 @@ Error Expression::parse(const String &p_expression, const Vector<String> &p_inpu } Variant Expression::execute(Array p_inputs, Object *p_base, bool p_show_error) { - ERR_FAIL_COND_V_MSG(error_set, Variant(), "There was previously a parse error: " + error_str + "."); execution_error = false; @@ -2291,7 +2135,6 @@ String Expression::get_error_text() const { } void Expression::_bind_methods() { - ClassDB::bind_method(D_METHOD("parse", "expression", "input_names"), &Expression::parse, DEFVAL(Vector<String>())); ClassDB::bind_method(D_METHOD("execute", "inputs", "base_instance", "show_error"), &Expression::execute, DEFVAL(Array()), DEFVAL(Variant()), DEFVAL(true)); ClassDB::bind_method(D_METHOD("has_execute_failed"), &Expression::has_execute_failed); @@ -2299,7 +2142,6 @@ void Expression::_bind_methods() { } Expression::~Expression() { - if (nodes) { memdelete(nodes); } diff --git a/core/math/expression.h b/core/math/expression.h index bf710ecdd5..2d67caca44 100644 --- a/core/math/expression.h +++ b/core/math/expression.h @@ -118,7 +118,6 @@ private: static const char *func_name[FUNC_MAX]; struct Input { - Variant::Type type = Variant::NIL; String name; @@ -180,7 +179,6 @@ private: static const char *token_name[TK_MAX]; struct Token { - TokenType type; Variant value; }; @@ -198,7 +196,6 @@ private: bool error_set = true; struct ENode { - enum Type { TYPE_INPUT, TYPE_CONSTANT, @@ -226,7 +223,6 @@ private: }; struct ExpressionNode { - bool is_op; union { Variant::Operator op; @@ -237,7 +233,6 @@ private: ENode *_parse_expression(); struct InputNode : public ENode { - int index; InputNode() { type = TYPE_INPUT; @@ -245,7 +240,6 @@ private: }; struct ConstantNode : public ENode { - Variant value; ConstantNode() { type = TYPE_CONSTANT; @@ -253,7 +247,6 @@ private: }; struct OperatorNode : public ENode { - Variant::Operator op; ENode *nodes[2]; @@ -264,7 +257,6 @@ private: }; struct SelfNode : public ENode { - SelfNode() { type = TYPE_SELF; } diff --git a/core/math/face3.cpp b/core/math/face3.cpp index 74331b391f..e1be4f0acf 100644 --- a/core/math/face3.cpp +++ b/core/math/face3.cpp @@ -33,7 +33,6 @@ #include "core/math/geometry.h" int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_over[3]) const { - ERR_FAIL_COND_V(is_degenerate(), 0); Vector3 above[4]; @@ -43,7 +42,6 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_ int below_count = 0; for (int i = 0; i < 3; i++) { - if (p_plane.has_point(vertex[i], CMP_EPSILON)) { // point is in plane ERR_FAIL_COND_V(above_count >= 4, 0); @@ -52,7 +50,6 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_ below[below_count++] = vertex[i]; } else { - if (p_plane.is_point_over(vertex[i])) { //Point is over ERR_FAIL_COND_V(above_count >= 4, 0); @@ -83,13 +80,11 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_ ERR_FAIL_COND_V(above_count >= 4 && below_count >= 4, 0); //bug in the algo if (above_count >= 3) { - p_res[polygons_created] = Face3(above[0], above[1], above[2]); p_is_point_over[polygons_created] = true; polygons_created++; if (above_count == 4) { - p_res[polygons_created] = Face3(above[2], above[3], above[0]); p_is_point_over[polygons_created] = true; polygons_created++; @@ -97,13 +92,11 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_ } if (below_count >= 3) { - p_res[polygons_created] = Face3(below[0], below[1], below[2]); p_is_point_over[polygons_created] = false; polygons_created++; if (below_count == 4) { - p_res[polygons_created] = Face3(below[2], below[3], below[0]); p_is_point_over[polygons_created] = false; polygons_created++; @@ -114,29 +107,24 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_ } bool Face3::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const { - return Geometry::ray_intersects_triangle(p_from, p_dir, vertex[0], vertex[1], vertex[2], p_intersection); } bool Face3::intersects_segment(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const { - return Geometry::segment_intersects_triangle(p_from, p_dir, vertex[0], vertex[1], vertex[2], p_intersection); } bool Face3::is_degenerate() const { - Vector3 normal = vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]); return (normal.length_squared() < CMP_EPSILON2); } Face3::Side Face3::get_side_of(const Face3 &p_face, ClockDirection p_clock_dir) const { - int over = 0, under = 0; Plane plane = get_plane(p_clock_dir); for (int i = 0; i < 3; i++) { - const Vector3 &v = p_face.vertex[i]; if (plane.has_point(v)) //coplanar, don't bother @@ -159,7 +147,6 @@ Face3::Side Face3::get_side_of(const Face3 &p_face, ClockDirection p_clock_dir) } Vector3 Face3::get_random_point_inside() const { - real_t a = Math::random(0, 1); real_t b = Math::random(0, 1); if (a > b) { @@ -170,29 +157,24 @@ Vector3 Face3::get_random_point_inside() const { } Plane Face3::get_plane(ClockDirection p_dir) const { - return Plane(vertex[0], vertex[1], vertex[2], p_dir); } Vector3 Face3::get_median_point() const { - return (vertex[0] + vertex[1] + vertex[2]) / 3.0; } real_t Face3::get_area() const { - return vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]).length(); } ClockDirection Face3::get_clock_dir() const { - Vector3 normal = vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]); //printf("normal is %g,%g,%g x %g,%g,%g- wtfu is %g\n",tofloat(normal.x),tofloat(normal.y),tofloat(normal.z),tofloat(vertex[0].x),tofloat(vertex[0].y),tofloat(vertex[0].z),tofloat( normal.dot( vertex[0] ) ) ); return (normal.dot(vertex[0]) >= 0) ? CLOCKWISE : COUNTERCLOCKWISE; } bool Face3::intersects_aabb(const AABB &p_aabb) const { - /** TEST PLANE **/ if (!p_aabb.intersects_plane(get_plane())) return false; @@ -228,7 +210,6 @@ bool Face3::intersects_aabb(const AABB &p_aabb) const { }; for (int i = 0; i < 12; i++) { - Vector3 from, to; p_aabb.get_edge(i, from, to); Vector3 e1 = from - to; @@ -253,14 +234,11 @@ bool Face3::intersects_aabb(const AABB &p_aabb) const { } Face3::operator String() const { - return String() + vertex[0] + ", " + vertex[1] + ", " + vertex[2]; } void Face3::project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const { - for (int i = 0; i < 3; i++) { - Vector3 v = p_transform.xform(vertex[i]); real_t d = p_normal.dot(v); @@ -273,7 +251,6 @@ 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_THRESHOLD 0.98 #define _EDGE_IS_VALID_SUPPORT_THRESHOLD 0.05 @@ -284,11 +261,9 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V /** TEST FACE AS SUPPORT **/ if (get_plane().normal.dot(n) > _FACE_IS_VALID_SUPPORT_THRESHOLD) { - *p_count = MIN(3, p_max); for (int i = 0; i < *p_count; i++) { - p_vertices[i] = p_transform.xform(vertex[i]); } @@ -301,7 +276,6 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V real_t support_max = 0; for (int i = 0; i < 3; i++) { - real_t d = n.dot(vertex[i]); if (i == 0 || d > support_max) { @@ -313,7 +287,6 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V /** TEST EDGES AS SUPPORT **/ for (int i = 0; i < 3; i++) { - if (i != vert_support_idx && i + 1 != vert_support_idx) continue; @@ -321,7 +294,6 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V real_t dot = (vertex[i] - vertex[(i + 1) % 3]).normalized().dot(n); dot = ABS(dot); if (dot < _EDGE_IS_VALID_SUPPORT_THRESHOLD) { - *p_count = MIN(2, p_max); for (int j = 0; j < *p_count; j++) @@ -336,7 +308,6 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V } Vector3 Face3::get_closest_point_to(const Vector3 &p_point) const { - Vector3 edge0 = vertex[1] - vertex[0]; Vector3 edge1 = vertex[2] - vertex[0]; Vector3 v0 = vertex[0] - p_point; diff --git a/core/math/face3.h b/core/math/face3.h index da269028f5..eb2b3b8bd5 100644 --- a/core/math/face3.h +++ b/core/math/face3.h @@ -78,7 +78,6 @@ public: void project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const; AABB get_aabb() const { - AABB aabb(vertex[0], Vector3()); aabb.expand_to(vertex[1]); aabb.expand_to(vertex[2]); @@ -98,7 +97,6 @@ public: }; bool Face3::intersects_aabb2(const AABB &p_aabb) const { - Vector3 perp = (vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]); Vector3 half_extents = p_aabb.size * 0.5; @@ -145,17 +143,13 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const { }; for (int i = 0; i < 12; i++) { - Vector3 from, to; switch (i) { - case 0: { - from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z); to = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z); } break; case 1: { - from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z); to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z); } break; @@ -165,18 +159,15 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const { } break; case 3: { - from = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z); to = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z); } break; case 4: { - from = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z); to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z); } break; case 5: { - from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z); to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z); } break; @@ -186,31 +177,26 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const { } break; case 7: { - from = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z); to = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z); } break; case 8: { - from = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z); to = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z); } break; case 9: { - from = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z); to = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z); } break; case 10: { - from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z); to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z); } break; case 11: { - from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z); to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z); @@ -240,7 +226,6 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const { real_t minT = 1e20, maxT = -1e20; for (int k = 0; k < 3; k++) { - real_t vert_d = axis.dot(vertex[k]); if (vert_d > maxT) diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp index f923b62542..3085997225 100644 --- a/core/math/geometry.cpp +++ b/core/math/geometry.cpp @@ -54,13 +54,10 @@ bool Geometry::is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2> */ void Geometry::MeshData::optimize_vertices() { - Map<int, int> vtx_remap; for (int i = 0; i < faces.size(); i++) { - for (int j = 0; j < faces[i].indices.size(); j++) { - int idx = faces[i].indices[j]; if (!vtx_remap.has(idx)) { int ni = vtx_remap.size(); @@ -72,7 +69,6 @@ void Geometry::MeshData::optimize_vertices() { } for (int i = 0; i < edges.size(); i++) { - int a = edges[i].a; int b = edges[i].b; @@ -93,7 +89,6 @@ void Geometry::MeshData::optimize_vertices() { new_vertices.resize(vtx_remap.size()); for (int i = 0; i < vertices.size(); i++) { - if (vtx_remap.has(i)) new_vertices.write[vtx_remap[i]] = vertices[i]; } @@ -101,9 +96,7 @@ void Geometry::MeshData::optimize_vertices() { } struct _FaceClassify { - struct _Link { - int face = -1; int edge = -1; void clear() { @@ -126,42 +119,34 @@ static bool _connect_faces(_FaceClassify *p_faces, int len, int p_group) { bool error = false; for (int i = 0; i < len; i++) { - for (int j = 0; j < 3; j++) { - p_faces[i].links[j].clear(); } } for (int i = 0; i < len; i++) { - if (p_faces[i].group != p_group) continue; for (int j = i + 1; j < len; j++) { - if (p_faces[j].group != p_group) continue; for (int k = 0; k < 3; k++) { - Vector3 vi1 = p_faces[i].face.vertex[k]; Vector3 vi2 = p_faces[i].face.vertex[(k + 1) % 3]; for (int l = 0; l < 3; l++) { - Vector3 vj2 = p_faces[j].face.vertex[l]; Vector3 vj1 = p_faces[j].face.vertex[(l + 1) % 3]; if (vi1.distance_to(vj1) < 0.00001 && vi2.distance_to(vj2) < 0.00001) { if (p_faces[i].links[k].face != -1) { - ERR_PRINT("already linked\n"); error = true; break; } if (p_faces[j].links[l].face != -1) { - ERR_PRINT("already linked\n"); error = true; break; @@ -184,10 +169,8 @@ static bool _connect_faces(_FaceClassify *p_faces, int len, int p_group) { } for (int i = 0; i < len; i++) { - p_faces[i].valid = true; for (int j = 0; j < 3; j++) { - if (p_faces[i].links[j].face == -1) p_faces[i].valid = false; } @@ -196,14 +179,12 @@ static bool _connect_faces(_FaceClassify *p_faces, int len, int p_group) { } static bool _group_face(_FaceClassify *p_faces, int len, int p_index, int p_group) { - if (p_faces[p_index].group >= 0) return false; p_faces[p_index].group = p_group; for (int i = 0; i < 3; i++) { - ERR_FAIL_INDEX_V(p_faces[p_index].links[i].face, len, true); _group_face(p_faces, len, p_faces[p_index].links[i].face, p_group); } @@ -212,7 +193,6 @@ static bool _group_face(_FaceClassify *p_faces, int len, int p_index, int p_grou } Vector<Vector<Face3>> Geometry::separate_objects(Vector<Face3> p_array) { - Vector<Vector<Face3>> objects; int len = p_array.size(); @@ -226,7 +206,6 @@ Vector<Vector<Face3>> Geometry::separate_objects(Vector<Face3> p_array) { _FaceClassify *_fcptr = fc.ptrw(); for (int i = 0; i < len; i++) { - _fcptr[i].face = arrayptr[i]; } @@ -238,7 +217,6 @@ Vector<Vector<Face3>> Geometry::separate_objects(Vector<Face3> p_array) { int group = 0; for (int i = 0; i < len; i++) { - if (!_fcptr[i].valid) continue; if (_group_face(_fcptr, len, i, group)) { @@ -249,12 +227,10 @@ Vector<Vector<Face3>> Geometry::separate_objects(Vector<Face3> p_array) { // Group connected faces in separate objects. for (int i = 0; i < len; i++) { - _fcptr[i].face = arrayptr[i]; } if (group >= 0) { - objects.resize(group); Vector<Face3> *group_faces = objects.ptrw(); @@ -262,7 +238,6 @@ Vector<Vector<Face3>> Geometry::separate_objects(Vector<Face3> p_array) { if (!_fcptr[i].valid) continue; if (_fcptr[i].group >= 0 && _fcptr[i].group < group) { - group_faces[_fcptr[i].group].push_back(_fcptr[i].face); } } @@ -299,7 +274,6 @@ enum _CellFlags { }; static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int len_x, int len_y, int len_z, const Vector3 &voxelsize, const Face3 &p_face) { - AABB aabb(Vector3(x, y, z), Vector3(len_x, len_y, len_z)); aabb.position = aabb.position * voxelsize; aabb.size = aabb.size * voxelsize; @@ -308,7 +282,6 @@ static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int return; if (len_x == 1 && len_y == 1 && len_z == 1) { - p_cell_status[x][y][z] = _CELL_SOLID; return; } @@ -337,15 +310,12 @@ static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int int new_len_z; for (int i = 0; i < div_x; i++) { - _SPLIT(i, div_x, x, len_x, new_x, new_len_x); for (int j = 0; j < div_y; j++) { - _SPLIT(j, div_y, y, len_y, new_y, new_len_y); for (int k = 0; k < div_z; k++) { - _SPLIT(k, div_z, z, len_z, new_z, new_len_z); _plot_face(p_cell_status, new_x, new_y, new_z, new_len_x, new_len_y, new_len_z, voxelsize, p_face); @@ -355,14 +325,12 @@ static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int } static inline void _mark_outside(uint8_t ***p_cell_status, int x, int y, int z, int len_x, int len_y, int len_z) { - if (p_cell_status[x][y][z] & 3) return; // Nothing to do, already used and/or visited. p_cell_status[x][y][z] = _CELL_PREV_FIRST; while (true) { - uint8_t &c = p_cell_status[x][y][z]; if ((c & _CELL_STEP_MASK) == _CELL_STEP_NONE) { @@ -416,9 +384,7 @@ static inline void _mark_outside(uint8_t ***p_cell_status, int x, int y, int z, uint8_t prev = 0; switch (c & _CELL_STEP_MASK) { - case _CELL_STEP_Y_POS: { - next_y++; prev = _CELL_PREV_Y_NEG; } break; @@ -464,7 +430,6 @@ static inline void _mark_outside(uint8_t ***p_cell_status, int x, int y, int z, } static inline void _build_faces(uint8_t ***p_cell_status, int x, int y, int z, int len_x, int len_y, int len_z, Vector<Face3> &p_faces) { - ERR_FAIL_INDEX(x, len_x); ERR_FAIL_INDEX(y, len_y); ERR_FAIL_INDEX(z, len_z); @@ -485,7 +450,6 @@ static inline void _build_faces(uint8_t ***p_cell_status, int x, int y, int z, i }; for (int i = 0; i < 6; i++) { - Vector3 face_points[4]; int disp_x = x + ((i % 3) == 0 ? ((i < 3) ? 1 : -1) : 0); int disp_y = y + (((i - 1) % 3) == 0 ? ((i < 3) ? 1 : -1) : 0); @@ -524,7 +488,6 @@ static inline void _build_faces(uint8_t ***p_cell_status, int x, int y, int z, i } Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) { - #define _MIN_SIZE 1.0 #define _MAX_LENGTH 20 @@ -534,12 +497,9 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) { AABB global_aabb; for (int i = 0; i < face_count; i++) { - if (i == 0) { - global_aabb = faces[i].get_aabb(); } else { - global_aabb.merge_with(faces[i].get_aabb()); } } @@ -573,15 +533,12 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) { uint8_t ***cell_status = memnew_arr(uint8_t **, div_x); for (int i = 0; i < div_x; i++) { - cell_status[i] = memnew_arr(uint8_t *, div_y); for (int j = 0; j < div_y; j++) { - cell_status[i][j] = memnew_arr(uint8_t, div_z); for (int k = 0; k < div_z; k++) { - cell_status[i][j][k] = 0; } } @@ -590,10 +547,8 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) { // Plot faces into cells. for (int i = 0; i < face_count; i++) { - Face3 f = faces[i]; for (int j = 0; j < 3; j++) { - f.vertex[j] -= global_aabb.position; } _plot_face(cell_status, 0, 0, 0, div_x, div_y, div_z, voxelsize, f); @@ -602,27 +557,21 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) { // Determine which cells connect to the outside by traversing the outside and recursively flood-fill marking. for (int i = 0; i < div_x; i++) { - for (int j = 0; j < div_y; j++) { - _mark_outside(cell_status, i, j, 0, div_x, div_y, div_z); _mark_outside(cell_status, i, j, div_z - 1, div_x, div_y, div_z); } } for (int i = 0; i < div_z; i++) { - for (int j = 0; j < div_y; j++) { - _mark_outside(cell_status, 0, j, i, div_x, div_y, div_z); _mark_outside(cell_status, div_x - 1, j, i, div_x, div_y, div_z); } } for (int i = 0; i < div_x; i++) { - for (int j = 0; j < div_z; j++) { - _mark_outside(cell_status, i, 0, j, div_x, div_y, div_z); _mark_outside(cell_status, i, div_y - 1, j, div_x, div_y, div_z); } @@ -633,11 +582,8 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) { Vector<Face3> wrapped_faces; for (int i = 0; i < div_x; i++) { - for (int j = 0; j < div_y; j++) { - for (int k = 0; k < div_z; k++) { - _build_faces(cell_status, i, j, k, div_x, div_y, div_z, wrapped_faces); } } @@ -649,9 +595,7 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) { Face3 *wrapped_faces_ptr = wrapped_faces.ptrw(); for (int i = 0; i < wrapped_faces_count; i++) { - for (int j = 0; j < 3; j++) { - Vector3 &v = wrapped_faces_ptr[i].vertex[j]; v = v * voxelsize; v += global_aabb.position; @@ -661,9 +605,7 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) { // clean up grid for (int i = 0; i < div_x; i++) { - for (int j = 0; j < div_y; j++) { - memdelete_arr(cell_status[i][j]); } @@ -712,14 +654,12 @@ Vector<Vector<Vector2>> Geometry::decompose_polygon_in_convex(Vector<Point2> pol } Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) { - MeshData mesh; #define SUBPLANE_SIZE 1024.0 real_t subplane_size = 1024.0; // Should compute this from the actual plane. for (int i = 0; i < p_planes.size(); i++) { - Plane p = p_planes[i]; Vector3 ref = Vector3(0.0, 1.0, 0.0); @@ -740,7 +680,6 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) { vertices.push_back(center + up * subplane_size + right * subplane_size); for (int j = 0; j < p_planes.size(); j++) { - if (j == i) continue; @@ -754,7 +693,6 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) { break; for (int k = 0; k < vertices.size(); k++) { - int k_n = (k + 1) % vertices.size(); Vector3 edge0_A = vertices[k]; @@ -770,7 +708,6 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) { // Check for different sides and non coplanar. if ((dist0 * dist1) < 0) { - // Calculate intersection. Vector3 rel = edge1_A - edge0_A; @@ -796,19 +733,15 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) { // Add face indices. for (int j = 0; j < vertices.size(); j++) { - int idx = -1; for (int k = 0; k < mesh.vertices.size(); k++) { - if (mesh.vertices[k].distance_to(vertices[j]) < 0.001) { - idx = k; break; } } if (idx == -1) { - idx = mesh.vertices.size(); mesh.vertices.push_back(vertices[j]); } @@ -821,13 +754,11 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) { // Add edge. for (int j = 0; j < face.indices.size(); j++) { - int a = face.indices[j]; int b = face.indices[(j + 1) % face.indices.size()]; bool found = false; for (int k = 0; k < mesh.edges.size(); k++) { - if (mesh.edges[k].a == a && mesh.edges[k].b == b) { found = true; break; @@ -851,7 +782,6 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) { } Vector<Plane> Geometry::build_box_planes(const Vector3 &p_extents) { - Vector<Plane> planes; planes.push_back(Plane(Vector3(1, 0, 0), p_extents.x)); @@ -865,11 +795,9 @@ Vector<Plane> Geometry::build_box_planes(const Vector3 &p_extents) { } Vector<Plane> Geometry::build_cylinder_planes(real_t p_radius, real_t p_height, int p_sides, Vector3::Axis p_axis) { - Vector<Plane> planes; for (int i = 0; i < p_sides; i++) { - Vector3 normal; normal[(p_axis + 1) % 3] = Math::cos(i * (2.0 * Math_PI) / p_sides); normal[(p_axis + 2) % 3] = Math::sin(i * (2.0 * Math_PI) / p_sides); @@ -887,7 +815,6 @@ Vector<Plane> Geometry::build_cylinder_planes(real_t p_radius, real_t p_height, } Vector<Plane> Geometry::build_sphere_planes(real_t p_radius, int p_lats, int p_lons, Vector3::Axis p_axis) { - Vector<Plane> planes; Vector3 axis; @@ -899,7 +826,6 @@ Vector<Plane> Geometry::build_sphere_planes(real_t p_radius, int p_lats, int p_l axis_neg[p_axis] = -1.0; for (int i = 0; i < p_lons; i++) { - Vector3 normal; normal[(p_axis + 1) % 3] = Math::cos(i * (2.0 * Math_PI) / p_lons); normal[(p_axis + 2) % 3] = Math::sin(i * (2.0 * Math_PI) / p_lons); @@ -907,7 +833,6 @@ Vector<Plane> Geometry::build_sphere_planes(real_t p_radius, int p_lats, int p_l planes.push_back(Plane(normal, p_radius)); for (int j = 1; j <= p_lats; j++) { - // FIXME: This is stupid. Vector3 angle = normal.lerp(axis, j / (real_t)p_lats).normalized(); Vector3 pos = angle * p_radius; @@ -920,7 +845,6 @@ Vector<Plane> Geometry::build_sphere_planes(real_t p_radius, int p_lats, int p_l } Vector<Plane> Geometry::build_capsule_planes(real_t p_radius, real_t p_height, int p_sides, int p_lats, Vector3::Axis p_axis) { - Vector<Plane> planes; Vector3 axis; @@ -932,7 +856,6 @@ Vector<Plane> Geometry::build_capsule_planes(real_t p_radius, real_t p_height, i axis_neg[p_axis] = -1.0; for (int i = 0; i < p_sides; i++) { - Vector3 normal; normal[(p_axis + 1) % 3] = Math::cos(i * (2.0 * Math_PI) / p_sides); normal[(p_axis + 2) % 3] = Math::sin(i * (2.0 * Math_PI) / p_sides); @@ -940,7 +863,6 @@ Vector<Plane> Geometry::build_capsule_planes(real_t p_radius, real_t p_height, i planes.push_back(Plane(normal, p_radius)); for (int j = 1; j <= p_lats; j++) { - Vector3 angle = normal.lerp(axis, j / (real_t)p_lats).normalized(); Vector3 pos = axis * p_height * 0.5 + angle * p_radius; planes.push_back(Plane(pos, angle)); @@ -952,7 +874,6 @@ Vector<Plane> Geometry::build_capsule_planes(real_t p_radius, real_t p_height, i } struct _AtlasWorkRect { - Size2i s; Point2i p; int idx; @@ -960,14 +881,12 @@ struct _AtlasWorkRect { }; struct _AtlasWorkRectResult { - Vector<_AtlasWorkRect> result; int max_w; int max_h; }; void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_result, Size2i &r_size) { - // Super simple, almost brute force scanline stacking fitter. // It's pretty basic for now, but it tries to make sure that the aspect ratio of the // resulting atlas is somehow square. This is necessary because video cards have limits. @@ -990,7 +909,6 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu Vector<_AtlasWorkRectResult> results; for (int i = 0; i <= 12; i++) { - int w = 1 << i; int max_h = 0; int max_w = 0; @@ -1006,15 +924,12 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu int ofs = 0; int limit_h = 0; for (int j = 0; j < wrects.size(); j++) { - if (ofs + wrects[j].s.width > w) { - ofs = 0; } int from_y = 0; for (int k = 0; k < wrects[j].s.width; k++) { - if (hmax[ofs + k] > from_y) from_y = hmax[ofs + k]; } @@ -1027,7 +942,6 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu limit_h = end_h; for (int k = 0; k < wrects[j].s.width; k++) { - hmax.write[ofs + k] = end_h; } @@ -1054,7 +968,6 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu real_t best_aspect = 1e20; for (int i = 0; i < results.size(); i++) { - real_t h = next_power_of_2(results[i].max_h); real_t w = next_power_of_2(results[i].max_w); real_t aspect = h > w ? h / w : w / h; @@ -1067,7 +980,6 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu r_result.resize(p_rects.size()); for (int i = 0; i < p_rects.size(); i++) { - r_result.write[results[best].result[i].idx] = results[best].result[i].p; } @@ -1075,7 +987,6 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu } Vector<Vector<Point2>> Geometry::_polypaths_do_operation(PolyBooleanOperation p_op, const Vector<Point2> &p_polypath_a, const Vector<Point2> &p_polypath_b, bool is_a_open) { - using namespace ClipperLib; ClipType op = ctUnion; @@ -1135,7 +1046,6 @@ Vector<Vector<Point2>> Geometry::_polypaths_do_operation(PolyBooleanOperation p_ } Vector<Vector<Point2>> Geometry::_polypath_offset(const Vector<Point2> &p_polypath, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) { - using namespace ClipperLib; JoinType jt = jtSquare; @@ -1202,19 +1112,16 @@ Vector<Vector<Point2>> Geometry::_polypath_offset(const Vector<Point2> &p_polypa } Vector<Vector3> Geometry::compute_convex_mesh_points(const Plane *p_planes, int p_plane_count) { - Vector<Vector3> points; // Iterate through every unique combination of any three planes. for (int i = p_plane_count - 1; i >= 0; i--) { for (int j = i - 1; j >= 0; j--) { for (int k = j - 1; k >= 0; k--) { - // Find the point where these planes all cross over (if they // do at all). Vector3 convex_shape_point; if (p_planes[i].intersect_3(p_planes[j], p_planes[k], &convex_shape_point)) { - // See if any *other* plane excludes this point because it's // on the wrong side. bool excluded = false; @@ -1241,7 +1148,6 @@ Vector<Vector3> Geometry::compute_convex_mesh_points(const Plane *p_planes, int } Vector<Point2i> Geometry::pack_rects(const Vector<Size2i> &p_sizes, const Size2i &p_atlas_size) { - Vector<stbrp_node> nodes; nodes.resize(p_atlas_size.width); @@ -1277,7 +1183,6 @@ Vector<Point2i> Geometry::pack_rects(const Vector<Size2i> &p_sizes, const Size2i } Vector<Vector3i> Geometry::partial_pack_rects(const Vector<Vector2i> &p_sizes, const Size2i &p_atlas_size) { - Vector<stbrp_node> nodes; nodes.resize(p_atlas_size.width); zeromem(nodes.ptrw(), sizeof(stbrp_node) * nodes.size()); @@ -1314,7 +1219,6 @@ Vector<Vector3i> Geometry::partial_pack_rects(const Vector<Vector2i> &p_sizes, c /* dt of 1d function using squared distance */ static void edt(float *f, int stride, int n) { - float *d = (float *)alloca(sizeof(float) * n + sizeof(int) * n + sizeof(float) * (n + 1)); int *v = (int *)&(d[n]); float *z = (float *)&v[n]; @@ -1351,7 +1255,6 @@ static void edt(float *f, int stride, int n) { #undef square Vector<uint32_t> Geometry::generate_edf(const Vector<bool> &p_voxels, const Vector3i &p_size, bool p_negative) { - uint32_t float_count = p_size.x * p_size.y * p_size.z; ERR_FAIL_COND_V((uint32_t)p_voxels.size() != float_count, Vector<uint32_t>()); @@ -1368,7 +1271,6 @@ Vector<uint32_t> Geometry::generate_edf(const Vector<bool> &p_voxels, const Vect { const bool *voxr = p_voxels.ptr(); for (uint32_t i = 0; i < float_count; i++) { - bool plot = voxr[i]; if (p_negative) { plot = !plot; diff --git a/core/math/geometry.h b/core/math/geometry.h index b90cae3786..b52b081016 100644 --- a/core/math/geometry.h +++ b/core/math/geometry.h @@ -45,7 +45,6 @@ class Geometry { public: static real_t get_closest_points_between_segments(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2, Vector2 &c1, Vector2 &c2) { - Vector2 d1 = q1 - p1; // Direction vector of segment S1. Vector2 d2 = q2 - p2; // Direction vector of segment S2. Vector2 r = p1 - p2; @@ -103,7 +102,6 @@ public: } static void get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2, Vector3 &c1, Vector3 &c2) { - // Do the function 'd' as defined by pb. I think is is dot product of some sort. #define d_of(m, n, o, p) ((m.x - n.x) * (o.x - p.x) + (m.y - n.y) * (o.y - p.y) + (m.z - n.z) * (o.z - p.z)) @@ -226,7 +224,6 @@ public: } static inline bool segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2, Vector3 *r_res = nullptr) { - Vector3 rel = p_to - p_from; Vector3 e1 = p_v1 - p_v0; Vector3 e2 = p_v2 - p_v0; @@ -263,7 +260,6 @@ public: } static inline bool segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius, Vector3 *r_res = nullptr, Vector3 *r_norm = nullptr) { - Vector3 sphere_pos = p_sphere_pos - p_from; Vector3 rel = (p_to - p_from); real_t rel_l = rel.length(); @@ -299,7 +295,6 @@ public: } static inline bool segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, real_t p_height, real_t p_radius, Vector3 *r_res = nullptr, Vector3 *r_norm = nullptr) { - Vector3 rel = (p_to - p_from); real_t rel_l = rel.length(); if (rel_l < CMP_EPSILON) @@ -339,7 +334,6 @@ public: int axis = -1; for (int i = 0; i < 2; i++) { - real_t seg_from = from2D[i]; real_t seg_to = to2D[i]; real_t box_begin = -size[i]; @@ -347,7 +341,6 @@ public: real_t cmin, cmax; if (seg_from < seg_to) { - if (seg_from > box_end || seg_to < box_begin) return false; real_t length = seg_to - seg_from; @@ -355,7 +348,6 @@ public: cmax = (seg_to > box_end) ? ((box_end - seg_from) / length) : 1; } else { - if (seg_to > box_end || seg_from < box_begin) return false; real_t length = seg_to - seg_from; @@ -395,7 +387,6 @@ public: } static bool segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Plane *p_planes, int p_plane_count, Vector3 *p_res, Vector3 *p_norm) { - real_t min = -1e20, max = 1e20; Vector3 rel = p_to - p_from; @@ -409,7 +400,6 @@ public: int min_index = -1; for (int i = 0; i < p_plane_count; i++) { - const Plane &p = p_planes[i]; real_t den = p.normal.dot(dir); @@ -424,7 +414,6 @@ public: if (dist < max) max = dist; } else { - // Front facing plane. if (dist > min) { min = dist; @@ -445,7 +434,6 @@ public: } static Vector3 get_closest_point_to_segment(const Vector3 &p_point, const Vector3 *p_segment) { - Vector3 p = p_point - p_segment[0]; Vector3 n = p_segment[1] - p_segment[0]; real_t l2 = n.length_squared(); @@ -463,7 +451,6 @@ public: } static Vector3 get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 *p_segment) { - Vector3 p = p_point - p_segment[0]; Vector3 n = p_segment[1] - p_segment[0]; real_t l2 = n.length_squared(); @@ -476,7 +463,6 @@ public: } static Vector2 get_closest_point_to_segment_2d(const Vector2 &p_point, const Vector2 *p_segment) { - Vector2 p = p_point - p_segment[0]; Vector2 n = p_segment[1] - p_segment[0]; real_t l2 = n.length_squared(); @@ -507,7 +493,6 @@ public: } static Vector2 get_closest_point_to_segment_uncapped_2d(const Vector2 &p_point, const Vector2 *p_segment) { - Vector2 p = p_point - p_segment[0]; Vector2 n = p_segment[1] - p_segment[0]; real_t l2 = n.length_squared(); @@ -520,7 +505,6 @@ public: } static bool line_intersects_line_2d(const Vector2 &p_from_a, const Vector2 &p_dir_a, const Vector2 &p_from_b, const Vector2 &p_dir_b, Vector2 &r_result) { - // See http://paulbourke.net/geometry/pointlineplane/ const real_t denom = p_dir_b.y * p_dir_a.x - p_dir_b.x * p_dir_a.y; @@ -535,7 +519,6 @@ public: } static bool segment_intersects_segment_2d(const Vector2 &p_from_a, const Vector2 &p_to_a, const Vector2 &p_from_b, const Vector2 &p_to_b, Vector2 *r_result) { - Vector2 B = p_to_a - p_from_a; Vector2 C = p_from_b - p_from_a; Vector2 D = p_to_b - p_from_a; @@ -564,7 +547,6 @@ public: } static inline bool point_in_projected_triangle(const Vector3 &p_point, const Vector3 &p_v1, const Vector3 &p_v2, const Vector3 &p_v3) { - Vector3 face_n = (p_v1 - p_v3).cross(p_v1 - p_v2); Vector3 n1 = (p_point - p_v3).cross(p_point - p_v2); @@ -586,7 +568,6 @@ public: } static inline bool triangle_sphere_intersection_test(const Vector3 *p_triangle, const Vector3 &p_normal, const Vector3 &p_sphere_pos, real_t p_sphere_radius, Vector3 &r_triangle_contact, Vector3 &r_sphere_contact) { - real_t d = p_normal.dot(p_sphere_pos) - p_normal.dot(p_triangle[0]); if (d > p_sphere_radius || d < -p_sphere_radius) // Not touching the plane of the face, return. @@ -608,7 +589,6 @@ public: const Vector3 verts[4] = { p_triangle[0], p_triangle[1], p_triangle[2], p_triangle[0] }; // for() friendly for (int i = 0; i < 3; i++) { - // Check edge cylinder. Vector3 n1 = verts[i] - verts[i + 1]; @@ -633,7 +613,6 @@ public: real_t sphere_at = n1.dot(n2); if (sphere_at >= 0 && sphere_at < n1.dot(n1)) { - r_triangle_contact = p_sphere_pos - axis * (axis.dot(n2)); r_sphere_contact = p_sphere_pos - axis * p_sphere_radius; // Point inside here. @@ -643,7 +622,6 @@ public: real_t r2 = p_sphere_radius * p_sphere_radius; if (n2.length_squared() < r2) { - Vector3 n = (p_sphere_pos - verts[i + 1]).normalized(); r_triangle_contact = verts[i + 1]; @@ -666,12 +644,10 @@ public: } static inline bool is_point_in_circle(const Vector2 &p_point, const Vector2 &p_circle_pos, real_t p_circle_radius) { - return p_point.distance_squared_to(p_circle_pos) <= p_circle_radius * p_circle_radius; } static real_t segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius) { - Vector2 line_vec = p_to - p_from; Vector2 vec_to_line = p_from - p_circle_pos; @@ -704,7 +680,6 @@ public: } static inline Vector<Vector3> clip_polygon(const Vector<Vector3> &polygon, const Plane &p_plane) { - enum LocationCache { LOC_INSIDE = 1, LOC_BOUNDARY = 0, @@ -734,11 +709,9 @@ public: } if (outside_count == 0) { - return polygon; // No changes. } else if (inside_count == 0) { - return Vector<Vector3>(); // Empty. } @@ -798,49 +771,40 @@ public: }; static Vector<Vector<Point2>> merge_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) { - return _polypaths_do_operation(OPERATION_UNION, p_polygon_a, p_polygon_b); } static Vector<Vector<Point2>> clip_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) { - return _polypaths_do_operation(OPERATION_DIFFERENCE, p_polygon_a, p_polygon_b); } static Vector<Vector<Point2>> intersect_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) { - return _polypaths_do_operation(OPERATION_INTERSECTION, p_polygon_a, p_polygon_b); } static Vector<Vector<Point2>> exclude_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) { - return _polypaths_do_operation(OPERATION_XOR, p_polygon_a, p_polygon_b); } static Vector<Vector<Point2>> clip_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) { - return _polypaths_do_operation(OPERATION_DIFFERENCE, p_polyline, p_polygon, true); } static Vector<Vector<Point2>> intersect_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) { - return _polypaths_do_operation(OPERATION_INTERSECTION, p_polyline, p_polygon, true); } static Vector<Vector<Point2>> offset_polygon_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type) { - return _polypath_offset(p_polygon, p_delta, p_join_type, END_POLYGON); } static Vector<Vector<Point2>> offset_polyline_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) { - ERR_FAIL_COND_V_MSG(p_end_type == END_POLYGON, Vector<Vector<Point2>>(), "Attempt to offset a polyline like a polygon (use offset_polygon_2d instead)."); return _polypath_offset(p_polygon, p_delta, p_join_type, p_end_type); } static Vector<int> triangulate_delaunay_2d(const Vector<Vector2> &p_points) { - Vector<Delaunay2D::Triangle> tr = Delaunay2D::triangulate(p_points); Vector<int> triangles; @@ -853,7 +817,6 @@ public: } static Vector<int> triangulate_polygon(const Vector<Vector2> &p_polygon) { - Vector<int> triangles; if (!Triangulate::triangulate(p_polygon, triangles)) return Vector<int>(); //fail @@ -912,7 +875,6 @@ public: static Vector<Face3> wrap_geometry(Vector<Face3> p_array, real_t *p_error = nullptr); struct MeshData { - struct Face { Plane plane; Vector<int> indices; @@ -921,7 +883,6 @@ public: Vector<Face> faces; struct Edge { - int a, b; }; @@ -933,7 +894,6 @@ public: }; _FORCE_INLINE_ static int get_uv84_normal_bit(const Vector3 &p_vector) { - int lat = Math::fast_ftoi(Math::floor(Math::acos(p_vector.dot(Vector3(0, 1, 0))) * 4.0 / Math_PI + 0.5)); if (lat == 0) { @@ -948,13 +908,11 @@ public: } _FORCE_INLINE_ static int get_uv84_normal_bit_neighbors(int p_idx) { - if (p_idx == 24) { return 1 | 2 | 4 | 8; } else if (p_idx == 25) { return (1 << 23) | (1 << 22) | (1 << 21) | (1 << 20); } else { - int ret = 0; if ((p_idx % 8) == 0) ret |= (1 << (p_idx + 7)); @@ -1143,7 +1101,6 @@ public: return false; _FORCE_INLINE_ static bool triangle_box_overlap(const Vector3 &boxcenter, const Vector3 boxhalfsize, const Vector3 *triverts) { - /* use separating axis theorem to test overlap between triangle and box */ /* need to test for overlap in these directions: */ /* 1) the {x,y,z}-directions (actually, since we use the AABB of the triangle */ diff --git a/core/math/math_fieldwise.cpp b/core/math/math_fieldwise.cpp index a47d4ef7ad..ef2a0c5339 100644 --- a/core/math/math_fieldwise.cpp +++ b/core/math/math_fieldwise.cpp @@ -41,7 +41,6 @@ } Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const String &p_field) { - ERR_FAIL_COND_V(p_target.get_type() != p_source.get_type(), p_target); /* clang-format makes a mess of this macro usage */ diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index 7417e64ac1..0c7a97e5c9 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -130,7 +130,6 @@ double Math::stepify(double p_value, double p_step) { } uint32_t Math::larger_prime(uint32_t p_val) { - static const uint32_t primes[] = { 5, 13, @@ -166,7 +165,6 @@ uint32_t Math::larger_prime(uint32_t p_val) { int idx = 0; while (true) { - ERR_FAIL_COND_V(primes[idx] == 0, 0); if (primes[idx] > p_val) return primes[idx]; diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index bd13c82894..33a7d602c3 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -41,7 +41,6 @@ #include <math.h> class Math { - static RandomPCG default_rand; public: @@ -328,7 +327,6 @@ public: } static _ALWAYS_INLINE_ float absf(float g) { - union { float f; uint32_t i; @@ -340,7 +338,6 @@ public: } static _ALWAYS_INLINE_ double absd(double g) { - union { double d; uint64_t i; @@ -352,7 +349,6 @@ public: //this function should be as fast as possible and rounding mode should not matter static _ALWAYS_INLINE_ int fast_ftoi(float a) { - static int b; #if (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0603) || WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP // windows 8 phone? @@ -407,7 +403,6 @@ public: } static _ALWAYS_INLINE_ float halfptr_to_float(const uint16_t *h) { - union { uint32_t u32; float f32; @@ -422,7 +417,6 @@ public: } static _ALWAYS_INLINE_ uint16_t make_half_float(float f) { - union { float fv; uint32_t ui; @@ -453,7 +447,6 @@ public: } // check if exponent is <= -15 else if (exp <= 0x38000000) { - /*// store a denorm half-float value or zero exp = (0x38000000 - exp) >> 23; mantissa >>= (14 + exp); diff --git a/core/math/octree.h b/core/math/octree.h index 7d89c50f69..0782a39804 100644 --- a/core/math/octree.h +++ b/core/math/octree.h @@ -68,7 +68,6 @@ private: }; struct PairKey { - union { struct { OctreeElementID A; @@ -78,18 +77,14 @@ private: }; _FORCE_INLINE_ bool operator<(const PairKey &p_pair) const { - return key < p_pair.key; } _FORCE_INLINE_ PairKey(OctreeElementID p_A, OctreeElementID p_B) { - if (p_A < p_B) { - A = p_A; B = p_B; } else { - B = p_A; A = p_B; } @@ -101,7 +96,6 @@ private: struct Element; struct Octant { - // cached for FAST plane check AABB aabb; @@ -122,7 +116,6 @@ private: struct PairData; struct Element { - Octree *octree = nullptr; T *userdata = nullptr; @@ -141,7 +134,6 @@ private: List<PairData *, AL> pair_list; struct OctantOwner { - Octant *octant; typename List<Element *, AL>::Element *E; }; // an element can be in max 8 octants @@ -152,7 +144,6 @@ private: }; struct PairData { - int refcount; bool intersect; Element *A, *B; @@ -179,19 +170,15 @@ private: int pair_count; _FORCE_INLINE_ void _pair_check(PairData *p_pair) { - bool intersect = p_pair->A->aabb.intersects_inclusive(p_pair->B->aabb); if (intersect != p_pair->intersect) { - if (intersect) { - if (pair_callback) { p_pair->ud = pair_callback(pair_callback_userdata, p_pair->A->_id, p_pair->A->userdata, p_pair->A->subindex, p_pair->B->_id, p_pair->B->userdata, p_pair->B->subindex); } pair_count++; } else { - if (unpair_callback) { unpair_callback(pair_callback_userdata, p_pair->A->_id, p_pair->A->userdata, p_pair->A->subindex, p_pair->B->_id, p_pair->B->userdata, p_pair->B->subindex, p_pair->ud); } @@ -203,7 +190,6 @@ private: } _FORCE_INLINE_ void _pair_reference(Element *p_A, Element *p_B) { - if (p_A == p_B || (p_A->userdata == p_B->userdata && p_A->userdata)) return; @@ -215,7 +201,6 @@ private: typename PairMap::Element *E = pair_map.find(key); if (!E) { - PairData pdata; pdata.refcount = 1; pdata.A = p_A; @@ -230,13 +215,11 @@ private: pair_callback(pair_callback_userdata,p_A->userdata,p_B->userdata); */ } else { - E->get().refcount++; } } _FORCE_INLINE_ void _pair_unreference(Element *p_A, Element *p_B) { - if (p_A == p_B) return; @@ -271,24 +254,18 @@ private: } _FORCE_INLINE_ void _element_check_pairs(Element *p_element) { - typename List<PairData *, AL>::Element *E = p_element->pair_list.front(); while (E) { - _pair_check(E->get()); E = E->next(); } } _FORCE_INLINE_ void _optimize() { - while (root && root->children_count < 2 && !root->elements.size() && !(use_pairs && root->pairable_elements.size())) { - Octant *new_root = nullptr; if (root->children_count == 1) { - for (int i = 0; i < 8; i++) { - if (root->children[i]) { new_root = root->children[i]; root->children[i] = nullptr; @@ -314,7 +291,6 @@ private: void _unpair_element(Element *p_element, Octant *p_octant); struct _CullConvexData { - const Plane *planes; int plane_count; const Vector3 *points; @@ -331,12 +307,10 @@ private: void _cull_point(Octant *p_octant, const Vector3 &p_point, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask); void _remove_tree(Octant *p_octant) { - if (!p_octant) return; for (int i = 0; i < 8; i++) { - if (p_octant->children[i]) _remove_tree(p_octant->children[i]); } @@ -380,7 +354,6 @@ T *Octree<T, use_pairs, AL>::get(OctreeElementID p_id) const { template <class T, bool use_pairs, class AL> bool Octree<T, use_pairs, AL>::is_pairable(OctreeElementID p_id) const { - const typename ElementMap::Element *E = element_map.find(p_id); ERR_FAIL_COND_V(!E, false); return E->get().pairable; @@ -388,7 +361,6 @@ bool Octree<T, use_pairs, AL>::is_pairable(OctreeElementID p_id) const { template <class T, bool use_pairs, class AL> int Octree<T, use_pairs, AL>::get_subindex(OctreeElementID p_id) const { - const typename ElementMap::Element *E = element_map.find(p_id); ERR_FAIL_COND_V(!E, -1); return E->get().subindex; @@ -398,7 +370,6 @@ int Octree<T, use_pairs, AL>::get_subindex(OctreeElementID p_id) const { template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_octant) { - real_t element_size = p_element->aabb.get_longest_axis_size() * 1.01; // avoid precision issues if (p_octant->aabb.size.x / OCTREE_DIVISOR < element_size) { @@ -409,11 +380,9 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct owner.octant = p_octant; if (use_pairs && p_element->pairable) { - p_octant->pairable_elements.push_back(p_element); owner.E = p_octant->pairable_elements.back(); } else { - p_octant->elements.push_back(p_element); owner.E = p_octant->elements.back(); } @@ -428,11 +397,9 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct } if (use_pairs && p_octant->children_count > 0) { - pass++; //elements below this only get ONE reference added for (int i = 0; i < 8; i++) { - if (p_octant->children[i]) { _pair_element(p_element, p_octant->children[i]); } @@ -444,7 +411,6 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct bool candidate = p_element->common_parent == nullptr; for (int i = 0; i < 8; i++) { - if (p_octant->children[i]) { /* element exists, go straight to it */ if (p_octant->children[i]->aabb.intersects_inclusive(p_element->aabb)) { @@ -484,13 +450,11 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct } if (candidate && splits > 1) { - p_element->common_parent = p_octant; } } if (use_pairs) { - typename List<Element *, AL>::Element *E = p_octant->pairable_elements.front(); while (E) { @@ -511,14 +475,12 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::_ensure_valid_root(const AABB &p_aabb) { - if (!root) { // octre is empty AABB base(Vector3(), Vector3(1.0, 1.0, 1.0) * unit_size); while (!base.encloses(p_aabb)) { - if (ABS(base.position.x + base.size.x) <= ABS(base.position.x)) { /* grow towards positive */ base.size *= 2.0; @@ -537,11 +499,9 @@ void Octree<T, use_pairs, AL>::_ensure_valid_root(const AABB &p_aabb) { octant_count++; } else { - AABB base = root->aabb; while (!base.encloses(p_aabb)) { - ERR_FAIL_COND_MSG(base.size.x > OCTREE_SIZE_LIMIT, "Octree upper size limit reached, does the AABB supplied contain NAN?"); Octant *gp = memnew_allocator(Octant, AL); @@ -570,11 +530,9 @@ void Octree<T, use_pairs, AL>::_ensure_valid_root(const AABB &p_aabb) { template <class T, bool use_pairs, class AL> bool Octree<T, use_pairs, AL>::_remove_element_from_octant(Element *p_element, Octant *p_octant, Octant *p_limit) { - bool octant_removed = false; while (true) { - // check all exit conditions if (p_octant == p_limit) // reached limit, nothing to erase, exit @@ -607,7 +565,6 @@ bool Octree<T, use_pairs, AL>::_remove_element_from_octant(Element *p_element, O Octant *parent = p_octant->parent; if (p_octant->children_count == 0 && p_octant->elements.empty() && p_octant->pairable_elements.empty()) { - // erase octant if (p_octant == root) { // won't have a parent, just erase @@ -637,7 +594,6 @@ bool Octree<T, use_pairs, AL>::_remove_element_from_octant(Element *p_element, O template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::_unpair_element(Element *p_element, Octant *p_octant) { - // always test pairable typename List<Element *, AL>::Element *E = p_octant->pairable_elements.front(); while (E) { @@ -666,7 +622,6 @@ void Octree<T, use_pairs, AL>::_unpair_element(Element *p_element, Octant *p_oct return; // small optimization for leafs for (int i = 0; i < 8; i++) { - if (p_octant->children[i]) _unpair_element(p_element, p_octant->children[i]); } @@ -674,13 +629,11 @@ void Octree<T, use_pairs, AL>::_unpair_element(Element *p_element, Octant *p_oct template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::_pair_element(Element *p_element, Octant *p_octant) { - // always test pairable typename List<Element *, AL>::Element *E = p_octant->pairable_elements.front(); while (E) { - if (E->get()->last_pass != pass) { // only get ONE reference _pair_reference(p_element, E->get()); E->get()->last_pass = pass; @@ -705,7 +658,6 @@ void Octree<T, use_pairs, AL>::_pair_element(Element *p_element, Octant *p_octan return; // small optimization for leafs for (int i = 0; i < 8; i++) { - if (p_octant->children[i]) _pair_element(p_element, p_octant->children[i]); } @@ -713,14 +665,12 @@ void Octree<T, use_pairs, AL>::_pair_element(Element *p_element, Octant *p_octan template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::_remove_element(Element *p_element) { - pass++; // will do a new pass for this typename List<typename Element::OctantOwner, AL>::Element *I = p_element->octant_owners.front(); /* FIRST remove going up normally */ for (; I; I = I->next()) { - Octant *o = I->get().octant; if (!use_pairs) // small speedup @@ -734,15 +684,12 @@ void Octree<T, use_pairs, AL>::_remove_element(Element *p_element) { I = p_element->octant_owners.front(); if (use_pairs) { - for (; I; I = I->next()) { - Octant *o = I->get().octant; // erase children pairs, they are erased ONCE even if repeated pass++; for (int i = 0; i < 8; i++) { - if (o->children[i]) _unpair_element(p_element, o->children[i]); } @@ -757,7 +704,6 @@ void Octree<T, use_pairs, AL>::_remove_element(Element *p_element) { p_element->octant_owners.clear(); if (use_pairs) { - int remaining = p_element->pair_list.size(); //p_element->pair_list.clear(); ERR_FAIL_COND(remaining); @@ -766,7 +712,6 @@ void Octree<T, use_pairs, AL>::_remove_element(Element *p_element) { template <class T, bool use_pairs, class AL> OctreeElementID Octree<T, use_pairs, AL>::create(T *p_userdata, const AABB &p_aabb, int p_subindex, bool p_pairable, uint32_t p_pairable_type, uint32_t p_pairable_mask) { - // check for AABB validity #ifdef DEBUG_ENABLED ERR_FAIL_COND_V(p_aabb.position.x > 1e15 || p_aabb.position.x < -1e15, 0); @@ -806,7 +751,6 @@ OctreeElementID Octree<T, use_pairs, AL>::create(T *p_userdata, const AABB &p_aa template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) { - #ifdef DEBUG_ENABLED // check for AABB validity ERR_FAIL_COND(p_aabb.position.x > 1e15 || p_aabb.position.x < -1e15); @@ -827,7 +771,6 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) { bool new_has_surf = !p_aabb.has_no_surface(); if (old_has_surf != new_has_surf) { - if (old_has_surf) { _remove_element(&e); // removing e.common_parent = nullptr; @@ -850,7 +793,6 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) { // it still is enclosed in the same AABB it was assigned to if (e.container_aabb.encloses(p_aabb)) { - e.aabb = p_aabb; if (use_pairs) _element_check_pairs(&e); // must check pairs anyway @@ -888,7 +830,6 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) { pass++; for (typename List<typename Element::OctantOwner, AL>::Element *F = owners.front(); F;) { - Octant *o = F->get().octant; typename List<typename Element::OctantOwner, AL>::Element *N = F->next(); @@ -903,7 +844,6 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) { o->elements.erase(F->get().E); if (_remove_element_from_octant(&e, o, common_parent->parent)) { - owners.erase(F); } @@ -913,13 +853,11 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) { if (use_pairs) { //unpair child elements in anything that survived for (typename List<typename Element::OctantOwner, AL>::Element *F = owners.front(); F; F = F->next()) { - Octant *o = F->get().octant; // erase children pairs, unref ONCE pass++; for (int i = 0; i < 8; i++) { - if (o->children[i]) _unpair_element(&e, o->children[i]); } @@ -933,7 +871,6 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) { template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::set_pairable(OctreeElementID p_id, bool p_pairable, uint32_t p_pairable_type, uint32_t p_pairable_mask) { - typename ElementMap::Element *E = element_map.find(p_id); ERR_FAIL_COND(!E); @@ -961,14 +898,12 @@ void Octree<T, use_pairs, AL>::set_pairable(OctreeElementID p_id, bool p_pairabl template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::erase(OctreeElementID p_id) { - typename ElementMap::Element *E = element_map.find(p_id); ERR_FAIL_COND(!E); Element &e = E->get(); if (!e.aabb.has_no_surface()) { - _remove_element(&e); } @@ -978,17 +913,14 @@ void Octree<T, use_pairs, AL>::erase(OctreeElementID p_id) { template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p_cull) { - if (*p_cull->result_idx == p_cull->result_max) return; //pointless if (!p_octant->elements.empty()) { - typename List<Element *, AL>::Element *I; I = p_octant->elements.front(); for (; I; I = I->next()) { - Element *e = I->get(); if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_cull->mask))) @@ -1000,7 +932,6 @@ void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p p_cull->result_array[*p_cull->result_idx] = e->userdata; (*p_cull->result_idx)++; } else { - return; // pointless to continue } } @@ -1008,12 +939,10 @@ void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p } if (use_pairs && !p_octant->pairable_elements.empty()) { - typename List<Element *, AL>::Element *I; I = p_octant->pairable_elements.front(); for (; I; I = I->next()) { - Element *e = I->get(); if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_cull->mask))) @@ -1021,13 +950,10 @@ void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p e->last_pass = pass; if (e->aabb.intersects_convex_shape(p_cull->planes, p_cull->plane_count, p_cull->points, p_cull->point_count)) { - if (*p_cull->result_idx < p_cull->result_max) { - p_cull->result_array[*p_cull->result_idx] = e->userdata; (*p_cull->result_idx)++; } else { - return; // pointless to continue } } @@ -1035,7 +961,6 @@ void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p } for (int i = 0; i < 8; i++) { - if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_convex_shape(p_cull->planes, p_cull->plane_count, p_cull->points, p_cull->point_count)) { _cull_convex(p_octant->children[i], p_cull); } @@ -1044,16 +969,13 @@ void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const AABB &p_aabb, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask) { - if (*p_result_idx == p_result_max) return; //pointless if (!p_octant->elements.empty()) { - typename List<Element *, AL>::Element *I; I = p_octant->elements.front(); for (; I; I = I->next()) { - Element *e = I->get(); if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) @@ -1061,16 +983,13 @@ void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const AABB &p_aabb, e->last_pass = pass; if (p_aabb.intersects_inclusive(e->aabb)) { - if (*p_result_idx < p_result_max) { - p_result_array[*p_result_idx] = e->userdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; (*p_result_idx)++; } else { - return; // pointless to continue } } @@ -1078,11 +997,9 @@ void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const AABB &p_aabb, } if (use_pairs && !p_octant->pairable_elements.empty()) { - typename List<Element *, AL>::Element *I; I = p_octant->pairable_elements.front(); for (; I; I = I->next()) { - Element *e = I->get(); if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) @@ -1090,15 +1007,12 @@ void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const AABB &p_aabb, e->last_pass = pass; if (p_aabb.intersects_inclusive(e->aabb)) { - if (*p_result_idx < p_result_max) { - p_result_array[*p_result_idx] = e->userdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; (*p_result_idx)++; } else { - return; // pointless to continue } } @@ -1106,7 +1020,6 @@ void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const AABB &p_aabb, } for (int i = 0; i < 8; i++) { - if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_inclusive(p_aabb)) { _cull_aabb(p_octant->children[i], p_aabb, p_result_array, p_result_idx, p_result_max, p_subindex_array, p_mask); } @@ -1115,16 +1028,13 @@ void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const AABB &p_aabb, template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_from, const Vector3 &p_to, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask) { - if (*p_result_idx == p_result_max) return; //pointless if (!p_octant->elements.empty()) { - typename List<Element *, AL>::Element *I; I = p_octant->elements.front(); for (; I; I = I->next()) { - Element *e = I->get(); if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) @@ -1132,16 +1042,13 @@ void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_ e->last_pass = pass; if (e->aabb.intersects_segment(p_from, p_to)) { - if (*p_result_idx < p_result_max) { - p_result_array[*p_result_idx] = e->userdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; (*p_result_idx)++; } else { - return; // pointless to continue } } @@ -1149,11 +1056,9 @@ void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_ } if (use_pairs && !p_octant->pairable_elements.empty()) { - typename List<Element *, AL>::Element *I; I = p_octant->pairable_elements.front(); for (; I; I = I->next()) { - Element *e = I->get(); if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) @@ -1162,9 +1067,7 @@ void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_ e->last_pass = pass; if (e->aabb.intersects_segment(p_from, p_to)) { - if (*p_result_idx < p_result_max) { - p_result_array[*p_result_idx] = e->userdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; @@ -1172,7 +1075,6 @@ void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_ (*p_result_idx)++; } else { - return; // pointless to continue } } @@ -1180,7 +1082,6 @@ void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_ } for (int i = 0; i < 8; i++) { - if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_segment(p_from, p_to)) { _cull_segment(p_octant->children[i], p_from, p_to, p_result_array, p_result_idx, p_result_max, p_subindex_array, p_mask); } @@ -1189,16 +1090,13 @@ void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_ template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_point, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask) { - if (*p_result_idx == p_result_max) return; //pointless if (!p_octant->elements.empty()) { - typename List<Element *, AL>::Element *I; I = p_octant->elements.front(); for (; I; I = I->next()) { - Element *e = I->get(); if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) @@ -1206,16 +1104,13 @@ void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_po e->last_pass = pass; if (e->aabb.has_point(p_point)) { - if (*p_result_idx < p_result_max) { - p_result_array[*p_result_idx] = e->userdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; (*p_result_idx)++; } else { - return; // pointless to continue } } @@ -1223,11 +1118,9 @@ void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_po } if (use_pairs && !p_octant->pairable_elements.empty()) { - typename List<Element *, AL>::Element *I; I = p_octant->pairable_elements.front(); for (; I; I = I->next()) { - Element *e = I->get(); if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) @@ -1236,9 +1129,7 @@ void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_po e->last_pass = pass; if (e->aabb.has_point(p_point)) { - if (*p_result_idx < p_result_max) { - p_result_array[*p_result_idx] = e->userdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; @@ -1246,7 +1137,6 @@ void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_po (*p_result_idx)++; } else { - return; // pointless to continue } } @@ -1254,7 +1144,6 @@ void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_po } for (int i = 0; i < 8; i++) { - //could be optimized.. if (p_octant->children[i] && p_octant->children[i]->aabb.has_point(p_point)) { _cull_point(p_octant->children[i], p_point, p_result_array, p_result_idx, p_result_max, p_subindex_array, p_mask); @@ -1264,7 +1153,6 @@ void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_po template <class T, bool use_pairs, class AL> int Octree<T, use_pairs, AL>::cull_convex(const Vector<Plane> &p_convex, T **p_result_array, int p_result_max, uint32_t p_mask) { - if (!root || p_convex.size() == 0) return 0; @@ -1291,7 +1179,6 @@ int Octree<T, use_pairs, AL>::cull_convex(const Vector<Plane> &p_convex, T **p_r template <class T, bool use_pairs, class AL> int Octree<T, use_pairs, AL>::cull_aabb(const AABB &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) { - if (!root) return 0; @@ -1304,7 +1191,6 @@ int Octree<T, use_pairs, AL>::cull_aabb(const AABB &p_aabb, T **p_result_array, template <class T, bool use_pairs, class AL> int Octree<T, use_pairs, AL>::cull_segment(const Vector3 &p_from, const Vector3 &p_to, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) { - if (!root) return 0; @@ -1317,7 +1203,6 @@ int Octree<T, use_pairs, AL>::cull_segment(const Vector3 &p_from, const Vector3 template <class T, bool use_pairs, class AL> int Octree<T, use_pairs, AL>::cull_point(const Vector3 &p_point, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) { - if (!root) return 0; @@ -1330,20 +1215,17 @@ int Octree<T, use_pairs, AL>::cull_point(const Vector3 &p_point, T **p_result_ar template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::set_pair_callback(PairCallback p_callback, void *p_userdata) { - pair_callback = p_callback; pair_callback_userdata = p_userdata; } template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::set_unpair_callback(UnpairCallback p_callback, void *p_userdata) { - unpair_callback = p_callback; unpair_callback_userdata = p_userdata; } template <class T, bool use_pairs, class AL> Octree<T, use_pairs, AL>::Octree(real_t p_unit_size) { - last_element_id = 1; pass = 1; unit_size = p_unit_size; diff --git a/core/math/plane.cpp b/core/math/plane.cpp index 26ac0aac47..94bdd41bd4 100644 --- a/core/math/plane.cpp +++ b/core/math/plane.cpp @@ -33,12 +33,10 @@ #include "core/math/math_funcs.h" void Plane::set_normal(const Vector3 &p_normal) { - normal = p_normal; } void Plane::normalize() { - real_t l = normal.length(); if (l == 0) { *this = Plane(0, 0, 0, 0); @@ -49,19 +47,16 @@ void Plane::normalize() { } Plane Plane::normalized() const { - Plane p = *this; p.normalize(); return p; } Vector3 Plane::get_any_point() const { - return get_normal() * d; } Vector3 Plane::get_any_perpendicular_normal() const { - static const Vector3 p1 = Vector3(1, 0, 0); static const Vector3 p2 = Vector3(0, 1, 0); Vector3 p; @@ -80,7 +75,6 @@ Vector3 Plane::get_any_perpendicular_normal() const { /* intersections */ bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r_result) const { - const Plane &p_plane0 = *this; Vector3 normal0 = p_plane0.normal; Vector3 normal1 = p_plane1.normal; @@ -102,13 +96,11 @@ bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r } bool Plane::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const { - Vector3 segment = p_dir; real_t den = normal.dot(segment); //printf("den is %i\n",den); if (Math::is_zero_approx(den)) { - return false; } @@ -127,13 +119,11 @@ bool Plane::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 } bool Plane::intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 *p_intersection) const { - Vector3 segment = p_begin - p_end; real_t den = normal.dot(segment); //printf("den is %i\n",den); if (Math::is_zero_approx(den)) { - return false; } @@ -141,7 +131,6 @@ bool Plane::intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vec //printf("dist is %i\n",dist); if (dist < -CMP_EPSILON || dist > (1.0 + CMP_EPSILON)) { - return false; } @@ -158,11 +147,9 @@ bool Plane::is_equal_approx_any_side(const Plane &p_plane) const { } bool Plane::is_equal_approx(const Plane &p_plane) const { - return normal.is_equal_approx(p_plane.normal) && Math::is_equal_approx(d, p_plane.d); } Plane::operator String() const { - return normal.operator String() + ", " + rtos(d); } diff --git a/core/math/plane.h b/core/math/plane.h index f4f205465f..017835a6da 100644 --- a/core/math/plane.h +++ b/core/math/plane.h @@ -61,7 +61,6 @@ public: bool intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 *p_intersection) const; _FORCE_INLINE_ Vector3 project(const Vector3 &p_point) const { - return p_point - normal * distance_to(p_point); } @@ -86,17 +85,14 @@ public: }; bool Plane::is_point_over(const Vector3 &p_point) const { - return (normal.dot(p_point) > d); } real_t Plane::distance_to(const Vector3 &p_point) const { - return (normal.dot(p_point) - d); } bool Plane::has_point(const Vector3 &p_point, real_t _epsilon) const { - real_t dist = normal.dot(p_point) - d; dist = ABS(dist); return (dist <= _epsilon); @@ -113,7 +109,6 @@ Plane::Plane(const Vector3 &p_point, const Vector3 &p_normal) : } Plane::Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_point3, ClockDirection p_dir) { - if (p_dir == CLOCKWISE) normal = (p_point1 - p_point3).cross(p_point1 - p_point2); else @@ -124,12 +119,10 @@ Plane::Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_ } bool Plane::operator==(const Plane &p_plane) const { - return normal == p_plane.normal && d == p_plane.d; } bool Plane::operator!=(const Plane &p_plane) const { - return normal != p_plane.normal || d != p_plane.d; } diff --git a/core/math/quat.cpp b/core/math/quat.cpp index 6fbea70279..f4b708616e 100644 --- a/core/math/quat.cpp +++ b/core/math/quat.cpp @@ -107,7 +107,6 @@ Vector3 Quat::get_euler_yxz() const { } void Quat::operator*=(const Quat &q) { - set(w * q.x + x * q.w + y * q.z - z * q.y, w * q.y + y * q.w + z * q.x - x * q.z, w * q.z + z * q.w + x * q.y - y * q.x, @@ -115,19 +114,16 @@ void Quat::operator*=(const Quat &q) { } Quat Quat::operator*(const Quat &q) const { - Quat r = *this; r *= q; return r; } bool Quat::is_equal_approx(const Quat &p_quat) const { - return Math::is_equal_approx(x, p_quat.x) && Math::is_equal_approx(y, p_quat.y) && Math::is_equal_approx(z, p_quat.z) && Math::is_equal_approx(w, p_quat.w); } real_t Quat::length() const { - return Math::sqrt(length_squared()); } @@ -233,7 +229,6 @@ Quat Quat::cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const } Quat::operator String() const { - return String::num(x) + ", " + String::num(y) + ", " + String::num(z) + ", " + String::num(w); } diff --git a/core/math/quat.h b/core/math/quat.h index 1ca6fe7ce3..64d0f00912 100644 --- a/core/math/quat.h +++ b/core/math/quat.h @@ -149,7 +149,6 @@ public: z = 0; w = 0; } else { - real_t s = Math::sqrt((1.0 + d) * 2.0); real_t rs = 1.0 / s; @@ -191,7 +190,6 @@ void Quat::operator*=(const real_t &s) { } void Quat::operator/=(const real_t &s) { - *this *= 1.0 / s; } diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp index 7fbb26c377..ace8ac9878 100644 --- a/core/math/quick_hull.cpp +++ b/core/math/quick_hull.cpp @@ -35,12 +35,10 @@ uint32_t QuickHull::debug_stop_after = 0xFFFFFFFF; Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_mesh) { - /* CREATE AABB VOLUME */ AABB aabb; for (int i = 0; i < p_points.size(); i++) { - if (i == 0) { aabb.position = p_points[i]; } else { @@ -57,7 +55,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me Set<Vector3> valid_cache; for (int i = 0; i < p_points.size(); i++) { - Vector3 sp = p_points[i].snapped(Vector3(0.0001, 0.0001, 0.0001)); if (valid_cache.has(sp)) { valid_points.write[i] = false; @@ -78,12 +75,10 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me real_t max = 0, min = 0; for (int i = 0; i < p_points.size(); i++) { - if (!valid_points[i]) continue; real_t d = p_points[i][longest_axis]; if (i == 0 || d < min) { - simplex[0] = i; min = d; } @@ -102,7 +97,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me Vector3 rel12 = p_points[simplex[0]] - p_points[simplex[1]]; for (int i = 0; i < p_points.size(); i++) { - if (!valid_points[i]) continue; @@ -110,7 +104,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me real_t d = Math::abs(n.dot(p_points[simplex[0]]) - n.dot(p_points[i])); if (i == 0 || d > maxd) { - maxd = d; simplex[2] = i; } @@ -124,14 +117,12 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me Plane p(p_points[simplex[0]], p_points[simplex[1]], p_points[simplex[2]]); for (int i = 0; i < p_points.size(); i++) { - if (!valid_points[i]) continue; real_t d = Math::abs(p.distance_to(p_points[i])); if (i == 0 || d > maxd) { - maxd = d; simplex[3] = i; } @@ -152,7 +143,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me List<Face> faces; for (int i = 0; i < 4; i++) { - static const int face_order[4][3] = { { 0, 1, 2 }, { 0, 1, 3 }, @@ -183,7 +173,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me /* COMPUTE AVAILABLE VERTICES */ for (int i = 0; i < p_points.size(); i++) { - if (i == simplex[0]) continue; if (i == simplex[1]) @@ -196,9 +185,7 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me continue; for (List<Face>::Element *E = faces.front(); E; E = E->next()) { - if (E->get().plane.distance_to(p_points[i]) > over_tolerance) { - E->get().points_over.push_back(i); break; } @@ -219,7 +206,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me uint32_t debug_stop = debug_stop_after; while (debug_stop > 0 && faces.back()->get().points_over.size()) { - debug_stop--; Face &f = faces.back()->get(); @@ -228,7 +214,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me real_t next_d = 0; for (int i = 0; i < f.points_over.size(); i++) { - real_t d = f.plane.distance_to(p_points[f.points_over[i]]); if (d > next_d) { @@ -247,9 +232,7 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me Map<Edge, FaceConnect> lit_edges; //create this on the flight, should not be that bad for performance and simplifies code a lot for (List<Face>::Element *E = faces.front(); E; E = E->next()) { - if (E->get().plane.distance_to(v) > 0) { - lit_faces.push_back(E); for (int i = 0; i < 3; i++) { @@ -265,7 +248,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me //left F->get().left = E; } else { - F->get().right = E; } } @@ -276,7 +258,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me List<List<Face>::Element *> new_faces; //new faces for (Map<Edge, FaceConnect>::Element *E = lit_edges.front(); E; E = E->next()) { - FaceConnect &fc = E->get(); if (fc.left && fc.right) { continue; //edge is uninteresting, not on horizont @@ -304,17 +285,14 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me //distribute points into new faces for (List<List<Face>::Element *>::Element *F = lit_faces.front(); F; F = F->next()) { - Face &lf = F->get()->get(); for (int i = 0; i < lf.points_over.size(); i++) { - if (lf.points_over[i] == f.points_over[next]) //do not add current one continue; Vector3 p = p_points[lf.points_over[i]]; for (List<List<Face>::Element *>::Element *E = new_faces.front(); E; E = E->next()) { - Face &f2 = E->get()->get(); if (f2.plane.distance_to(p) > over_tolerance) { f2.points_over.push_back(lf.points_over[i]); @@ -327,7 +305,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me //erase lit faces while (lit_faces.size()) { - faces.erase(lit_faces.front()->get()); lit_faces.pop_front(); } @@ -335,7 +312,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me //put faces that contain no points on the front for (List<List<Face>::Element *>::Element *E = new_faces.front(); E; E = E->next()) { - Face &f2 = E->get()->get(); if (f2.points_over.size() == 0) { faces.move_to_front(E->get()); @@ -352,7 +328,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me List<Geometry::MeshData::Face> ret_faces; for (List<Face>::Element *E = faces.front(); E; E = E->next()) { - Geometry::MeshData::Face f; f.plane = E->get().plane; @@ -363,7 +338,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me List<Geometry::MeshData::Face>::Element *F = ret_faces.push_back(f); for (int i = 0; i < 3; i++) { - uint32_t a = E->get().vertices[i]; uint32_t b = E->get().vertices[(i + 1) % 3]; Edge e(a, b); @@ -376,7 +350,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me //left G->get().left = F; } else { - G->get().right = F; } } @@ -385,11 +358,9 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me //fill faces for (List<Geometry::MeshData::Face>::Element *E = ret_faces.front(); E; E = E->next()) { - Geometry::MeshData::Face &f = E->get(); for (int i = 0; i < f.indices.size(); i++) { - int a = E->get().indices[i]; int b = E->get().indices[(i + 1) % f.indices.size()]; Edge e(a, b); @@ -411,7 +382,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me if (O->get().indices[j] == a) { //append the rest for (int k = 0; k < ois; k++) { - int idx = O->get().indices[(k + j) % ois]; int idxn = O->get().indices[(k + j + 1) % ois]; if (idx == b && idxn == a) { //already have b! @@ -463,7 +433,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me r_mesh.edges.resize(ret_edges.size()); idx = 0; for (Map<Edge, RetFaceConnect>::Element *E = ret_edges.front(); E; E = E->next()) { - Geometry::MeshData::Edge e; e.a = E->key().vertices[0]; e.b = E->key().vertices[1]; diff --git a/core/math/quick_hull.h b/core/math/quick_hull.h index 89061ab415..29f709febe 100644 --- a/core/math/quick_hull.h +++ b/core/math/quick_hull.h @@ -37,10 +37,8 @@ #include "core/set.h" class QuickHull { - public: struct Edge { - union { uint32_t vertices[2]; uint64_t id; @@ -51,7 +49,6 @@ public: } Edge(int p_vtx_a = 0, int p_vtx_b = 0) { - if (p_vtx_a > p_vtx_b) { SWAP(p_vtx_a, p_vtx_b); } @@ -62,13 +59,11 @@ public: }; struct Face { - Plane plane; uint32_t vertices[3]; Vector<int> points_over; bool operator<(const Face &p_face) const { - return points_over.size() < p_face.points_over.size(); } }; diff --git a/core/math/rect2.cpp b/core/math/rect2.cpp index 12b9904c88..1e26f815ed 100644 --- a/core/math/rect2.cpp +++ b/core/math/rect2.cpp @@ -31,12 +31,10 @@ #include "core/math/transform_2d.h" // Includes rect2.h but Rect2 needs Transform2D bool Rect2::is_equal_approx(const Rect2 &p_rect) const { - return position.is_equal_approx(p_rect.position) && size.is_equal_approx(p_rect.size); } bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_pos, Point2 *r_normal) const { - real_t min = 0, max = 1; int axis = 0; real_t sign = 0; @@ -50,7 +48,6 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 real_t csign; if (seg_from < seg_to) { - if (seg_from > box_end || seg_to < box_begin) return false; real_t length = seg_to - seg_from; @@ -59,7 +56,6 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 csign = -1.0; } else { - if (seg_to > box_end || seg_from < box_begin) return false; real_t length = seg_to - seg_from; @@ -94,7 +90,6 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 } bool Rect2::intersects_transformed(const Transform2D &p_xform, const Rect2 &p_rect) const { - //SAT intersection between local and transformed rect2 Vector2 xf_points[4] = { diff --git a/core/math/rect2.h b/core/math/rect2.h index a3f3634bfb..f6274ae32b 100644 --- a/core/math/rect2.h +++ b/core/math/rect2.h @@ -36,7 +36,6 @@ struct Transform2D; struct Rect2 { - Point2 position; Size2 size; @@ -72,7 +71,6 @@ struct Rect2 { } inline real_t distance_to(const Vector2 &p_point) const { - real_t dist = 0.0; bool inside = true; @@ -108,14 +106,12 @@ struct Rect2 { bool intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_pos = nullptr, Point2 *r_normal = nullptr) const; inline bool encloses(const Rect2 &p_rect) const { - return (p_rect.position.x >= position.x) && (p_rect.position.y >= position.y) && ((p_rect.position.x + p_rect.size.x) <= (position.x + size.x)) && ((p_rect.position.y + p_rect.size.y) <= (position.y + size.y)); } _FORCE_INLINE_ bool has_no_area() const { - return (size.x <= 0 || size.y <= 0); } inline Rect2 clip(const Rect2 &p_rect) const { /// return a clipped rect @@ -170,7 +166,6 @@ struct Rect2 { bool operator!=(const Rect2 &p_rect) const { return position != p_rect.position || size != p_rect.size; } inline Rect2 grow(real_t p_by) const { - Rect2 g = *this; g.position.x -= p_by; g.position.y -= p_by; @@ -189,7 +184,6 @@ struct Rect2 { } inline Rect2 grow_individual(real_t p_left, real_t p_top, real_t p_right, real_t p_bottom) const { - Rect2 g = *this; g.position.x -= p_left; g.position.y -= p_top; @@ -200,7 +194,6 @@ struct Rect2 { } _FORCE_INLINE_ Rect2 expand(const Vector2 &p_vector) const { - Rect2 r = *this; r.expand_to(p_vector); return r; @@ -226,7 +219,6 @@ struct Rect2 { } _FORCE_INLINE_ Rect2 abs() const { - return Rect2(Point2(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0)), size.abs()); } @@ -244,7 +236,6 @@ struct Rect2 { }; struct Rect2i { - Point2i position; Size2i size; @@ -269,14 +260,12 @@ struct Rect2i { } inline bool encloses(const Rect2i &p_rect) const { - return (p_rect.position.x >= position.x) && (p_rect.position.y >= position.y) && ((p_rect.position.x + p_rect.size.x) < (position.x + size.x)) && ((p_rect.position.y + p_rect.size.y) < (position.y + size.y)); } _FORCE_INLINE_ bool has_no_area() const { - return (size.x <= 0 || size.y <= 0); } inline Rect2i clip(const Rect2i &p_rect) const { /// return a clipped rect @@ -330,7 +319,6 @@ struct Rect2i { bool operator!=(const Rect2i &p_rect) const { return position != p_rect.position || size != p_rect.size; } Rect2i grow(int p_by) const { - Rect2i g = *this; g.position.x -= p_by; g.position.y -= p_by; @@ -349,7 +337,6 @@ struct Rect2i { } inline Rect2i grow_individual(int p_left, int p_top, int p_right, int p_bottom) const { - Rect2i g = *this; g.position.x -= p_left; g.position.y -= p_top; @@ -360,14 +347,12 @@ struct Rect2i { } _FORCE_INLINE_ Rect2i expand(const Vector2i &p_vector) const { - Rect2i r = *this; r.expand_to(p_vector); return r; } inline void expand_to(const Point2i &p_vector) { - Point2i begin = position; Point2i end = position + size; @@ -386,7 +371,6 @@ struct Rect2i { } _FORCE_INLINE_ Rect2i abs() const { - return Rect2i(Point2i(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0)), size.abs()); } diff --git a/core/math/transform.cpp b/core/math/transform.cpp index 82e4005d3e..0f62c8b2c0 100644 --- a/core/math/transform.cpp +++ b/core/math/transform.cpp @@ -35,20 +35,17 @@ #include "core/print_string.h" void Transform::affine_invert() { - basis.invert(); origin = basis.xform(-origin); } Transform Transform::affine_inverse() const { - Transform ret = *this; ret.affine_invert(); return ret; } void Transform::invert() { - basis.transpose(); origin = basis.xform(-origin); } @@ -62,22 +59,18 @@ Transform Transform::inverse() const { } void Transform::rotate(const Vector3 &p_axis, real_t p_phi) { - *this = rotated(p_axis, p_phi); } Transform Transform::rotated(const Vector3 &p_axis, real_t p_phi) const { - return Transform(Basis(p_axis, p_phi), Vector3()) * (*this); } void Transform::rotate_basis(const Vector3 &p_axis, real_t p_phi) { - basis.rotate(p_axis, p_phi); } Transform Transform::looking_at(const Vector3 &p_target, const Vector3 &p_up) const { - Transform t = *this; t.set_look_at(origin, p_target, p_up); return t; @@ -117,7 +110,6 @@ void Transform::set_look_at(const Vector3 &p_eye, const Vector3 &p_target, const } Transform Transform::interpolate_with(const Transform &p_transform, real_t p_c) const { - /* not sure if very "efficient" but good enough? */ Vector3 src_scale = basis.get_scale(); @@ -136,20 +128,17 @@ Transform Transform::interpolate_with(const Transform &p_transform, real_t p_c) } void Transform::scale(const Vector3 &p_scale) { - basis.scale(p_scale); origin *= p_scale; } Transform Transform::scaled(const Vector3 &p_scale) const { - Transform t = *this; t.scale(p_scale); return t; } void Transform::scale_basis(const Vector3 &p_scale) { - basis.scale(p_scale); } @@ -157,60 +146,50 @@ void Transform::translate(real_t p_tx, real_t p_ty, real_t p_tz) { translate(Vector3(p_tx, p_ty, p_tz)); } void Transform::translate(const Vector3 &p_translation) { - for (int i = 0; i < 3; i++) { origin[i] += basis[i].dot(p_translation); } } Transform Transform::translated(const Vector3 &p_translation) const { - Transform t = *this; t.translate(p_translation); return t; } void Transform::orthonormalize() { - basis.orthonormalize(); } Transform Transform::orthonormalized() const { - Transform _copy = *this; _copy.orthonormalize(); return _copy; } bool Transform::is_equal_approx(const Transform &p_transform) const { - return basis.is_equal_approx(p_transform.basis) && origin.is_equal_approx(p_transform.origin); } bool Transform::operator==(const Transform &p_transform) const { - return (basis == p_transform.basis && origin == p_transform.origin); } bool Transform::operator!=(const Transform &p_transform) const { - return (basis != p_transform.basis || origin != p_transform.origin); } void Transform::operator*=(const Transform &p_transform) { - origin = xform(p_transform.origin); basis *= p_transform.basis; } Transform Transform::operator*(const Transform &p_transform) const { - Transform t = *this; t *= p_transform; return t; } Transform::operator String() const { - return basis.operator String() + " - " + origin.operator String(); } diff --git a/core/math/transform.h b/core/math/transform.h index c6e3be4c70..7f7e9ce833 100644 --- a/core/math/transform.h +++ b/core/math/transform.h @@ -92,14 +92,12 @@ public: Transform interpolate_with(const Transform &p_transform, real_t p_c) const; _FORCE_INLINE_ Transform inverse_xform(const Transform &t) const { - Vector3 v = t.origin - origin; return Transform(basis.transpose_xform(t.basis), basis.xform(v)); } void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz, real_t tx, real_t ty, real_t tz) { - basis.set(xx, xy, xz, yx, yy, yz, zx, zy, zz); origin.x = tx; origin.y = ty; @@ -114,14 +112,12 @@ public: }; _FORCE_INLINE_ Vector3 Transform::xform(const Vector3 &p_vector) const { - return Vector3( basis[0].dot(p_vector) + origin.x, basis[1].dot(p_vector) + origin.y, basis[2].dot(p_vector) + origin.z); } _FORCE_INLINE_ Vector3 Transform::xform_inv(const Vector3 &p_vector) const { - Vector3 v = p_vector - origin; return Vector3( @@ -131,7 +127,6 @@ _FORCE_INLINE_ Vector3 Transform::xform_inv(const Vector3 &p_vector) const { } _FORCE_INLINE_ Plane Transform::xform(const Plane &p_plane) const { - Vector3 point = p_plane.normal * p_plane.d; Vector3 point_dir = point + p_plane.normal; point = xform(point); @@ -144,7 +139,6 @@ _FORCE_INLINE_ Plane Transform::xform(const Plane &p_plane) const { return Plane(normal, d); } _FORCE_INLINE_ Plane Transform::xform_inv(const Plane &p_plane) const { - Vector3 point = p_plane.normal * p_plane.d; Vector3 point_dir = point + p_plane.normal; xform_inv(point); @@ -158,7 +152,6 @@ _FORCE_INLINE_ Plane Transform::xform_inv(const Plane &p_plane) const { } _FORCE_INLINE_ AABB Transform::xform(const AABB &p_aabb) const { - /* http://dev.theomader.com/transform-bounding-boxes/ */ Vector3 min = p_aabb.position; Vector3 max = p_aabb.position + p_aabb.size; @@ -184,7 +177,6 @@ _FORCE_INLINE_ AABB Transform::xform(const AABB &p_aabb) const { } _FORCE_INLINE_ AABB Transform::xform_inv(const AABB &p_aabb) const { - /* define vertices */ Vector3 vertices[8] = { Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z), @@ -202,7 +194,6 @@ _FORCE_INLINE_ AABB Transform::xform_inv(const AABB &p_aabb) const { ret.position = xform_inv(vertices[0]); for (int i = 1; i < 8; i++) { - ret.expand_to(xform_inv(vertices[i])); } @@ -210,7 +201,6 @@ _FORCE_INLINE_ AABB Transform::xform_inv(const AABB &p_aabb) const { } Vector<Vector3> Transform::xform(const Vector<Vector3> &p_array) const { - Vector<Vector3> array; array.resize(p_array.size()); @@ -224,7 +214,6 @@ Vector<Vector3> Transform::xform(const Vector<Vector3> &p_array) const { } Vector<Vector3> Transform::xform_inv(const Vector<Vector3> &p_array) const { - Vector<Vector3> array; array.resize(p_array.size()); diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp index ed95baa233..f82d1d99c4 100644 --- a/core/math/transform_2d.cpp +++ b/core/math/transform_2d.cpp @@ -38,14 +38,12 @@ void Transform2D::invert() { } Transform2D Transform2D::inverse() const { - Transform2D inv = *this; inv.invert(); return inv; } void Transform2D::affine_invert() { - real_t det = basis_determinant(); #ifdef MATH_CHECKS ERR_FAIL_COND(det == 0); @@ -60,7 +58,6 @@ void Transform2D::affine_invert() { } Transform2D Transform2D::affine_inverse() const { - Transform2D inv = *this; inv.affine_invert(); return inv; @@ -71,13 +68,11 @@ void Transform2D::rotate(real_t p_phi) { } real_t Transform2D::get_skew() const { - real_t det = basis_determinant(); return Math::acos(elements[0].normalized().dot(SGN(det) * elements[1].normalized())) - Math_PI * 0.5; } void Transform2D::set_skew(float p_angle) { - real_t det = basis_determinant(); elements[1] = SGN(det) * elements[0].rotated((Math_PI * 0.5 + p_angle)).normalized() * elements[1].length(); } @@ -103,7 +98,6 @@ void Transform2D::set_rotation(real_t p_rot) { } Transform2D::Transform2D(real_t p_rot, const Vector2 &p_pos) { - real_t cr = Math::cos(p_rot); real_t sr = Math::sin(p_rot); elements[0][0] = cr; @@ -130,23 +124,19 @@ void Transform2D::scale(const Size2 &p_scale) { elements[2] *= p_scale; } void Transform2D::scale_basis(const Size2 &p_scale) { - elements[0][0] *= p_scale.x; elements[0][1] *= p_scale.y; elements[1][0] *= p_scale.x; elements[1][1] *= p_scale.y; } void Transform2D::translate(real_t p_tx, real_t p_ty) { - translate(Vector2(p_tx, p_ty)); } void Transform2D::translate(const Vector2 &p_translation) { - elements[2] += basis_xform(p_translation); } void Transform2D::orthonormalize() { - // Gram-Schmidt Process Vector2 x = elements[0]; @@ -161,19 +151,16 @@ void Transform2D::orthonormalize() { } Transform2D Transform2D::orthonormalized() const { - Transform2D on = *this; on.orthonormalize(); return on; } bool Transform2D::is_equal_approx(const Transform2D &p_transform) const { - return elements[0].is_equal_approx(p_transform.elements[0]) && elements[1].is_equal_approx(p_transform.elements[1]) && elements[2].is_equal_approx(p_transform.elements[2]); } bool Transform2D::operator==(const Transform2D &p_transform) const { - for (int i = 0; i < 3; i++) { if (elements[i] != p_transform.elements[i]) return false; @@ -183,7 +170,6 @@ bool Transform2D::operator==(const Transform2D &p_transform) const { } bool Transform2D::operator!=(const Transform2D &p_transform) const { - for (int i = 0; i < 3; i++) { if (elements[i] != p_transform.elements[i]) return true; @@ -193,7 +179,6 @@ bool Transform2D::operator!=(const Transform2D &p_transform) const { } void Transform2D::operator*=(const Transform2D &p_transform) { - elements[2] = xform(p_transform.elements[2]); real_t x0, x1, y0, y1; @@ -210,54 +195,46 @@ void Transform2D::operator*=(const Transform2D &p_transform) { } Transform2D Transform2D::operator*(const Transform2D &p_transform) const { - Transform2D t = *this; t *= p_transform; return t; } Transform2D Transform2D::scaled(const Size2 &p_scale) const { - Transform2D copy = *this; copy.scale(p_scale); return copy; } Transform2D Transform2D::basis_scaled(const Size2 &p_scale) const { - Transform2D copy = *this; copy.scale_basis(p_scale); return copy; } Transform2D Transform2D::untranslated() const { - Transform2D copy = *this; copy.elements[2] = Vector2(); return copy; } Transform2D Transform2D::translated(const Vector2 &p_offset) const { - Transform2D copy = *this; copy.translate(p_offset); return copy; } Transform2D Transform2D::rotated(real_t p_phi) const { - Transform2D copy = *this; copy.rotate(p_phi); return copy; } real_t Transform2D::basis_determinant() const { - return elements[0].x * elements[1].y - elements[0].y * elements[1].x; } Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t p_c) const { - //extract parameters Vector2 p1 = get_origin(); Vector2 p2 = p_transform.get_origin(); @@ -293,6 +270,5 @@ Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t } Transform2D::operator String() const { - return String(String() + elements[0] + ", " + elements[1] + ", " + elements[2]); } diff --git a/core/math/transform_2d.h b/core/math/transform_2d.h index 459ceed7a9..66958257d7 100644 --- a/core/math/transform_2d.h +++ b/core/math/transform_2d.h @@ -120,7 +120,6 @@ struct Transform2D { operator String() const; Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy) { - elements[0][0] = xx; elements[0][1] = xy; elements[1][0] = yx; @@ -137,28 +136,24 @@ struct Transform2D { }; Vector2 Transform2D::basis_xform(const Vector2 &p_vec) const { - return Vector2( tdotx(p_vec), tdoty(p_vec)); } Vector2 Transform2D::basis_xform_inv(const Vector2 &p_vec) const { - return Vector2( elements[0].dot(p_vec), elements[1].dot(p_vec)); } Vector2 Transform2D::xform(const Vector2 &p_vec) const { - return Vector2( tdotx(p_vec), tdoty(p_vec)) + elements[2]; } Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const { - Vector2 v = p_vec - elements[2]; return Vector2( @@ -166,7 +161,6 @@ Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const { elements[1].dot(v)); } Rect2 Transform2D::xform(const Rect2 &p_rect) const { - Vector2 x = elements[0] * p_rect.size.x; Vector2 y = elements[1] * p_rect.size.y; Vector2 pos = xform(p_rect.position); @@ -180,7 +174,6 @@ Rect2 Transform2D::xform(const Rect2 &p_rect) const { } void Transform2D::set_rotation_and_scale(real_t p_rot, const Size2 &p_scale) { - elements[0][0] = Math::cos(p_rot) * p_scale.x; elements[1][1] = Math::cos(p_rot) * p_scale.y; elements[1][0] = -Math::sin(p_rot) * p_scale.y; @@ -188,7 +181,6 @@ void Transform2D::set_rotation_and_scale(real_t p_rot, const Size2 &p_scale) { } void Transform2D::set_rotation_scale_and_skew(real_t p_rot, const Size2 &p_scale, float p_skew) { - elements[0][0] = Math::cos(p_rot) * p_scale.x; elements[1][1] = Math::cos(p_rot + p_skew) * p_scale.y; elements[1][0] = -Math::sin(p_rot + p_skew) * p_scale.y; @@ -196,7 +188,6 @@ void Transform2D::set_rotation_scale_and_skew(real_t p_rot, const Size2 &p_scale } Rect2 Transform2D::xform_inv(const Rect2 &p_rect) const { - Vector2 ends[4] = { xform_inv(p_rect.position), xform_inv(Vector2(p_rect.position.x, p_rect.position.y + p_rect.size.y)), @@ -214,7 +205,6 @@ Rect2 Transform2D::xform_inv(const Rect2 &p_rect) const { } Vector<Vector2> Transform2D::xform(const Vector<Vector2> &p_array) const { - Vector<Vector2> array; array.resize(p_array.size()); @@ -228,7 +218,6 @@ Vector<Vector2> Transform2D::xform(const Vector<Vector2> &p_array) const { } Vector<Vector2> Transform2D::xform_inv(const Vector<Vector2> &p_array) const { - Vector<Vector2> array; array.resize(p_array.size()); diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp index 0f7350a260..9a608e3f1b 100644 --- a/core/math/triangle_mesh.cpp +++ b/core/math/triangle_mesh.cpp @@ -33,30 +33,25 @@ #include "core/sort_array.h" int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, int p_depth, int &max_depth, int &max_alloc) { - if (p_depth > max_depth) { max_depth = p_depth; } if (p_size == 1) { - return p_bb[p_from] - p_bvh; } else if (p_size == 0) { - return -1; } AABB aabb; aabb = p_bb[p_from]->aabb; for (int i = 1; i < p_size; i++) { - aabb.merge_with(p_bb[p_from + i]->aabb); } int li = aabb.get_longest_axis_index(); switch (li) { - case Vector3::AXIS_X: { SortArray<BVH *, BVHCmpX> sort_x; sort_x.nth_element(0, p_size, p_size / 2, &p_bb[p_from]); @@ -90,7 +85,6 @@ int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, in } void TriangleMesh::get_indices(Vector<int> *r_triangles_indices) const { - if (!valid) return; @@ -110,7 +104,6 @@ void TriangleMesh::get_indices(Vector<int> *r_triangles_indices) const { } void TriangleMesh::create(const Vector<Vector3> &p_faces) { - valid = false; int fc = p_faces.size(); @@ -122,7 +115,6 @@ void TriangleMesh::create(const Vector<Vector3> &p_faces) { BVH *bw = bvh.ptrw(); { - //create faces and indices and base bvh //except for the Set for repeated triangles, everything //goes in-place. @@ -132,12 +124,10 @@ void TriangleMesh::create(const Vector<Vector3> &p_faces) { Map<Vector3, int> db; for (int i = 0; i < fc; i++) { - Triangle &f = w[i]; const Vector3 *v = &r[i * 3]; for (int j = 0; j < 3; j++) { - int vidx = -1; Vector3 vs = v[j].snapped(Vector3(0.0001, 0.0001, 0.0001)); Map<Vector3, int>::Element *E = db.find(vs); @@ -174,7 +164,6 @@ void TriangleMesh::create(const Vector<Vector3> &p_faces) { bwptrs.resize(fc); BVH **bwp = bwptrs.ptrw(); for (int i = 0; i < fc; i++) { - bwp[i] = &bw[i]; } @@ -188,7 +177,6 @@ void TriangleMesh::create(const Vector<Vector3> &p_faces) { } Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const { - uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth); enum { @@ -215,23 +203,18 @@ Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const { stack[0] = pos; while (true) { - uint32_t node = stack[level] & NODE_IDX_MASK; const BVH &b = bvhptr[node]; bool done = false; switch (stack[level] >> VISITED_BIT_SHIFT) { case TEST_AABB_BIT: { - bool valid = b.aabb.intersects(p_aabb); if (!valid) { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - if (b.face_index >= 0) { - const Triangle &s = triangleptr[b.face_index]; n += s.normal; n_count++; @@ -239,28 +222,24 @@ Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const { stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node; } } continue; } case VISIT_LEFT_BIT: { - stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.left | TEST_AABB_BIT; level++; continue; } case VISIT_RIGHT_BIT: { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.right | TEST_AABB_BIT; level++; continue; } case VISIT_DONE_BIT: { - if (level == 0) { done = true; break; @@ -281,7 +260,6 @@ Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const { } bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal) const { - uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth); enum { @@ -309,35 +287,28 @@ bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_en stack[0] = pos; while (true) { - uint32_t node = stack[level] & NODE_IDX_MASK; const BVH &b = bvhptr[node]; bool done = false; switch (stack[level] >> VISITED_BIT_SHIFT) { case TEST_AABB_BIT: { - bool valid = b.aabb.intersects_segment(p_begin, p_end); //bool valid = b.aabb.intersects(ray_aabb); if (!valid) { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - if (b.face_index >= 0) { - const Triangle &s = triangleptr[b.face_index]; Face3 f3(vertexptr[s.indices[0]], vertexptr[s.indices[1]], vertexptr[s.indices[2]]); Vector3 res; if (f3.intersects_segment(p_begin, p_end, &res)) { - real_t nd = n.dot(res); if (nd < d) { - d = nd; r_point = res; r_normal = f3.get_plane().get_normal(); @@ -348,28 +319,24 @@ bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_en stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node; } } continue; } case VISIT_LEFT_BIT: { - stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.left | TEST_AABB_BIT; level++; continue; } case VISIT_RIGHT_BIT: { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.right | TEST_AABB_BIT; level++; continue; } case VISIT_DONE_BIT: { - if (level == 0) { done = true; break; @@ -384,7 +351,6 @@ bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_en } if (inters) { - if (n.dot(r_normal) > 0) r_normal = -r_normal; } @@ -393,7 +359,6 @@ bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_en } bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, Vector3 &r_point, Vector3 &r_normal) const { - uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth); enum { @@ -421,33 +386,26 @@ bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, V stack[0] = pos; while (true) { - uint32_t node = stack[level] & NODE_IDX_MASK; const BVH &b = bvhptr[node]; bool done = false; switch (stack[level] >> VISITED_BIT_SHIFT) { case TEST_AABB_BIT: { - bool valid = b.aabb.intersects_ray(p_begin, p_dir); if (!valid) { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - if (b.face_index >= 0) { - const Triangle &s = triangleptr[b.face_index]; Face3 f3(vertexptr[s.indices[0]], vertexptr[s.indices[1]], vertexptr[s.indices[2]]); Vector3 res; if (f3.intersects_ray(p_begin, p_dir, &res)) { - real_t nd = n.dot(res); if (nd < d) { - d = nd; r_point = res; r_normal = f3.get_plane().get_normal(); @@ -458,28 +416,24 @@ bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, V stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node; } } continue; } case VISIT_LEFT_BIT: { - stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.left | TEST_AABB_BIT; level++; continue; } case VISIT_RIGHT_BIT: { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.right | TEST_AABB_BIT; level++; continue; } case VISIT_DONE_BIT: { - if (level == 0) { done = true; break; @@ -494,7 +448,6 @@ bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, V } if (inters) { - if (n.dot(r_normal) > 0) r_normal = -r_normal; } @@ -528,23 +481,18 @@ bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_cou stack[0] = pos; while (true) { - uint32_t node = stack[level] & NODE_IDX_MASK; const BVH &b = bvhptr[node]; bool done = false; switch (stack[level] >> VISITED_BIT_SHIFT) { case TEST_AABB_BIT: { - bool valid = b.aabb.intersects_convex_shape(p_planes, p_plane_count, p_points, p_point_count); if (!valid) { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - if (b.face_index >= 0) { - const Triangle &s = triangleptr[b.face_index]; for (int j = 0; j < 3; ++j) { @@ -582,28 +530,24 @@ bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_cou stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node; } } continue; } case VISIT_LEFT_BIT: { - stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.left | TEST_AABB_BIT; level++; continue; } case VISIT_RIGHT_BIT: { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.right | TEST_AABB_BIT; level++; continue; } case VISIT_DONE_BIT: { - if (level == 0) { done = true; break; @@ -646,25 +590,21 @@ bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count, stack[0] = pos; while (true) { - uint32_t node = stack[level] & NODE_IDX_MASK; const BVH &b = bvhptr[node]; bool done = false; switch (stack[level] >> VISITED_BIT_SHIFT) { case TEST_AABB_BIT: { - bool intersects = scale.xform(b.aabb).intersects_convex_shape(p_planes, p_plane_count, p_points, p_point_count); if (!intersects) return false; bool inside = scale.xform(b.aabb).inside_convex_shape(p_planes, p_plane_count); if (inside) { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - if (b.face_index >= 0) { const Triangle &s = triangleptr[b.face_index]; for (int j = 0; j < 3; ++j) { @@ -679,28 +619,24 @@ bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count, stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node; } } continue; } case VISIT_LEFT_BIT: { - stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.left | TEST_AABB_BIT; level++; continue; } case VISIT_RIGHT_BIT: { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.right | TEST_AABB_BIT; level++; continue; } case VISIT_DONE_BIT: { - if (level == 0) { done = true; break; @@ -718,12 +654,10 @@ bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count, } bool TriangleMesh::is_valid() const { - return valid; } Vector<Face3> TriangleMesh::get_faces() const { - if (!valid) return Vector<Face3>(); @@ -745,7 +679,6 @@ Vector<Face3> TriangleMesh::get_faces() const { } TriangleMesh::TriangleMesh() { - valid = false; max_depth = 0; } diff --git a/core/math/triangle_mesh.h b/core/math/triangle_mesh.h index 64704477cc..86412cf725 100644 --- a/core/math/triangle_mesh.h +++ b/core/math/triangle_mesh.h @@ -35,11 +35,9 @@ #include "core/reference.h" class TriangleMesh : public Reference { - GDCLASS(TriangleMesh, Reference); struct Triangle { - Vector3 normal; int indices[3]; }; @@ -48,7 +46,6 @@ class TriangleMesh : public Reference { Vector<Vector3> vertices; struct BVH { - AABB aabb; Vector3 center; //used for sorting int left; @@ -58,24 +55,18 @@ class TriangleMesh : public Reference { }; struct BVHCmpX { - bool operator()(const BVH *p_left, const BVH *p_right) const { - return p_left->center.x < p_right->center.x; } }; struct BVHCmpY { - bool operator()(const BVH *p_left, const BVH *p_right) const { - return p_left->center.y < p_right->center.y; } }; struct BVHCmpZ { - bool operator()(const BVH *p_left, const BVH *p_right) const { - return p_left->center.z < p_right->center.z; } }; diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp index ae278b034d..c7b838fd10 100644 --- a/core/math/triangulate.cpp +++ b/core/math/triangulate.cpp @@ -31,7 +31,6 @@ #include "triangulate.h" real_t Triangulate::get_area(const Vector<Vector2> &contour) { - int n = contour.size(); const Vector2 *c = &contour[0]; diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp index f46badd19e..d06f64b40b 100644 --- a/core/math/vector2.cpp +++ b/core/math/vector2.cpp @@ -31,25 +31,20 @@ #include "vector2.h" real_t Vector2::angle() const { - return Math::atan2(y, x); } real_t Vector2::length() const { - return Math::sqrt(x * x + y * y); } real_t Vector2::length_squared() const { - return x * x + y * y; } void Vector2::normalize() { - real_t l = x * x + y * y; if (l != 0) { - l = Math::sqrt(l); x /= l; y /= l; @@ -57,7 +52,6 @@ void Vector2::normalize() { } Vector2 Vector2::normalized() const { - Vector2 v = *this; v.normalize(); return v; @@ -69,52 +63,42 @@ bool Vector2::is_normalized() const { } real_t Vector2::distance_to(const Vector2 &p_vector2) const { - return Math::sqrt((x - p_vector2.x) * (x - p_vector2.x) + (y - p_vector2.y) * (y - p_vector2.y)); } real_t Vector2::distance_squared_to(const Vector2 &p_vector2) const { - return (x - p_vector2.x) * (x - p_vector2.x) + (y - p_vector2.y) * (y - p_vector2.y); } real_t Vector2::angle_to(const Vector2 &p_vector2) const { - return Math::atan2(cross(p_vector2), dot(p_vector2)); } real_t Vector2::angle_to_point(const Vector2 &p_vector2) const { - return Math::atan2(y - p_vector2.y, x - p_vector2.x); } real_t Vector2::dot(const Vector2 &p_other) const { - return x * p_other.x + y * p_other.y; } real_t Vector2::cross(const Vector2 &p_other) const { - return x * p_other.y - y * p_other.x; } Vector2 Vector2::sign() const { - return Vector2(SGN(x), SGN(y)); } Vector2 Vector2::floor() const { - return Vector2(Math::floor(x), Math::floor(y)); } Vector2 Vector2::ceil() const { - return Vector2(Math::ceil(x), Math::ceil(y)); } Vector2 Vector2::round() const { - return Vector2(Math::round(x), Math::round(y)); } @@ -139,18 +123,15 @@ Vector2 Vector2::project(const Vector2 &p_b) const { } Vector2 Vector2::snapped(const Vector2 &p_by) const { - return Vector2( Math::stepify(x, p_by.x), Math::stepify(y, p_by.y)); } Vector2 Vector2::clamped(real_t p_len) const { - real_t l = length(); Vector2 v = *this; if (l > 0 && p_len < l) { - v /= l; v *= p_len; } @@ -159,7 +140,6 @@ Vector2 Vector2::clamped(real_t p_len) const { } Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const { - Vector2 p0 = p_pre_a; Vector2 p1 = *this; Vector2 p2 = p_b; @@ -210,65 +190,52 @@ bool Vector2::is_equal_approx(const Vector2 &p_v) const { /* Vector2i */ Vector2i Vector2i::operator+(const Vector2i &p_v) const { - return Vector2i(x + p_v.x, y + p_v.y); } void Vector2i::operator+=(const Vector2i &p_v) { - x += p_v.x; y += p_v.y; } Vector2i Vector2i::operator-(const Vector2i &p_v) const { - return Vector2i(x - p_v.x, y - p_v.y); } void Vector2i::operator-=(const Vector2i &p_v) { - x -= p_v.x; y -= p_v.y; } Vector2i Vector2i::operator*(const Vector2i &p_v1) const { - return Vector2i(x * p_v1.x, y * p_v1.y); }; Vector2i Vector2i::operator*(const int &rvalue) const { - return Vector2i(x * rvalue, y * rvalue); }; void Vector2i::operator*=(const int &rvalue) { - x *= rvalue; y *= rvalue; }; Vector2i Vector2i::operator/(const Vector2i &p_v1) const { - return Vector2i(x / p_v1.x, y / p_v1.y); }; Vector2i Vector2i::operator/(const int &rvalue) const { - return Vector2i(x / rvalue, y / rvalue); }; void Vector2i::operator/=(const int &rvalue) { - x /= rvalue; y /= rvalue; }; Vector2i Vector2i::operator-() const { - return Vector2i(-x, -y); } bool Vector2i::operator==(const Vector2i &p_vec2) const { - return x == p_vec2.x && y == p_vec2.y; } bool Vector2i::operator!=(const Vector2i &p_vec2) const { - return x != p_vec2.x || y != p_vec2.y; } diff --git a/core/math/vector2.h b/core/math/vector2.h index 5a3e6a0660..5aa40d45f7 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -37,7 +37,6 @@ struct Vector2i; struct Vector2 { - enum Axis { AXIS_X, AXIS_Y, @@ -123,13 +122,11 @@ struct Vector2 { real_t angle() const; _FORCE_INLINE_ Vector2 abs() const { - return Vector2(Math::abs(x), Math::abs(y)); } Vector2 rotated(real_t p_by) const; Vector2 tangent() const { - return Vector2(y, -x); } @@ -150,81 +147,65 @@ struct Vector2 { }; _FORCE_INLINE_ Vector2 Vector2::plane_project(real_t p_d, const Vector2 &p_vec) const { - return p_vec - *this * (dot(p_vec) - p_d); } _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::lerp(const Vector2 &p_b, real_t p_t) const { - Vector2 res = *this; res.x += (p_t * (p_b.x - x)); @@ -253,7 +234,6 @@ typedef Vector2 Point2; /* INTEGER STUFF */ struct Vector2i { - enum Axis { AXIS_X, AXIS_Y, diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp index 353b2acd16..8acbe31f35 100644 --- a/core/math/vector3.cpp +++ b/core/math/vector3.cpp @@ -33,12 +33,10 @@ #include "core/math/basis.h" void Vector3::rotate(const Vector3 &p_axis, real_t p_phi) { - *this = Basis(p_axis, p_phi).xform(*this); } Vector3 Vector3::rotated(const Vector3 &p_axis, real_t p_phi) const { - Vector3 r = *this; r.rotate(p_axis, p_phi); return r; @@ -49,35 +47,29 @@ void Vector3::set_axis(int p_axis, real_t p_value) { coord[p_axis] = p_value; } real_t Vector3::get_axis(int p_axis) const { - ERR_FAIL_INDEX_V(p_axis, 3, 0); return operator[](p_axis); } int Vector3::min_axis() const { - return x < y ? (x < z ? 0 : 2) : (y < z ? 1 : 2); } int Vector3::max_axis() const { - return x < y ? (y < z ? 2 : 1) : (x < z ? 2 : 0); } void Vector3::snap(Vector3 p_val) { - x = Math::stepify(x, p_val.x); y = Math::stepify(y, p_val.y); z = Math::stepify(z, p_val.z); } Vector3 Vector3::snapped(Vector3 p_val) const { - Vector3 v = *this; v.snap(p_val); return v; } Vector3 Vector3::cubic_interpolaten(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_t) const { - Vector3 p0 = p_pre_a; Vector3 p1 = *this; Vector3 p2 = p_b; @@ -109,7 +101,6 @@ Vector3 Vector3::cubic_interpolaten(const Vector3 &p_b, const Vector3 &p_pre_a, } Vector3 Vector3::cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_t) const { - Vector3 p0 = p_pre_a; Vector3 p1 = *this; Vector3 p2 = p_b; @@ -135,7 +126,6 @@ Vector3 Vector3::move_toward(const Vector3 &p_to, const real_t p_delta) const { } Basis Vector3::outer(const Vector3 &p_b) const { - Vector3 row0(x * p_b.x, x * p_b.y, x * p_b.z); Vector3 row1(y * p_b.x, y * p_b.y, y * p_b.z); Vector3 row2(z * p_b.x, z * p_b.y, z * p_b.z); @@ -150,11 +140,9 @@ Basis Vector3::to_diagonal_matrix() const { } bool Vector3::is_equal_approx(const Vector3 &p_v) const { - return Math::is_equal_approx(x, p_v.x) && Math::is_equal_approx(y, p_v.y) && Math::is_equal_approx(z, p_v.z); } Vector3::operator String() const { - return (rtos(x) + ", " + rtos(y) + ", " + rtos(z)); } diff --git a/core/math/vector3.h b/core/math/vector3.h index 7131063e04..5fc412628f 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -38,7 +38,6 @@ class Basis; struct Vector3 { - enum Axis { AXIS_X, AXIS_Y, @@ -56,12 +55,10 @@ struct Vector3 { }; _FORCE_INLINE_ const real_t &operator[](int p_axis) const { - return coord[p_axis]; } _FORCE_INLINE_ real_t &operator[](int p_axis) { - return coord[p_axis]; } @@ -166,7 +163,6 @@ struct Vector3 { }; Vector3 Vector3::cross(const Vector3 &p_b) const { - Vector3 ret( (y * p_b.z) - (z * p_b.y), (z * p_b.x) - (x * p_b.z), @@ -176,37 +172,30 @@ Vector3 Vector3::cross(const Vector3 &p_b) const { } real_t Vector3::dot(const Vector3 &p_b) const { - return x * p_b.x + y * p_b.y + z * p_b.z; } 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)); } Vector3 Vector3::ceil() const { - return Vector3(Math::ceil(x), Math::ceil(y), Math::ceil(z)); } Vector3 Vector3::round() const { - return Vector3(Math::round(x), Math::round(y), Math::round(z)); } Vector3 Vector3::lerp(const Vector3 &p_b, real_t p_t) const { - return Vector3( x + (p_t * (p_b.x - x)), y + (p_t * (p_b.y - y)), @@ -219,12 +208,10 @@ Vector3 Vector3::slerp(const Vector3 &p_b, real_t p_t) const { } real_t Vector3::distance_to(const Vector3 &p_b) const { - return (p_b - *this).length(); } real_t Vector3::distance_squared_to(const Vector3 &p_b) const { - return (p_b - *this).length_squared(); } @@ -241,7 +228,6 @@ Vector3 Vector3::project(const Vector3 &p_b) const { } real_t Vector3::angle_to(const Vector3 &p_b) const { - return Math::atan2(cross(p_b).length(), dot(p_b)); } @@ -254,7 +240,6 @@ Vector3 Vector3::direction_to(const Vector3 &p_b) const { /* Operators */ Vector3 &Vector3::operator+=(const Vector3 &p_v) { - x += p_v.x; y += p_v.y; z += p_v.z; @@ -262,36 +247,30 @@ Vector3 &Vector3::operator+=(const Vector3 &p_v) { } Vector3 Vector3::operator+(const Vector3 &p_v) const { - return Vector3(x + p_v.x, y + p_v.y, z + p_v.z); } Vector3 &Vector3::operator-=(const Vector3 &p_v) { - x -= p_v.x; y -= p_v.y; z -= p_v.z; return *this; } Vector3 Vector3::operator-(const Vector3 &p_v) const { - return Vector3(x - p_v.x, y - p_v.y, z - p_v.z); } Vector3 &Vector3::operator*=(const Vector3 &p_v) { - x *= p_v.x; y *= p_v.y; z *= p_v.z; return *this; } Vector3 Vector3::operator*(const Vector3 &p_v) const { - return Vector3(x * p_v.x, y * p_v.y, z * p_v.z); } Vector3 &Vector3::operator/=(const Vector3 &p_v) { - x /= p_v.x; y /= p_v.y; z /= p_v.z; @@ -299,12 +278,10 @@ Vector3 &Vector3::operator/=(const Vector3 &p_v) { } Vector3 Vector3::operator/(const Vector3 &p_v) const { - return Vector3(x / p_v.x, y / p_v.y, z / p_v.z); } Vector3 &Vector3::operator*=(real_t p_scalar) { - x *= p_scalar; y *= p_scalar; z *= p_scalar; @@ -312,17 +289,14 @@ Vector3 &Vector3::operator*=(real_t p_scalar) { } _FORCE_INLINE_ Vector3 operator*(real_t p_scalar, const Vector3 &p_vec) { - return p_vec * p_scalar; } Vector3 Vector3::operator*(real_t p_scalar) const { - return Vector3(x * p_scalar, y * p_scalar, z * p_scalar); } Vector3 &Vector3::operator/=(real_t p_scalar) { - x /= p_scalar; y /= p_scalar; z /= p_scalar; @@ -330,27 +304,22 @@ Vector3 &Vector3::operator/=(real_t p_scalar) { } Vector3 Vector3::operator/(real_t p_scalar) const { - return Vector3(x / p_scalar, y / p_scalar, z / p_scalar); } Vector3 Vector3::operator-() const { - return Vector3(-x, -y, -z); } bool Vector3::operator==(const Vector3 &p_v) const { - return x == p_v.x && y == p_v.y && z == p_v.z; } bool Vector3::operator!=(const Vector3 &p_v) const { - return x != p_v.x || y != p_v.y || z != p_v.z; } bool Vector3::operator<(const Vector3 &p_v) const { - if (Math::is_equal_approx(x, p_v.x)) { if (Math::is_equal_approx(y, p_v.y)) return z < p_v.z; @@ -362,7 +331,6 @@ bool Vector3::operator<(const Vector3 &p_v) const { } bool Vector3::operator>(const Vector3 &p_v) const { - if (Math::is_equal_approx(x, p_v.x)) { if (Math::is_equal_approx(y, p_v.y)) return z > p_v.z; @@ -374,7 +342,6 @@ bool Vector3::operator>(const Vector3 &p_v) const { } bool Vector3::operator<=(const Vector3 &p_v) const { - if (Math::is_equal_approx(x, p_v.x)) { if (Math::is_equal_approx(y, p_v.y)) return z <= p_v.z; @@ -386,7 +353,6 @@ bool Vector3::operator<=(const Vector3 &p_v) const { } bool Vector3::operator>=(const Vector3 &p_v) const { - if (Math::is_equal_approx(x, p_v.x)) { if (Math::is_equal_approx(y, p_v.y)) return z >= p_v.z; @@ -398,17 +364,14 @@ bool Vector3::operator>=(const Vector3 &p_v) const { } _FORCE_INLINE_ Vector3 vec3_cross(const Vector3 &p_a, const Vector3 &p_b) { - return p_a.cross(p_b); } _FORCE_INLINE_ real_t vec3_dot(const Vector3 &p_a, const Vector3 &p_b) { - return p_a.dot(p_b); } real_t Vector3::length() const { - real_t x2 = x * x; real_t y2 = y * y; real_t z2 = z * z; @@ -417,7 +380,6 @@ real_t Vector3::length() const { } real_t Vector3::length_squared() const { - real_t x2 = x * x; real_t y2 = y * y; real_t z2 = z * z; @@ -426,7 +388,6 @@ real_t Vector3::length_squared() const { } void Vector3::normalize() { - real_t lengthsq = length_squared(); if (lengthsq == 0) { x = y = z = 0; @@ -439,7 +400,6 @@ void Vector3::normalize() { } Vector3 Vector3::normalized() const { - Vector3 v = *this; v.normalize(); return v; @@ -451,12 +411,10 @@ bool Vector3::is_normalized() const { } Vector3 Vector3::inverse() const { - return Vector3(1.0 / x, 1.0 / y, 1.0 / z); } void Vector3::zero() { - x = y = z = 0; } diff --git a/core/math/vector3i.cpp b/core/math/vector3i.cpp index 8a4ddf03b9..e621d5493a 100644 --- a/core/math/vector3i.cpp +++ b/core/math/vector3i.cpp @@ -35,21 +35,17 @@ void Vector3i::set_axis(int p_axis, int32_t p_value) { coord[p_axis] = p_value; } int32_t Vector3i::get_axis(int p_axis) const { - ERR_FAIL_INDEX_V(p_axis, 3, 0); return operator[](p_axis); } int Vector3i::min_axis() const { - return x < y ? (x < z ? 0 : 2) : (y < z ? 1 : 2); } int Vector3i::max_axis() const { - return x < y ? (y < z ? 2 : 1) : (x < z ? 2 : 0); } Vector3i::operator String() const { - return (itos(x) + ", " + itos(y) + ", " + itos(z)); } diff --git a/core/math/vector3i.h b/core/math/vector3i.h index 60e5b94c12..5ecd3228b2 100644 --- a/core/math/vector3i.h +++ b/core/math/vector3i.h @@ -35,7 +35,6 @@ #include "core/ustring.h" struct Vector3i { - enum Axis { AXIS_X, AXIS_Y, @@ -53,12 +52,10 @@ struct Vector3i { }; _FORCE_INLINE_ const int32_t &operator[](int p_axis) const { - return coord[p_axis]; } _FORCE_INLINE_ int32_t &operator[](int p_axis) { - return coord[p_axis]; } @@ -109,19 +106,16 @@ struct Vector3i { }; Vector3i Vector3i::abs() const { - return Vector3i(ABS(x), ABS(y), ABS(z)); } Vector3i Vector3i::sign() const { - return Vector3i(SGN(x), SGN(y), SGN(z)); } /* Operators */ Vector3i &Vector3i::operator+=(const Vector3i &p_v) { - x += p_v.x; y += p_v.y; z += p_v.z; @@ -129,36 +123,30 @@ Vector3i &Vector3i::operator+=(const Vector3i &p_v) { } Vector3i Vector3i::operator+(const Vector3i &p_v) const { - return Vector3i(x + p_v.x, y + p_v.y, z + p_v.z); } Vector3i &Vector3i::operator-=(const Vector3i &p_v) { - x -= p_v.x; y -= p_v.y; z -= p_v.z; return *this; } Vector3i Vector3i::operator-(const Vector3i &p_v) const { - return Vector3i(x - p_v.x, y - p_v.y, z - p_v.z); } Vector3i &Vector3i::operator*=(const Vector3i &p_v) { - x *= p_v.x; y *= p_v.y; z *= p_v.z; return *this; } Vector3i Vector3i::operator*(const Vector3i &p_v) const { - return Vector3i(x * p_v.x, y * p_v.y, z * p_v.z); } Vector3i &Vector3i::operator/=(const Vector3i &p_v) { - x /= p_v.x; y /= p_v.y; z /= p_v.z; @@ -166,12 +154,10 @@ Vector3i &Vector3i::operator/=(const Vector3i &p_v) { } Vector3i Vector3i::operator/(const Vector3i &p_v) const { - return Vector3i(x / p_v.x, y / p_v.y, z / p_v.z); } Vector3i &Vector3i::operator*=(int32_t p_scalar) { - x *= p_scalar; y *= p_scalar; z *= p_scalar; @@ -179,17 +165,14 @@ Vector3i &Vector3i::operator*=(int32_t p_scalar) { } _FORCE_INLINE_ Vector3i operator*(int32_t p_scalar, const Vector3i &p_vec) { - return p_vec * p_scalar; } Vector3i Vector3i::operator*(int32_t p_scalar) const { - return Vector3i(x * p_scalar, y * p_scalar, z * p_scalar); } Vector3i &Vector3i::operator/=(int32_t p_scalar) { - x /= p_scalar; y /= p_scalar; z /= p_scalar; @@ -197,27 +180,22 @@ Vector3i &Vector3i::operator/=(int32_t p_scalar) { } Vector3i Vector3i::operator/(int32_t p_scalar) const { - return Vector3i(x / p_scalar, y / p_scalar, z / p_scalar); } Vector3i Vector3i::operator-() const { - return Vector3i(-x, -y, -z); } bool Vector3i::operator==(const Vector3i &p_v) const { - return (x == p_v.x && y == p_v.y && z == p_v.z); } bool Vector3i::operator!=(const Vector3i &p_v) const { - return (x != p_v.x || y != p_v.y || z != p_v.z); } bool Vector3i::operator<(const Vector3i &p_v) const { - if (x == p_v.x) { if (y == p_v.y) return z < p_v.z; @@ -229,7 +207,6 @@ bool Vector3i::operator<(const Vector3i &p_v) const { } bool Vector3i::operator>(const Vector3i &p_v) const { - if (x == p_v.x) { if (y == p_v.y) return z > p_v.z; @@ -241,7 +218,6 @@ bool Vector3i::operator>(const Vector3i &p_v) const { } bool Vector3i::operator<=(const Vector3i &p_v) const { - if (x == p_v.x) { if (y == p_v.y) return z <= p_v.z; @@ -253,7 +229,6 @@ bool Vector3i::operator<=(const Vector3i &p_v) const { } bool Vector3i::operator>=(const Vector3i &p_v) const { - if (x == p_v.x) { if (y == p_v.y) return z >= p_v.z; @@ -265,7 +240,6 @@ bool Vector3i::operator>=(const Vector3i &p_v) const { } void Vector3i::zero() { - x = y = z = 0; } diff --git a/core/message_queue.cpp b/core/message_queue.cpp index ad4211f3da..4de4c48578 100644 --- a/core/message_queue.cpp +++ b/core/message_queue.cpp @@ -37,17 +37,14 @@ MessageQueue *MessageQueue::singleton = nullptr; MessageQueue *MessageQueue::get_singleton() { - return singleton; } Error MessageQueue::push_call(ObjectID p_id, const StringName &p_method, const Variant **p_args, int p_argcount, bool p_show_error) { - return push_callable(Callable(p_id, p_method), p_args, p_argcount, p_show_error); } Error MessageQueue::push_call(ObjectID p_id, const StringName &p_method, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS; int argc = 0; @@ -62,7 +59,6 @@ Error MessageQueue::push_call(ObjectID p_id, const StringName &p_method, VARIANT } Error MessageQueue::push_set(ObjectID p_id, const StringName &p_prop, const Variant &p_value) { - _THREAD_SAFE_METHOD_ uint8_t room_needed = sizeof(Message) + sizeof(Variant); @@ -91,7 +87,6 @@ Error MessageQueue::push_set(ObjectID p_id, const StringName &p_prop, const Vari } Error MessageQueue::push_notification(ObjectID p_id, int p_notification) { - _THREAD_SAFE_METHOD_ ERR_FAIL_COND_V(p_notification < 0, ERR_INVALID_PARAMETER); @@ -117,21 +112,17 @@ Error MessageQueue::push_notification(ObjectID p_id, int p_notification) { } Error MessageQueue::push_call(Object *p_object, const StringName &p_method, VARIANT_ARG_DECLARE) { - return push_call(p_object->get_instance_id(), p_method, VARIANT_ARG_PASS); } Error MessageQueue::push_notification(Object *p_object, int p_notification) { - return push_notification(p_object->get_instance_id(), p_notification); } Error MessageQueue::push_set(Object *p_object, const StringName &p_prop, const Variant &p_value) { - return push_set(p_object->get_instance_id(), p_prop, p_value); } Error MessageQueue::push_callable(const Callable &p_callable, const Variant **p_args, int p_argcount, bool p_show_error) { - _THREAD_SAFE_METHOD_ int room_needed = sizeof(Message) + sizeof(Variant) * p_argcount; @@ -152,7 +143,6 @@ Error MessageQueue::push_callable(const Callable &p_callable, const Variant **p_ buffer_end += sizeof(Message); for (int i = 0; i < p_argcount; i++) { - Variant *v = memnew_placement(&buffer[buffer_end], Variant); buffer_end += sizeof(Variant); *v = *p_args[i]; @@ -162,7 +152,6 @@ Error MessageQueue::push_callable(const Callable &p_callable, const Variant **p_ } void MessageQueue::statistics() { - Map<StringName, int> set_count; Map<int, int> notify_count; Map<Callable, int> call_count; @@ -175,11 +164,8 @@ void MessageQueue::statistics() { Object *target = message->callable.get_object(); if (target != nullptr) { - switch (message->type & FLAG_MASK) { - case TYPE_CALL: { - if (!call_count.has(message->callable)) call_count[message->callable] = 0; @@ -187,7 +173,6 @@ void MessageQueue::statistics() { } break; case TYPE_NOTIFICATION: { - if (!notify_count.has(message->notification)) notify_count[message->notification] = 0; @@ -195,7 +180,6 @@ void MessageQueue::statistics() { } break; case TYPE_SET: { - StringName t = message->callable.get_method(); if (!set_count.has(t)) set_count[t] = 0; @@ -234,12 +218,10 @@ void MessageQueue::statistics() { } int MessageQueue::get_max_buffer_usage() const { - return buffer_max_used; } void MessageQueue::_call_function(const Callable &p_callable, const Variant *p_args, int p_argcount, bool p_show_error) { - const Variant **argptrs = nullptr; if (p_argcount) { argptrs = (const Variant **)alloca(sizeof(Variant *) * p_argcount); @@ -252,13 +234,11 @@ void MessageQueue::_call_function(const Callable &p_callable, const Variant *p_a Variant ret; p_callable.call(argptrs, p_argcount, ret, ce); if (p_show_error && ce.error != Callable::CallError::CALL_OK) { - ERR_PRINT("Error calling deferred method: " + Variant::get_callable_error_text(p_callable, argptrs, p_argcount, ce) + "."); } } void MessageQueue::flush() { - if (buffer_end > buffer_max_used) { buffer_max_used = buffer_end; } @@ -275,7 +255,6 @@ void MessageQueue::flush() { flushing = true; while (read_pos < buffer_end) { - //lock on each iteration, so a call can re-add itself to the message queue Message *message = (Message *)&buffer[read_pos]; @@ -292,10 +271,8 @@ void MessageQueue::flush() { Object *target = message->callable.get_object(); if (target != nullptr) { - switch (message->type & FLAG_MASK) { case TYPE_CALL: { - Variant *args = (Variant *)(message + 1); // messages don't expect a return value @@ -304,13 +281,11 @@ void MessageQueue::flush() { } break; case TYPE_NOTIFICATION: { - // messages don't expect a return value target->notification(message->notification); } break; case TYPE_SET: { - Variant *arg = (Variant *)(message + 1); // messages don't expect a return value target->set(message->callable.get_method(), *arg); @@ -337,12 +312,10 @@ void MessageQueue::flush() { } bool MessageQueue::is_flushing() const { - return flushing; } MessageQueue::MessageQueue() { - ERR_FAIL_COND_MSG(singleton != nullptr, "A MessageQueue singleton already exists."); singleton = this; @@ -353,11 +326,9 @@ MessageQueue::MessageQueue() { } MessageQueue::~MessageQueue() { - uint32_t read_pos = 0; while (read_pos < buffer_end) { - Message *message = (Message *)&buffer[read_pos]; Variant *args = (Variant *)(message + 1); int argc = message->args; diff --git a/core/message_queue.h b/core/message_queue.h index 180e0ce362..8e50f1b2b7 100644 --- a/core/message_queue.h +++ b/core/message_queue.h @@ -35,7 +35,6 @@ #include "core/os/thread_safe.h" class MessageQueue { - _THREAD_SAFE_CLASS_ enum { @@ -53,7 +52,6 @@ class MessageQueue { }; struct Message { - Callable callable; int16_t type; union { diff --git a/core/method_bind.cpp b/core/method_bind.cpp index 854e19cf8a..610111a3e8 100644 --- a/core/method_bind.cpp +++ b/core/method_bind.cpp @@ -36,7 +36,6 @@ #ifdef DEBUG_METHODS_ENABLED PropertyInfo MethodBind::get_argument_info(int p_argument) const { - ERR_FAIL_INDEX_V(p_argument, get_argument_count(), PropertyInfo()); PropertyInfo info = _gen_argument_type_info(p_argument); @@ -45,18 +44,15 @@ PropertyInfo MethodBind::get_argument_info(int p_argument) const { } PropertyInfo MethodBind::get_return_info() const { - return _gen_argument_type_info(-1); } #endif void MethodBind::_set_const(bool p_const) { - _const = p_const; } void MethodBind::_set_returns(bool p_returns) { - _returns = p_returns; } @@ -69,11 +65,9 @@ void MethodBind::set_name(const StringName &p_name) { #ifdef DEBUG_METHODS_ENABLED void MethodBind::set_argument_names(const Vector<StringName> &p_names) { - arg_names = p_names; } Vector<StringName> MethodBind::get_argument_names() const { - return arg_names; } @@ -86,7 +80,6 @@ void MethodBind::set_default_arguments(const Vector<Variant> &p_defargs) { #ifdef DEBUG_METHODS_ENABLED void MethodBind::_generate_argument_types(int p_count) { - set_argument_count(p_count); Variant::Type *argt = memnew_arr(Variant::Type, p_count + 1); diff --git a/core/method_bind.h b/core/method_bind.h index 0092527a25..7f3da9c25e 100644 --- a/core/method_bind.h +++ b/core/method_bind.h @@ -59,27 +59,21 @@ enum MethodFlags { template <class T> struct VariantCaster { - static _FORCE_INLINE_ T cast(const Variant &p_variant) { - return p_variant; } }; template <class T> struct VariantCaster<T &> { - static _FORCE_INLINE_ T cast(const Variant &p_variant) { - return p_variant; } }; template <class T> struct VariantCaster<const T &> { - static _FORCE_INLINE_ T cast(const Variant &p_variant) { - return p_variant; } }; @@ -93,7 +87,6 @@ struct VariantCaster<const T &> { MAKE_ENUM_TYPE_INFO(m_enum) \ template <> \ struct VariantCaster<m_enum> { \ - \ static _FORCE_INLINE_ m_enum cast(const Variant &p_variant) { \ return (m_enum)p_variant.operator int(); \ } \ @@ -114,7 +107,6 @@ struct VariantCaster<const T &> { MAKE_ENUM_TYPE_INFO(m_enum) \ template <> \ struct VariantCaster<m_enum> { \ - \ static _FORCE_INLINE_ m_enum cast(const Variant &p_variant) { \ return (m_enum)p_variant.operator int(); \ } \ @@ -206,7 +198,6 @@ struct PtrToArg<wchar_t> { #endif class MethodBind { - int method_id; uint32_t hint_flags = METHOD_FLAGS_DEFAULT; StringName name; @@ -237,7 +228,6 @@ public: _FORCE_INLINE_ int get_default_argument_count() const { return default_argument_count; } _FORCE_INLINE_ Variant has_default_argument(int p_arg) const { - int idx = argument_count - p_arg - 1; if (idx < 0 || idx >= default_arguments.size()) @@ -247,7 +237,6 @@ public: } _FORCE_INLINE_ Variant get_default_argument(int p_arg) const { - int idx = argument_count - p_arg - 1; if (idx < 0 || idx >= default_arguments.size()) @@ -259,7 +248,6 @@ public: #ifdef DEBUG_METHODS_ENABLED _FORCE_INLINE_ Variant::Type get_argument_type(int p_argument) const { - ERR_FAIL_COND_V(p_argument < -1 || p_argument > argument_count, Variant::NIL); return argument_types[p_argument + 1]; } @@ -313,7 +301,6 @@ public: #ifdef DEBUG_METHODS_ENABLED virtual PropertyInfo _gen_argument_type_info(int p_arg) const { - if (p_arg < 0) { return arguments.return_val; } else if (p_arg < arguments.arguments.size()) { @@ -339,23 +326,19 @@ public: #endif virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { - T *instance = static_cast<T *>(p_object); return (instance->*call_method)(p_args, p_arg_count, r_error); } void set_method_info(const MethodInfo &p_info, bool p_return_nil_is_variant) { - set_argument_count(p_info.arguments.size()); #ifdef DEBUG_METHODS_ENABLED Variant::Type *at = memnew_arr(Variant::Type, p_info.arguments.size() + 1); at[0] = p_info.return_val.type; if (p_info.arguments.size()) { - Vector<StringName> names; names.resize(p_info.arguments.size()); for (int i = 0; i < p_info.arguments.size(); i++) { - at[i + 1] = p_info.arguments[i].type; names.write[i] = p_info.arguments[i].name; } @@ -389,7 +372,6 @@ public: template <class T> MethodBind *create_vararg_method_bind(Variant (T::*p_method)(const Variant **, int, Callable::CallError &), const MethodInfo &p_info, bool p_return_nil_is_variant) { - MethodBindVarArg<T> *a = memnew((MethodBindVarArg<T>)); a->set_method(p_method); a->set_method_info(p_info, p_return_nil_is_variant); diff --git a/core/method_ptrcall.h b/core/method_ptrcall.h index 7ae0a788bd..022ed2a5d6 100644 --- a/core/method_ptrcall.h +++ b/core/method_ptrcall.h @@ -150,28 +150,22 @@ MAKE_PTRARG_BY_REFERENCE(Variant); template <class T> struct PtrToArg<T *> { - _FORCE_INLINE_ static T *convert(const void *p_ptr) { - return const_cast<T *>(reinterpret_cast<const T *>(p_ptr)); } _FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) { - *((T **)p_ptr) = p_var; } }; template <class T> struct PtrToArg<const T *> { - _FORCE_INLINE_ static const T *convert(const void *p_ptr) { - return reinterpret_cast<const T *>(p_ptr); } _FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) { - *((T **)p_ptr) = p_var; } }; @@ -181,12 +175,10 @@ struct PtrToArg<const T *> { template <> struct PtrToArg<ObjectID> { _FORCE_INLINE_ static const ObjectID convert(const void *p_ptr) { - return ObjectID(*reinterpret_cast<const uint64_t *>(p_ptr)); } _FORCE_INLINE_ static void encode(const ObjectID &p_val, void *p_ptr) { - *((uint64_t *)p_ptr) = p_val; } }; diff --git a/core/node_path.cpp b/core/node_path.cpp index f8001a354a..0e4f2eeaf0 100644 --- a/core/node_path.cpp +++ b/core/node_path.cpp @@ -33,7 +33,6 @@ #include "core/print_string.h" void NodePath::_update_hash_cache() const { - uint32_t h = data->absolute ? 1 : 0; int pc = data->path.size(); const StringName *sn = data->path.ptr(); @@ -51,7 +50,6 @@ void NodePath::_update_hash_cache() const { } void NodePath::prepend_period() { - if (data->path.size() && data->path[0].operator String() != ".") { data->path.insert(0, "."); data->hash_cache_valid = false; @@ -59,51 +57,43 @@ void NodePath::prepend_period() { } bool NodePath::is_absolute() const { - if (!data) return false; return data->absolute; } int NodePath::get_name_count() const { - if (!data) return 0; return data->path.size(); } StringName NodePath::get_name(int p_idx) const { - ERR_FAIL_COND_V(!data, StringName()); ERR_FAIL_INDEX_V(p_idx, data->path.size(), StringName()); return data->path[p_idx]; } int NodePath::get_subname_count() const { - if (!data) return 0; return data->subpath.size(); } StringName NodePath::get_subname(int p_idx) const { - ERR_FAIL_COND_V(!data, StringName()); ERR_FAIL_INDEX_V(p_idx, data->subpath.size(), StringName()); return data->subpath[p_idx]; } void NodePath::unref() { - if (data && data->refcount.unref()) { - memdelete(data); } data = nullptr; } bool NodePath::operator==(const NodePath &p_path) const { - if (data == p_path.data) return true; @@ -129,7 +119,6 @@ bool NodePath::operator==(const NodePath &p_path) const { const StringName *r_path_ptr = p_path.data->path.ptr(); for (int i = 0; i < path_size; i++) { - if (l_path_ptr[i] != r_path_ptr[i]) return false; } @@ -138,7 +127,6 @@ bool NodePath::operator==(const NodePath &p_path) const { const StringName *r_subpath_ptr = p_path.data->subpath.ptr(); for (int i = 0; i < subpath_size; i++) { - if (l_subpath_ptr[i] != r_subpath_ptr[i]) return false; } @@ -146,25 +134,21 @@ bool NodePath::operator==(const NodePath &p_path) const { return true; } bool NodePath::operator!=(const NodePath &p_path) const { - return (!(*this == p_path)); } void NodePath::operator=(const NodePath &p_path) { - if (this == &p_path) return; unref(); if (p_path.data && p_path.data->refcount.ref()) { - data = p_path.data; } } NodePath::operator String() const { - if (!data) return String(); @@ -173,14 +157,12 @@ NodePath::operator String() const { ret = "/"; for (int i = 0; i < data->path.size(); i++) { - if (i > 0) ret += "/"; ret += data->path[i].operator String(); } for (int i = 0; i < data->subpath.size(); i++) { - ret += ":" + data->subpath[i].operator String(); } @@ -188,14 +170,12 @@ NodePath::operator String() const { } Vector<StringName> NodePath::get_names() const { - if (data) return data->path; return Vector<StringName>(); } Vector<StringName> NodePath::get_subnames() const { - if (data) return data->subpath; return Vector<StringName>(); @@ -217,7 +197,6 @@ StringName NodePath::get_concatenated_subnames() const { } NodePath NodePath::rel_path_to(const NodePath &p_np) const { - ERR_FAIL_COND_V(!is_absolute(), NodePath()); ERR_FAIL_COND_V(!p_np.is_absolute(), NodePath()); @@ -242,12 +221,10 @@ NodePath NodePath::rel_path_to(const NodePath &p_np) const { Vector<StringName> relpath; for (int i = src_dirs.size() - 1; i > common_parent; i--) { - relpath.push_back(".."); } for (int i = common_parent + 1; i < dst_dirs.size(); i++) { - relpath.push_back(dst_dirs[i]); } @@ -258,7 +235,6 @@ NodePath NodePath::rel_path_to(const NodePath &p_np) const { } NodePath NodePath::get_as_property_path() const { - if (!data || !data->path.size()) { return *this; } else { @@ -280,7 +256,6 @@ bool NodePath::is_empty() const { } void NodePath::simplify() { - if (!data) return; for (int i = 0; i < data->path.size(); i++) { @@ -304,7 +279,6 @@ void NodePath::simplify() { } NodePath NodePath::simplified() const { - NodePath np = *this; np.simplify(); return np; @@ -355,13 +329,10 @@ NodePath::NodePath(const String &p_path) { int subpath_pos = path.find(":"); if (subpath_pos != -1) { - int from = subpath_pos + 1; for (int i = from; i <= path.length(); i++) { - if (path[i] == ':' || path[i] == 0) { - String str = path.substr(from, i - from); if (str == "") { if (path[i] == 0) @@ -379,13 +350,10 @@ NodePath::NodePath(const String &p_path) { } for (int i = (int)absolute; i < path.length(); i++) { - if (path[i] == '/') { - last_is_slash = true; has_slashes = true; } else { - if (last_is_slash) slices++; @@ -411,11 +379,8 @@ NodePath::NodePath(const String &p_path) { int slice = 0; for (int i = (int)absolute; i < path.length() + 1; i++) { - if (path[i] == '/' || path[i] == 0) { - if (!last_is_slash) { - String name = path.substr(from, i - from); ERR_FAIL_INDEX(slice, data->path.size()); data->path.write[slice++] = name; diff --git a/core/node_path.h b/core/node_path.h index fb15d017bf..8f89b9fadf 100644 --- a/core/node_path.h +++ b/core/node_path.h @@ -35,9 +35,7 @@ #include "core/ustring.h" class NodePath { - struct Data { - SafeRefCount refcount; Vector<StringName> path; Vector<StringName> subpath; diff --git a/core/oa_hash_map.h b/core/oa_hash_map.h index b4d9ce4d51..e411ced044 100644 --- a/core/oa_hash_map.h +++ b/core/oa_hash_map.h @@ -50,7 +50,6 @@ template <class TKey, class TValue, class Hasher = HashMapHasherDefault, class Comparator = HashMapComparatorDefault<TKey>> class OAHashMap { - private: TValue *values; TKey *keys; @@ -110,7 +109,6 @@ private: } void _insert_with_hash(uint32_t p_hash, const TKey &p_key, const TValue &p_value) { - uint32_t hash = p_hash; uint32_t distance = 0; uint32_t pos = hash % capacity; @@ -140,7 +138,6 @@ private: } void _resize_and_rehash(uint32_t p_new_capacity) { - uint32_t old_capacity = capacity; capacity = p_new_capacity; @@ -183,9 +180,7 @@ public: } void clear() { - for (uint32_t i = 0; i < capacity; i++) { - if (hashes[i] == EMPTY_HASH) { continue; } @@ -199,7 +194,6 @@ public: } void insert(const TKey &p_key, const TValue &p_value) { - if (num_elements + 1 > 0.9 * capacity) { _resize_and_rehash(); } @@ -317,7 +311,6 @@ public: } Iterator next_iter(const Iterator &p_iter) const { - if (!p_iter.valid) { return p_iter; } @@ -348,7 +341,6 @@ public: OAHashMap &operator=(const OAHashMap &) = delete; // Same for assignment operator. OAHashMap(uint32_t p_initial_capacity = 64) { - capacity = p_initial_capacity; keys = memnew_arr(TKey, p_initial_capacity); @@ -361,7 +353,6 @@ public: } ~OAHashMap() { - memdelete_arr(keys); memdelete_arr(values); memdelete_arr(hashes); diff --git a/core/object.cpp b/core/object.cpp index 9ae2d2dcde..50bf7d4d28 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -42,7 +42,6 @@ #ifdef DEBUG_ENABLED struct _ObjectDebugLock { - Object *obj; _ObjectDebugLock(Object *p_obj) { @@ -63,7 +62,6 @@ struct _ObjectDebugLock { #endif PropertyInfo::operator Dictionary() const { - Dictionary d; d["name"] = name; d["class_name"] = class_name; @@ -75,7 +73,6 @@ PropertyInfo::operator Dictionary() const { } PropertyInfo PropertyInfo::from_dict(const Dictionary &p_dict) { - PropertyInfo pi; if (p_dict.has("type")) @@ -101,10 +98,8 @@ PropertyInfo PropertyInfo::from_dict(const Dictionary &p_dict) { } Array convert_property_list(const List<PropertyInfo> *p_list) { - Array va; for (const List<PropertyInfo>::Element *E = p_list->front(); E; E = E->next()) { - va.push_back(Dictionary(E->get())); } @@ -112,7 +107,6 @@ Array convert_property_list(const List<PropertyInfo> *p_list) { } MethodInfo::operator Dictionary() const { - Dictionary d; d["name"] = name; d["args"] = convert_property_list(&arguments); @@ -128,7 +122,6 @@ MethodInfo::operator Dictionary() const { } MethodInfo MethodInfo::from_dict(const Dictionary &p_dict) { - MethodInfo mi; if (p_dict.has("name")) @@ -312,7 +305,6 @@ MethodInfo::MethodInfo(const PropertyInfo &p_ret, const String &p_name, const Pr } Object::Connection::operator Variant() const { - Dictionary d; d["signal"] = signal; d["callable"] = callable; @@ -322,7 +314,6 @@ Object::Connection::operator Variant() const { } bool Object::Connection::operator<(const Connection &p_conn) const { - if (signal == p_conn.signal) { return callable < p_conn.callable; } else { @@ -330,7 +321,6 @@ bool Object::Connection::operator<(const Connection &p_conn) const { } } Object::Connection::Connection(const Variant &p_variant) { - Dictionary d = p_variant; if (d.has("signal")) signal = d["signal"]; @@ -343,7 +333,6 @@ Object::Connection::Connection(const Variant &p_variant) { } bool Object::_predelete() { - _predelete_ok = 1; notification(NOTIFICATION_PREDELETE, true); if (_predelete_ok) { @@ -364,14 +353,12 @@ void Object::_get_valid_parents_static(List<String> *p_parents) { } void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid) { - #ifdef TOOLS_ENABLED _edited = true; #endif if (script_instance) { - if (script_instance->set(p_name, p_value)) { if (r_valid) *r_valid = true; @@ -439,11 +426,9 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid } Variant Object::get(const StringName &p_name, bool *r_valid) const { - Variant ret; if (script_instance) { - if (script_instance->get(p_name, ret)) { if (r_valid) *r_valid = true; @@ -546,7 +531,6 @@ void Object::set_indexed(const Vector<StringName> &p_names, const Variant &p_val value_stack.push_back(p_value); // p_names[p_names.size() - 1] for (int i = p_names.size() - 1; i > 0; i--) { - value_stack.back()->prev()->get().set_named(p_names[i], value_stack.back()->get(), r_valid); value_stack.pop_back(); @@ -584,7 +568,6 @@ Variant Object::get_indexed(const Vector<StringName> &p_names, bool *r_valid) co } void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) const { - if (script_instance && p_reversed) { p_list->push_back(PropertyInfo(Variant::NIL, "Script Variables", PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_CATEGORY)); script_instance->get_property_list(p_list); @@ -611,7 +594,6 @@ void Object::_validate_property(PropertyInfo &property) const { } void Object::get_method_list(List<MethodInfo> *p_list) const { - ClassDB::get_method_list(get_class_name(), p_list); if (script_instance) { script_instance->get_method_list(p_list); @@ -619,7 +601,6 @@ void Object::get_method_list(List<MethodInfo> *p_list) const { } Variant Object::_call_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (p_argcount < 1) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 0; @@ -639,7 +620,6 @@ Variant Object::_call_bind(const Variant **p_args, int p_argcount, Callable::Cal } Variant Object::_call_deferred_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (p_argcount < 1) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 0; @@ -664,24 +644,19 @@ Variant Object::_call_deferred_bind(const Variant **p_args, int p_argcount, Call #ifdef DEBUG_ENABLED static void _test_call_error(const StringName &p_func, const Callable::CallError &error) { - switch (error.error) { - case Callable::CallError::CALL_OK: case Callable::CallError::CALL_ERROR_INVALID_METHOD: break; case Callable::CallError::CALL_ERROR_INVALID_ARGUMENT: { - ERR_FAIL_MSG("Error calling function: " + String(p_func) + " - Invalid type for argument " + itos(error.argument) + ", expected " + Variant::get_type_name(Variant::Type(error.expected)) + "."); break; } case Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: { - ERR_FAIL_MSG("Error calling function: " + String(p_func) + " - Too many arguments, expected " + itos(error.argument) + "."); break; } case Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS: { - ERR_FAIL_MSG("Error calling function: " + String(p_func) + " - Too few arguments, expected " + itos(error.argument) + "."); break; } @@ -696,7 +671,6 @@ static void _test_call_error(const StringName &p_func, const Callable::CallError #endif void Object::call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount) { - if (p_method == CoreStringNames::get_singleton()->_free) { #ifdef DEBUG_ENABLED ERR_FAIL_COND_MSG(Object::cast_to<Reference>(this), "Can't 'free' a reference."); @@ -722,21 +696,18 @@ void Object::call_multilevel(const StringName &p_method, const Variant **p_args, MethodBind *method = ClassDB::get_method(get_class_name(), p_method); if (method) { - method->call(this, p_args, p_argcount, error); _test_call_error(p_method, error); } } void Object::call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount) { - MethodBind *method = ClassDB::get_method(get_class_name(), p_method); Callable::CallError error; OBJ_DEBUG_LOCK if (method) { - method->call(this, p_args, p_argcount, error); _test_call_error(p_method, error); } @@ -750,7 +721,6 @@ void Object::call_multilevel_reversed(const StringName &p_method, const Variant } bool Object::has_method(const StringName &p_method) const { - if (p_method == CoreStringNames::get_singleton()->_free) { return true; } @@ -765,13 +735,11 @@ bool Object::has_method(const StringName &p_method) const { } Variant Object::getvar(const Variant &p_key, bool *r_valid) const { - if (r_valid) *r_valid = false; return Variant(); } void Object::setvar(const Variant &p_key, const Variant &p_value, bool *r_valid) { - if (r_valid) *r_valid = false; } @@ -795,7 +763,6 @@ Variant Object::callv(const StringName &p_method, const Array &p_args) { } Variant Object::call(const StringName &p_name, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS; int argc = 0; @@ -812,7 +779,6 @@ Variant Object::call(const StringName &p_name, VARIANT_ARG_DECLARE) { } void Object::call_multilevel(const StringName &p_name, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS; int argc = 0; @@ -827,7 +793,6 @@ void Object::call_multilevel(const StringName &p_name, VARIANT_ARG_DECLARE) { } Variant Object::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - r_error.error = Callable::CallError::CALL_OK; if (p_method == CoreStringNames::get_singleton()->_free) { @@ -863,7 +828,6 @@ Variant Object::call(const StringName &p_method, const Variant **p_args, int p_a ret = script_instance->call(p_method, p_args, p_argcount, r_error); //force jumptable switch (r_error.error) { - case Callable::CallError::CALL_OK: return ret; case Callable::CallError::CALL_ERROR_INVALID_METHOD: @@ -889,7 +853,6 @@ Variant Object::call(const StringName &p_method, const Variant **p_args, int p_a } void Object::notification(int p_notification, bool p_reversed) { - _notificationv(p_notification, p_reversed); if (script_instance) { @@ -911,27 +874,22 @@ void Object::_changed_callback(Object *p_changed, const char *p_prop) { } void Object::add_change_receptor(Object *p_receptor) { - change_receptors.insert(p_receptor); } void Object::remove_change_receptor(Object *p_receptor) { - change_receptors.erase(p_receptor); } void Object::property_list_changed_notify() { - _change_notify(); } void Object::cancel_delete() { - _predelete_ok = true; } void Object::set_script_and_instance(const Variant &p_script, ScriptInstance *p_instance) { - //this function is not meant to be used in any of these ways ERR_FAIL_COND(p_script.is_null()); ERR_FAIL_COND(!p_instance); @@ -942,7 +900,6 @@ void Object::set_script_and_instance(const Variant &p_script, ScriptInstance *p_ } void Object::set_script(const Variant &p_script) { - if (script == p_script) return; @@ -969,7 +926,6 @@ void Object::set_script(const Variant &p_script) { } void Object::set_script_instance(ScriptInstance *p_instance) { - if (script_instance == p_instance) return; @@ -985,17 +941,14 @@ void Object::set_script_instance(ScriptInstance *p_instance) { } Variant Object::get_script() const { - return script; } bool Object::has_meta(const String &p_name) const { - return metadata.has(p_name); } void Object::set_meta(const String &p_name, const Variant &p_value) { - if (p_value.get_type() == Variant::NIL) { metadata.erase(p_name); return; @@ -1005,7 +958,6 @@ void Object::set_meta(const String &p_name, const Variant &p_value) { } Variant Object::get_meta(const String &p_name) const { - ERR_FAIL_COND_V(!metadata.has(p_name), Variant()); return metadata[p_name]; } @@ -1015,20 +967,17 @@ void Object::remove_meta(const String &p_name) { } Array Object::_get_property_list_bind() const { - List<PropertyInfo> lpi; get_property_list(&lpi); return convert_property_list(&lpi); } Array Object::_get_method_list_bind() const { - List<MethodInfo> ml; get_method_list(&ml); Array ret; for (List<MethodInfo>::Element *E = ml.front(); E; E = E->next()) { - Dictionary d = E->get(); //va.push_back(d); ret.push_back(d); @@ -1038,30 +987,25 @@ Array Object::_get_method_list_bind() const { } Vector<String> Object::_get_meta_list_bind() const { - Vector<String> _metaret; List<Variant> keys; metadata.get_key_list(&keys); for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { - _metaret.push_back(E->get()); } return _metaret; } void Object::get_meta_list(List<String> *p_list) const { - List<Variant> keys; metadata.get_key_list(&keys); for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { - p_list->push_back(E->get()); } } void Object::add_user_signal(const MethodInfo &p_signal) { - ERR_FAIL_COND_MSG(p_signal.name == "", "Signal name cannot be empty."); ERR_FAIL_COND_MSG(ClassDB::has_signal(get_class_name(), p_signal.name), "User signal's name conflicts with a built-in signal of '" + get_class_name() + "'."); ERR_FAIL_COND_MSG(signal_map.has(p_signal.name), "Trying to add already existing signal '" + p_signal.name + "'."); @@ -1071,20 +1015,17 @@ void Object::add_user_signal(const MethodInfo &p_signal) { } bool Object::_has_user_signal(const StringName &p_name) const { - if (!signal_map.has(p_name)) return false; return signal_map[p_name].user.name.length() > 0; } struct _ObjectSignalDisconnectData { - StringName signal; Callable callable; }; Variant Object::_emit_signal(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; ERR_FAIL_COND_V(p_argcount < 1, Variant()); @@ -1112,7 +1053,6 @@ Variant Object::_emit_signal(const Variant **p_args, int p_argcount, Callable::C } Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int p_argcount) { - if (_block_signals) return ERR_CANT_ACQUIRE_RESOURCE; //no emit, signals blocked @@ -1143,7 +1083,6 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int Error err = OK; for (int i = 0; i < ssize; i++) { - const Connection &c = slot_map.getv(i).conn; Object *target = c.callable.get_object(); @@ -1201,7 +1140,6 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int } #endif if (disconnect) { - _ObjectSignalDisconnectData dd; dd.signal = p_name; dd.callable = c.callable; @@ -1210,7 +1148,6 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int } while (!disconnect_data.empty()) { - const _ObjectSignalDisconnectData &dd = disconnect_data.front()->get(); _disconnect(dd.signal, dd.callable); @@ -1221,13 +1158,11 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int } Error Object::emit_signal(const StringName &p_name, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS; int argc = 0; for (int i = 0; i < VARIANT_ARG_MAX; i++) { - if (argptr[i]->get_type() == Variant::NIL) break; argc++; @@ -1237,7 +1172,6 @@ Error Object::emit_signal(const StringName &p_name, VARIANT_ARG_DECLARE) { } void Object::_add_user_signal(const String &p_name, const Array &p_args) { - // this version of add_user_signal is meant to be used from scripts or external apis // without access to ADD_SIGNAL in bind_methods // added events are per instance, as opposed to the other ones, which are global @@ -1246,7 +1180,6 @@ void Object::_add_user_signal(const String &p_name, const Array &p_args) { mi.name = p_name; for (int i = 0; i < p_args.size(); i++) { - Dictionary d = p_args[i]; PropertyInfo param; @@ -1262,13 +1195,11 @@ void Object::_add_user_signal(const String &p_name, const Array &p_args) { } Array Object::_get_signal_list() const { - List<MethodInfo> signal_list; get_signal_list(&signal_list); Array ret; for (List<MethodInfo>::Element *E = signal_list.front(); E; E = E->next()) { - ret.push_back(Dictionary(E->get())); } @@ -1276,14 +1207,12 @@ Array Object::_get_signal_list() const { } Array Object::_get_signal_connection_list(const String &p_signal) const { - List<Connection> conns; get_all_signal_connections(&conns); Array ret; for (List<Connection>::Element *E = conns.front(); E; E = E->next()) { - Connection &c = E->get(); if (c.signal.get_name() == p_signal) { ret.push_back(c); @@ -1294,7 +1223,6 @@ Array Object::_get_signal_connection_list(const String &p_signal) const { } Array Object::_get_incoming_connections() const { - Array ret; int connections_amount = connections.size(); for (int idx_conn = 0; idx_conn < connections_amount; idx_conn++) { @@ -1324,7 +1252,6 @@ bool Object::has_signal(const StringName &p_name) const { } void Object::get_signal_list(List<MethodInfo> *p_signals) const { - if (!script.is_null()) { Ref<Script> scr = script; if (scr.is_valid()) { @@ -1337,7 +1264,6 @@ void Object::get_signal_list(List<MethodInfo> *p_signals) const { const StringName *S = nullptr; while ((S = signal_map.next(S))) { - if (signal_map[*S].user.name != "") { //user signal p_signals->push_back(signal_map[*S].user); @@ -1346,22 +1272,18 @@ void Object::get_signal_list(List<MethodInfo> *p_signals) const { } void Object::get_all_signal_connections(List<Connection> *p_connections) const { - const StringName *S = nullptr; while ((S = signal_map.next(S))) { - const SignalData *s = &signal_map[*S]; for (int i = 0; i < s->slot_map.size(); i++) { - p_connections->push_back(s->slot_map.getv(i).conn); } } } void Object::get_signal_connection_list(const StringName &p_signal, List<Connection> *p_connections) const { - const SignalData *s = signal_map.getptr(p_signal); if (!s) return; //nothing @@ -1371,12 +1293,10 @@ void Object::get_signal_connection_list(const StringName &p_signal, List<Connect } int Object::get_persistent_signal_connection_count() const { - int count = 0; const StringName *S = nullptr; while ((S = signal_map.next(S))) { - const SignalData *s = &signal_map[*S]; for (int i = 0; i < s->slot_map.size(); i++) { @@ -1390,18 +1310,15 @@ int Object::get_persistent_signal_connection_count() const { } void Object::get_signals_connected_to_this(List<Connection> *p_connections) const { - for (const List<Connection>::Element *E = connections.front(); E; E = E->next()) { p_connections->push_back(E->get()); } } Error Object::connect_compat(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method, const Vector<Variant> &p_binds, uint32_t p_flags) { - return connect(p_signal, Callable(p_to_object, p_to_method), p_binds, p_flags); } Error Object::connect(const StringName &p_signal, const Callable &p_callable, const Vector<Variant> &p_binds, uint32_t p_flags) { - ERR_FAIL_COND_V(p_callable.is_null(), ERR_INVALID_PARAMETER); Object *target_object = p_callable.get_object(); @@ -1412,7 +1329,6 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, co bool signal_is_valid = ClassDB::has_signal(get_class_name(), p_signal); //check in script if (!signal_is_valid && !script.is_null()) { - if (Ref<Script>(script)->has_script_signal(p_signal)) { signal_is_valid = true; } @@ -1462,12 +1378,10 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, co } bool Object::is_connected_compat(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method) const { - return is_connected(p_signal, Callable(p_to_object, p_to_method)); } bool Object::is_connected(const StringName &p_signal, const Callable &p_callable) const { - ERR_FAIL_COND_V(p_callable.is_null(), false); const SignalData *s = signal_map.getptr(p_signal); if (!s) { @@ -1489,7 +1403,6 @@ bool Object::is_connected(const StringName &p_signal, const Callable &p_callable } void Object::disconnect_compat(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method) { - _disconnect(p_signal, Callable(p_to_object, p_to_method)); } @@ -1498,7 +1411,6 @@ void Object::disconnect(const StringName &p_signal, const Callable &p_callable) } void Object::_disconnect(const StringName &p_signal, const Callable &p_callable, bool p_force) { - ERR_FAIL_COND(p_callable.is_null()); Object *target_object = p_callable.get_object(); @@ -1528,27 +1440,22 @@ void Object::_disconnect(const StringName &p_signal, const Callable &p_callable, } void Object::_set_bind(const String &p_set, const Variant &p_value) { - set(p_set, p_value); } Variant Object::_get_bind(const String &p_name) const { - return get(p_name); } void Object::_set_indexed_bind(const NodePath &p_name, const Variant &p_value) { - set_indexed(p_name.get_as_property_path().get_subnames(), p_value); } Variant Object::_get_indexed_bind(const NodePath &p_name) const { - return get_indexed(p_name.get_as_property_path().get_subnames()); } void Object::initialize_class() { - static bool initialized = false; if (initialized) return; @@ -1558,7 +1465,6 @@ void Object::initialize_class() { } StringName Object::tr(const StringName &p_message) const { - if (!_can_translate || !TranslationServer::get_singleton()) return p_message; @@ -1566,11 +1472,8 @@ StringName Object::tr(const StringName &p_message) const { } void Object::_clear_internal_resource_paths(const Variant &p_var) { - switch (p_var.get_type()) { - case Variant::OBJECT: { - RES r = p_var; if (!r.is_valid()) return; @@ -1586,7 +1489,6 @@ void Object::_clear_internal_resource_paths(const Variant &p_var) { r->clear_internal_resource_paths(); } break; case Variant::ARRAY: { - Array a = p_var; for (int i = 0; i < a.size(); i++) { _clear_internal_resource_paths(a[i]); @@ -1594,13 +1496,11 @@ void Object::_clear_internal_resource_paths(const Variant &p_var) { } break; case Variant::DICTIONARY: { - Dictionary d = p_var; List<Variant> keys; d.get_key_list(&keys); for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { - _clear_internal_resource_paths(E->get()); _clear_internal_resource_paths(d[E->get()]); } @@ -1612,7 +1512,6 @@ void Object::_clear_internal_resource_paths(const Variant &p_var) { #ifdef TOOLS_ENABLED void Object::editor_set_section_unfold(const String &p_section, bool p_unfolded) { - set_edited(true); if (p_unfolded) editor_section_folding.insert(p_section); @@ -1621,26 +1520,22 @@ void Object::editor_set_section_unfold(const String &p_section, bool p_unfolded) } bool Object::editor_is_section_unfolded(const String &p_section) { - return editor_section_folding.has(p_section); } #endif void Object::clear_internal_resource_paths() { - List<PropertyInfo> pinfo; get_property_list(&pinfo); for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - _clear_internal_resource_paths(get(E->get().name)); } } void Object::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_class"), &Object::get_class); ClassDB::bind_method(D_METHOD("is_class", "class"), &Object::is_class); ClassDB::bind_method(D_METHOD("set", "property", "value"), &Object::_set_bind); @@ -1745,7 +1640,6 @@ void Object::_bind_methods() { } void Object::call_deferred(const StringName &p_method, VARIANT_ARG_DECLARE) { - MessageQueue::get_singleton()->push_call(this, p_method, VARIANT_ARG_PASS); } @@ -1754,22 +1648,18 @@ void Object::set_deferred(const StringName &p_property, const Variant &p_value) } void Object::set_block_signals(bool p_block) { - _block_signals = p_block; } bool Object::is_blocking_signals() const { - return _block_signals; } void Object::get_translatable_strings(List<String> *p_strings) const { - List<PropertyInfo> plist; get_property_list(&plist); for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_INTERNATIONALIZED)) continue; @@ -1783,7 +1673,6 @@ void Object::get_translatable_strings(List<String> *p_strings) const { } Variant::Type Object::get_static_property_type(const StringName &p_property, bool *r_valid) const { - bool valid; Variant::Type t = ClassDB::get_property_type(get_class_name(), p_property, &valid); if (valid) { @@ -1802,7 +1691,6 @@ Variant::Type Object::get_static_property_type(const StringName &p_property, boo } Variant::Type Object::get_static_property_type_indexed(const Vector<StringName> &p_path, bool *r_valid) const { - if (p_path.size() == 0) { if (r_valid) *r_valid = false; @@ -1851,18 +1739,15 @@ bool Object::is_queued_for_deletion() const { #ifdef TOOLS_ENABLED void Object::set_edited(bool p_edited) { - _edited = p_edited; _edited_version++; } bool Object::is_edited() const { - return _edited; } uint32_t Object::get_edited_version() const { - return _edited_version; } #endif @@ -1889,7 +1774,6 @@ void *Object::get_script_instance_binding(int p_script_language_index) { } bool Object::has_script_instance_binding(int p_script_language_index) { - return _script_instance_bindings[p_script_language_index] != nullptr; } @@ -1919,7 +1803,6 @@ Object::Object() { } Object::~Object() { - if (script_instance) memdelete(script_instance); script_instance = nullptr; @@ -1932,7 +1815,6 @@ Object::~Object() { } while ((S = signal_map.next(nullptr))) { - SignalData *s = &signal_map[*S]; //brute force disconnect for performance @@ -1940,7 +1822,6 @@ Object::~Object() { const VMap<Callable, SignalData::Slot>::Pair *slot_list = s->slot_map.get_array(); for (int i = 0; i < slot_count; i++) { - slot_list[i].value.conn.callable.get_object()->connections.erase(slot_list[i].value.cE); } @@ -1949,7 +1830,6 @@ Object::~Object() { //signals from nodes that connect to this node while (connections.size()) { - Connection c = connections.front()->get(); c.signal.get_object()->_disconnect(c.signal.get_name(), c.callable, true); } @@ -1968,17 +1848,14 @@ Object::~Object() { } bool predelete_handler(Object *p_object) { - return p_object->_predelete(); } void postinitialize_handler(Object *p_object) { - p_object->_postinitialize(); } void ObjectDB::debug_objects(DebugFunc p_func) { - spin_lock.lock(); for (uint32_t i = 0; i < slot_count; i++) { uint32_t slot = object_slots[i].next_free; @@ -1997,15 +1874,12 @@ ObjectDB::ObjectSlot *ObjectDB::object_slots = nullptr; uint64_t ObjectDB::validator_counter = 0; int ObjectDB::get_object_count() { - return slot_count; } ObjectID ObjectDB::add_instance(Object *p_object) { - spin_lock.lock(); if (unlikely(slot_count == slot_max)) { - CRASH_COND(slot_count == (1 << OBJECTDB_SLOT_MAX_COUNT_BITS)); uint32_t new_slot_max = slot_max > 0 ? slot_max * 2 : 1; @@ -2081,12 +1955,10 @@ void ObjectDB::remove_instance(Object *p_object) { } void ObjectDB::setup() { - //nothing to do now } void ObjectDB::cleanup() { - if (slot_count > 0) { spin_lock.lock(); diff --git a/core/object.h b/core/object.h index 20defae095..84db756323 100644 --- a/core/object.h +++ b/core/object.h @@ -138,7 +138,6 @@ enum PropertyUsageFlags { #define ADD_SUBGROUP(m_name, m_prefix) ClassDB::add_property_subgroup(get_class_static(), m_name, m_prefix) struct PropertyInfo { - Variant::Type type = Variant::NIL; String name; StringName class_name; //for classes @@ -164,7 +163,6 @@ struct PropertyInfo { hint(p_hint), hint_string(p_hint_string), usage(p_usage) { - if (hint == PROPERTY_HINT_RESOURCE_TYPE) { class_name = hint_string; } else { @@ -193,7 +191,6 @@ struct PropertyInfo { Array convert_property_list(const List<PropertyInfo> *p_list); struct MethodInfo { - String name; PropertyInfo return_val; uint32_t flags; // NOLINT - prevent clang-tidy to assign method_bind.h constant here, it should stay in .cpp. @@ -297,7 +294,6 @@ public: virtual bool is_class_ptr(void *p_ptr) const { return (p_ptr == get_class_ptr_static()) ? true : m_inherits::is_class_ptr(p_ptr); } \ \ static void get_valid_parents_static(List<String> *p_parents) { \ - \ if (m_class::_get_valid_parents_static != m_inherits::_get_valid_parents_static) { \ m_class::_get_valid_parents_static(p_parents); \ } \ @@ -406,7 +402,6 @@ public: }; struct Connection { - ::Signal signal; Callable callable; @@ -432,7 +427,6 @@ private: friend void postinitialize_handler(Object *); struct SignalData { - struct Slot { int reference_count = 0; Connection conn; @@ -744,7 +738,6 @@ bool predelete_handler(Object *p_object); void postinitialize_handler(Object *p_object); class ObjectDB { - //this needs to add up to 63, 1 bit is for reference #define OBJECTDB_VALIDATOR_BITS 39 #define OBJECTDB_VALIDATOR_MASK ((uint64_t(1) << OBJECTDB_VALIDATOR_BITS) - 1) @@ -779,7 +772,6 @@ public: typedef void (*DebugFunc)(Object *p_obj); _ALWAYS_INLINE_ static Object *get_instance(ObjectID p_instance_id) { - uint64_t id = p_instance_id; uint32_t slot = id & OBJECTDB_SLOT_MAX_COUNT_MASK; diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index 53b959a580..520968c9a9 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -36,9 +36,7 @@ #include "core/project_settings.h" String DirAccess::_get_root_path() const { - switch (_access_type) { - case ACCESS_RESOURCES: return ProjectSettings::get_singleton()->get_resource_path(); case ACCESS_USERDATA: @@ -48,9 +46,7 @@ String DirAccess::_get_root_path() const { } } String DirAccess::_get_root_string() const { - switch (_access_type) { - case ACCESS_RESOURCES: return "res://"; case ACCESS_USERDATA: @@ -61,7 +57,6 @@ String DirAccess::_get_root_string() const { } int DirAccess::get_current_drive() { - String path = get_current_dir().to_lower(); for (int i = 0; i < get_drive_count(); i++) { String d = get_drive(i).to_lower(); @@ -73,21 +68,17 @@ int DirAccess::get_current_drive() { } bool DirAccess::drives_are_shortcuts() { - return false; } static Error _erase_recursive(DirAccess *da) { - List<String> dirs; List<String> files; da->list_dir_begin(); String n = da->get_next(); while (n != String()) { - if (n != "." && n != "..") { - if (da->current_is_dir()) dirs.push_back(n); else @@ -100,10 +91,8 @@ static Error _erase_recursive(DirAccess *da) { da->list_dir_end(); for (List<String>::Element *E = dirs.front(); E; E = E->next()) { - Error err = da->change_dir(E->get()); if (err == OK) { - err = _erase_recursive(da); if (err) { da->change_dir(".."); @@ -123,7 +112,6 @@ static Error _erase_recursive(DirAccess *da) { } for (List<String>::Element *E = files.front(); E; E = E->next()) { - Error err = da->remove(da->get_current_dir().plus_file(E->get())); if (err) { return err; @@ -134,12 +122,10 @@ static Error _erase_recursive(DirAccess *da) { } Error DirAccess::erase_contents_recursive() { - return _erase_recursive(this); } Error DirAccess::make_dir_recursive(String p_dir) { - if (p_dir.length() < 1) { return OK; }; @@ -178,11 +164,9 @@ Error DirAccess::make_dir_recursive(String p_dir) { String curpath = base; for (int i = 0; i < subdirs.size(); i++) { - curpath = curpath.plus_file(subdirs[i]); Error err = make_dir(curpath); if (err != OK && err != ERR_ALREADY_EXISTS) { - ERR_FAIL_V(err); } } @@ -191,17 +175,12 @@ Error DirAccess::make_dir_recursive(String p_dir) { } String DirAccess::fix_path(String p_path) const { - switch (_access_type) { - case ACCESS_RESOURCES: { - if (ProjectSettings::get_singleton()) { if (p_path.begins_with("res://")) { - String resource_path = ProjectSettings::get_singleton()->get_resource_path(); if (resource_path != "") { - return p_path.replace_first("res:/", resource_path); }; return p_path.replace_first("res://", ""); @@ -210,12 +189,9 @@ String DirAccess::fix_path(String p_path) const { } break; case ACCESS_USERDATA: { - if (p_path.begins_with("user://")) { - String data_dir = OS::get_singleton()->get_user_data_dir(); if (data_dir != "") { - return p_path.replace_first("user:/", data_dir); }; return p_path.replace_first("user://", ""); @@ -223,7 +199,6 @@ String DirAccess::fix_path(String p_path) const { } break; case ACCESS_FILESYSTEM: { - return p_path; } break; case ACCESS_MAX: @@ -236,16 +211,12 @@ String DirAccess::fix_path(String p_path) const { DirAccess::CreateFunc DirAccess::create_func[ACCESS_MAX] = { nullptr, nullptr, nullptr }; DirAccess *DirAccess::create_for_path(const String &p_path) { - DirAccess *da = nullptr; if (p_path.begins_with("res://")) { - da = create(ACCESS_RESOURCES); } else if (p_path.begins_with("user://")) { - da = create(ACCESS_USERDATA); } else { - da = create(ACCESS_FILESYSTEM); } @@ -253,7 +224,6 @@ DirAccess *DirAccess::create_for_path(const String &p_path) { } DirAccess *DirAccess::open(const String &p_path, Error *r_error) { - DirAccess *da = create_for_path(p_path); ERR_FAIL_COND_V_MSG(!da, nullptr, "Cannot create DirAccess for path '" + p_path + "'."); @@ -269,7 +239,6 @@ DirAccess *DirAccess::open(const String &p_path, Error *r_error) { } DirAccess *DirAccess::create(AccessType p_access) { - DirAccess *da = create_func[p_access] ? create_func[p_access]() : nullptr; if (da) { da->_access_type = p_access; @@ -279,7 +248,6 @@ DirAccess *DirAccess::create(AccessType p_access) { }; String DirAccess::get_full_path(const String &p_path, AccessType p_access) { - DirAccess *d = DirAccess::create(p_access); if (!d) return p_path; @@ -291,7 +259,6 @@ String DirAccess::get_full_path(const String &p_path, AccessType p_access) { } Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) { - //printf("copy %s -> %s\n",p_from.ascii().get_data(),p_to.ascii().get_data()); Error err; FileAccess *fsrc = FileAccess::open(p_from, FileAccess::READ, &err); @@ -303,7 +270,6 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) { FileAccess *fdst = FileAccess::open(p_to, FileAccess::WRITE, &err); if (err) { - fsrc->close(); memdelete(fsrc); ERR_PRINT("Failed to open " + p_to); @@ -315,7 +281,6 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) { fsrc->seek(0); err = OK; while (size--) { - if (fsrc->get_error() != OK) { err = fsrc->get_error(); break; @@ -367,9 +332,7 @@ Error DirAccess::_copy_dir(DirAccess *p_target_da, String p_to, int p_chmod_flag list_dir_begin(); String n = get_next(); while (n != String()) { - if (n != "." && n != "..") { - if (current_is_dir()) dirs.push_back(n); else { @@ -440,7 +403,6 @@ Error DirAccess::copy_dir(String p_from, String p_to, int p_chmod_flags) { } bool DirAccess::exists(String p_dir) { - DirAccess *da = DirAccess::create_for_path(p_dir); bool valid = da->change_dir(p_dir) == OK; memdelete(da); diff --git a/core/os/dir_access.h b/core/os/dir_access.h index cac0d0ec7c..06b3abca8c 100644 --- a/core/os/dir_access.h +++ b/core/os/dir_access.h @@ -61,7 +61,6 @@ protected: template <class T> static DirAccess *_create_builtin() { - return memnew(T); } @@ -114,7 +113,6 @@ public: template <class T> static void make_default(AccessType p_access) { - create_func[p_access] = _create_builtin<T>; } @@ -125,9 +123,7 @@ public: }; struct DirAccessRef { - _FORCE_INLINE_ DirAccess *operator->() { - return f; } diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index cb8705f706..f31842bcae 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -43,7 +43,6 @@ FileAccess::FileCloseFailNotify FileAccess::close_fail_notify = nullptr; bool FileAccess::backup_save = false; FileAccess *FileAccess::create(AccessType p_access) { - ERR_FAIL_INDEX_V(p_access, ACCESS_MAX, nullptr); FileAccess *ret = create_func[p_access](); @@ -52,7 +51,6 @@ FileAccess *FileAccess::create(AccessType p_access) { } bool FileAccess::exists(const String &p_name) { - if (PackedData::get_singleton() && PackedData::get_singleton()->has_path(p_name)) return true; @@ -64,22 +62,17 @@ bool FileAccess::exists(const String &p_name) { } void FileAccess::_set_access_type(AccessType p_access) { - _access_type = p_access; }; FileAccess *FileAccess::create_for_path(const String &p_path) { - FileAccess *ret = nullptr; if (p_path.begins_with("res://")) { - ret = create(ACCESS_RESOURCES); } else if (p_path.begins_with("user://")) { - ret = create(ACCESS_USERDATA); } else { - ret = create(ACCESS_FILESYSTEM); } @@ -87,12 +80,10 @@ FileAccess *FileAccess::create_for_path(const String &p_path) { } Error FileAccess::reopen(const String &p_path, int p_mode_flags) { - return _open(p_path, p_mode_flags); }; FileAccess *FileAccess::open(const String &p_path, int p_mode_flags, Error *r_error) { - //try packed data first FileAccess *ret = nullptr; @@ -111,7 +102,6 @@ FileAccess *FileAccess::open(const String &p_path, int p_mode_flags, Error *r_er if (r_error) *r_error = err; if (err != OK) { - memdelete(ret); ret = nullptr; } @@ -120,7 +110,6 @@ FileAccess *FileAccess::open(const String &p_path, int p_mode_flags, Error *r_er } FileAccess::CreateFunc FileAccess::get_create_func(AccessType p_access) { - return create_func[p_access]; }; @@ -130,15 +119,11 @@ String FileAccess::fix_path(const String &p_path) const { String r_path = p_path.replace("\\", "/"); switch (_access_type) { - case ACCESS_RESOURCES: { - if (ProjectSettings::get_singleton()) { if (r_path.begins_with("res://")) { - String resource_path = ProjectSettings::get_singleton()->get_resource_path(); if (resource_path != "") { - return r_path.replace("res:/", resource_path); }; return r_path.replace("res://", ""); @@ -147,12 +132,9 @@ String FileAccess::fix_path(const String &p_path) const { } break; case ACCESS_USERDATA: { - if (r_path.begins_with("user://")) { - String data_dir = OS::get_singleton()->get_user_data_dir(); if (data_dir != "") { - return r_path.replace("user:/", data_dir); }; return r_path.replace("user://", ""); @@ -160,7 +142,6 @@ String FileAccess::fix_path(const String &p_path) const { } break; case ACCESS_FILESYSTEM: { - return r_path; } break; case ACCESS_MAX: @@ -173,7 +154,6 @@ String FileAccess::fix_path(const String &p_path) const { /* these are all implemented for ease of porting, then can later be optimized */ uint16_t FileAccess::get_16() const { - uint16_t res; uint8_t a, b; @@ -181,7 +161,6 @@ uint16_t FileAccess::get_16() const { b = get_8(); if (endian_swap) { - SWAP(a, b); } @@ -192,7 +171,6 @@ uint16_t FileAccess::get_16() const { return res; } uint32_t FileAccess::get_32() const { - uint32_t res; uint16_t a, b; @@ -200,7 +178,6 @@ uint32_t FileAccess::get_32() const { b = get_16(); if (endian_swap) { - SWAP(a, b); } @@ -211,7 +188,6 @@ uint32_t FileAccess::get_32() const { return res; } uint64_t FileAccess::get_64() const { - uint64_t res; uint32_t a, b; @@ -219,7 +195,6 @@ uint64_t FileAccess::get_64() const { b = get_32(); if (endian_swap) { - SWAP(a, b); } @@ -231,14 +206,12 @@ uint64_t FileAccess::get_64() const { } float FileAccess::get_float() const { - MarshallFloat m; m.i = get_32(); return m.f; }; real_t FileAccess::get_real() const { - if (real_is_double) return get_double(); else @@ -246,20 +219,17 @@ real_t FileAccess::get_real() const { } double FileAccess::get_double() const { - MarshallDouble m; m.l = get_64(); return m.d; }; String FileAccess::get_token() const { - CharString token; CharType c = get_8(); while (!eof_reached()) { - if (c <= ' ') { if (token.length()) break; @@ -281,16 +251,13 @@ class CharBuffer { int written = 0; 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.write[i] = stack_buffer[i]; } } @@ -309,9 +276,7 @@ public: } _FORCE_INLINE_ void push_back(char c) { - if (written >= capacity) { - ERR_FAIL_COND(!grow()); } @@ -319,19 +284,16 @@ public: } _FORCE_INLINE_ const char *get_data() const { - return buffer; } }; String FileAccess::get_line() const { - CharBuffer line; CharType c = get_8(); while (!eof_reached()) { - if (c == '\n' || c == '\0') { line.push_back(0); return String::utf8(line.get_data()); @@ -345,7 +307,6 @@ String FileAccess::get_line() const { } Vector<String> FileAccess::get_csv_line(const String &p_delim) const { - ERR_FAIL_COND_V(p_delim.length() != 1, Vector<String>()); String l; @@ -357,7 +318,6 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const { l += get_line() + "\n"; qc = 0; for (int i = 0; i < l.length(); i++) { - if (l[i] == '"') qc++; } @@ -371,7 +331,6 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const { bool in_quote = false; String current; for (int i = 0; i < l.length(); i++) { - CharType c = l[i]; CharType s[2] = { 0, 0 }; @@ -384,7 +343,6 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const { current += s; i++; } else { - in_quote = !in_quote; } } else { @@ -399,7 +357,6 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const { } int FileAccess::get_buffer(uint8_t *p_dst, int p_length) const { - int i = 0; for (i = 0; i < p_length && !eof_reached(); i++) p_dst[i] = get_8(); @@ -425,14 +382,12 @@ String FileAccess::get_as_utf8_string() const { } void FileAccess::store_16(uint16_t p_dest) { - uint8_t a, b; a = p_dest & 0xFF; b = p_dest >> 8; if (endian_swap) { - SWAP(a, b); } @@ -440,14 +395,12 @@ void FileAccess::store_16(uint16_t p_dest) { store_8(b); } void FileAccess::store_32(uint32_t p_dest) { - uint16_t a, b; a = p_dest & 0xFFFF; b = p_dest >> 16; if (endian_swap) { - SWAP(a, b); } @@ -455,14 +408,12 @@ void FileAccess::store_32(uint32_t p_dest) { store_16(b); } void FileAccess::store_64(uint64_t p_dest) { - uint32_t a, b; a = p_dest & 0xFFFFFFFF; b = p_dest >> 32; if (endian_swap) { - SWAP(a, b); } @@ -471,7 +422,6 @@ void FileAccess::store_64(uint64_t p_dest) { } void FileAccess::store_real(real_t p_real) { - if (sizeof(real_t) == 4) store_float(p_real); else @@ -479,21 +429,18 @@ void FileAccess::store_real(real_t p_real) { } void FileAccess::store_float(float p_dest) { - MarshallFloat m; m.f = p_dest; store_32(m.i); }; void FileAccess::store_double(double p_dest) { - MarshallDouble m; m.d = p_dest; store_64(m.l); }; uint64_t FileAccess::get_modified_time(const String &p_file) { - if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file)) return 0; @@ -506,7 +453,6 @@ uint64_t FileAccess::get_modified_time(const String &p_file) { } uint32_t FileAccess::get_unix_permissions(const String &p_file) { - if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file)) return 0; @@ -519,7 +465,6 @@ uint32_t FileAccess::get_unix_permissions(const String &p_file) { } Error FileAccess::set_unix_permissions(const String &p_file, uint32_t p_permissions) { - FileAccess *fa = create_for_path(p_file); ERR_FAIL_COND_V_MSG(!fa, ERR_CANT_CREATE, "Cannot create FileAccess for path '" + p_file + "'."); @@ -529,7 +474,6 @@ Error FileAccess::set_unix_permissions(const String &p_file, uint32_t p_permissi } void FileAccess::store_string(const String &p_string) { - if (p_string.length() == 0) return; @@ -538,14 +482,12 @@ void FileAccess::store_string(const String &p_string) { } void FileAccess::store_pascal_string(const String &p_string) { - CharString cs = p_string.utf8(); store_32(cs.length()); store_buffer((uint8_t *)&cs[0], cs.length()); }; String FileAccess::get_pascal_string() { - uint32_t sl = get_32(); CharString cs; cs.resize(sl + 1); @@ -559,13 +501,11 @@ String FileAccess::get_pascal_string() { }; void FileAccess::store_line(const String &p_line) { - store_string(p_line); store_8('\n'); } void FileAccess::store_csv_line(const Vector<String> &p_values, const String &p_delim) { - ERR_FAIL_COND(p_delim.length() != 1); String line = ""; @@ -587,13 +527,11 @@ void FileAccess::store_csv_line(const Vector<String> &p_values, const String &p_ } void FileAccess::store_buffer(const uint8_t *p_src, int p_length) { - for (int i = 0; i < p_length; i++) store_8(p_src[i]); } Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path, Error *r_error) { - FileAccess *f = FileAccess::open(p_path, READ, r_error); if (!f) { if (r_error) { // if error requested, do not throw error @@ -609,7 +547,6 @@ Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path, Error *r_err } String FileAccess::get_file_as_string(const String &p_path, Error *r_error) { - Error err; Vector<uint8_t> array = get_file_as_array(p_path, &err); if (r_error) { @@ -628,7 +565,6 @@ String FileAccess::get_file_as_string(const String &p_path, Error *r_error) { } String FileAccess::get_md5(const String &p_file) { - FileAccess *f = FileAccess::open(p_file, READ); if (!f) return String(); @@ -639,10 +575,8 @@ String FileAccess::get_md5(const String &p_file) { unsigned char step[32768]; while (true) { - int br = f->get_buffer(step, 32768); if (br > 0) { - ctx.update(step, br); } if (br < 4096) @@ -658,7 +592,6 @@ String FileAccess::get_md5(const String &p_file) { } String FileAccess::get_multiple_md5(const Vector<String> &p_file) { - CryptoCore::MD5Context ctx; ctx.start(); @@ -669,10 +602,8 @@ String FileAccess::get_multiple_md5(const Vector<String> &p_file) { unsigned char step[32768]; while (true) { - int br = f->get_buffer(step, 32768); if (br > 0) { - ctx.update(step, br); } if (br < 4096) @@ -688,7 +619,6 @@ String FileAccess::get_multiple_md5(const Vector<String> &p_file) { } String FileAccess::get_sha256(const String &p_file) { - FileAccess *f = FileAccess::open(p_file, READ); if (!f) return String(); @@ -699,10 +629,8 @@ String FileAccess::get_sha256(const String &p_file) { unsigned char step[32768]; while (true) { - int br = f->get_buffer(step, 32768); if (br > 0) { - ctx.update(step, br); } if (br < 4096) diff --git a/core/os/file_access.h b/core/os/file_access.h index 0ee29abbc9..a956ae12f4 100644 --- a/core/os/file_access.h +++ b/core/os/file_access.h @@ -41,7 +41,6 @@ */ class FileAccess { - public: enum AccessType { ACCESS_RESOURCES, @@ -73,7 +72,6 @@ private: static CreateFunc create_func[ACCESS_MAX]; /** default file access creation function for a platform */ template <class T> static FileAccess *_create_builtin() { - return memnew(T); } @@ -172,7 +170,6 @@ public: template <class T> static void make_default(AccessType p_access) { - create_func[p_access] = _create_builtin<T>; } @@ -181,9 +178,7 @@ public: }; struct FileAccessRef { - _FORCE_INLINE_ FileAccess *operator->() { - return f; } diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp index c65d3fefc2..d088151a6d 100644 --- a/core/os/keyboard.cpp +++ b/core/os/keyboard.cpp @@ -293,9 +293,7 @@ static const _KeyCodeText _keycodes[] = { }; bool keycode_has_unicode(uint32_t p_keycode) { - switch (p_keycode) { - case KEY_ESCAPE: case KEY_TAB: case KEY_BACKTAB: @@ -394,7 +392,6 @@ bool keycode_has_unicode(uint32_t p_keycode) { } String keycode_get_string(uint32_t p_code) { - String codestr; if (p_code & KEY_MASK_SHIFT) { codestr += find_keycode_name(KEY_SHIFT); @@ -418,9 +415,7 @@ String keycode_get_string(uint32_t p_code) { const _KeyCodeText *kct = &_keycodes[0]; while (kct->text) { - if (kct->code == (int)p_code) { - codestr += kct->text; return codestr; } @@ -433,11 +428,9 @@ String keycode_get_string(uint32_t p_code) { } int find_keycode(const String &p_code) { - const _KeyCodeText *kct = &_keycodes[0]; while (kct->text) { - if (p_code.nocasecmp_to(kct->text) == 0) { return kct->code; } @@ -448,11 +441,9 @@ int find_keycode(const String &p_code) { } const char *find_keycode_name(int p_keycode) { - const _KeyCodeText *kct = &_keycodes[0]; while (kct->text) { - if (kct->code == p_keycode) { return kct->text; } @@ -463,12 +454,10 @@ const char *find_keycode_name(int p_keycode) { } int keycode_get_count() { - const _KeyCodeText *kct = &_keycodes[0]; int count = 0; while (kct->text) { - count++; kct++; } diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index b29e3f6142..7c00af8d1f 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -33,7 +33,6 @@ #include "core/script_language.h" void MainLoop::_bind_methods() { - ClassDB::bind_method(D_METHOD("init"), &MainLoop::init); ClassDB::bind_method(D_METHOD("iteration", "delta"), &MainLoop::iteration); ClassDB::bind_method(D_METHOD("idle", "delta"), &MainLoop::idle); @@ -56,12 +55,10 @@ void MainLoop::_bind_methods() { }; void MainLoop::set_init_script(const Ref<Script> &p_init_script) { - init_script = p_init_script; } void MainLoop::init() { - if (init_script.is_valid()) set_script(init_script); @@ -69,14 +66,12 @@ void MainLoop::init() { get_script_instance()->call("_initialize"); } bool MainLoop::iteration(float p_time) { - if (get_script_instance()) return get_script_instance()->call("_iteration", p_time); return false; } bool MainLoop::idle(float p_time) { - if (get_script_instance()) return get_script_instance()->call("_idle", p_time); @@ -84,7 +79,6 @@ bool MainLoop::idle(float p_time) { } void MainLoop::finish() { - if (get_script_instance()) { get_script_instance()->call("_finalize"); set_script(Variant()); //clear script diff --git a/core/os/main_loop.h b/core/os/main_loop.h index c7cc8f01e0..90790a45a1 100644 --- a/core/os/main_loop.h +++ b/core/os/main_loop.h @@ -36,7 +36,6 @@ #include "core/script_language.h" class MainLoop : public Object { - GDCLASS(MainLoop, Object); OBJ_CATEGORY("Main Loop"); diff --git a/core/os/memory.cpp b/core/os/memory.cpp index 0e48592cc1..8457c52092 100644 --- a/core/os/memory.cpp +++ b/core/os/memory.cpp @@ -38,28 +38,23 @@ #include <stdlib.h> void *operator new(size_t p_size, const char *p_description) { - return Memory::alloc_static(p_size, false); } void *operator new(size_t p_size, void *(*p_allocfunc)(size_t p_size)) { - return p_allocfunc(p_size); } #ifdef _MSC_VER void operator delete(void *p_mem, const char *p_description) { - CRASH_NOW_MSG("Call to placement delete should not happen."); } void operator delete(void *p_mem, void *(*p_allocfunc)(size_t p_size)) { - CRASH_NOW_MSG("Call to placement delete should not happen."); } void operator delete(void *p_mem, void *p_pointer, size_t check, const char *p_description) { - CRASH_NOW_MSG("Call to placement delete should not happen."); } #endif @@ -72,7 +67,6 @@ uint64_t Memory::max_usage = 0; uint64_t Memory::alloc_count = 0; void *Memory::alloc_static(size_t p_bytes, bool p_pad_align) { - #ifdef DEBUG_ENABLED bool prepad = true; #else @@ -102,7 +96,6 @@ void *Memory::alloc_static(size_t p_bytes, bool p_pad_align) { } void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) { - if (p_memory == nullptr) { return alloc_static(p_bytes, p_pad_align); } @@ -144,7 +137,6 @@ void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) { return mem + PAD_ALIGN; } } else { - mem = (uint8_t *)realloc(mem, p_bytes); ERR_FAIL_COND_V(mem == nullptr && p_bytes > 0, nullptr); @@ -154,7 +146,6 @@ void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) { } void Memory::free_static(void *p_ptr, bool p_pad_align) { - ERR_FAIL_COND(p_ptr == nullptr); uint8_t *mem = (uint8_t *)p_ptr; @@ -177,13 +168,11 @@ void Memory::free_static(void *p_ptr, bool p_pad_align) { free(mem); } else { - free(mem); } } uint64_t Memory::get_mem_available() { - return -1; // 0xFFFF... } diff --git a/core/os/memory.h b/core/os/memory.h index 03c6a80e89..42723152e4 100644 --- a/core/os/memory.h +++ b/core/os/memory.h @@ -41,7 +41,6 @@ #endif class Memory { - Memory(); #ifdef DEBUG_ENABLED static uint64_t mem_usage; @@ -87,7 +86,6 @@ _ALWAYS_INLINE_ void postinitialize_handler(void *) {} template <class T> _ALWAYS_INLINE_ T *_post_initialize(T *p_obj) { - postinitialize_handler(p_obj); return p_obj; } @@ -110,7 +108,6 @@ _ALWAYS_INLINE_ bool predelete_handler(void *) { template <class T> void memdelete(T *p_class) { - if (!predelete_handler(p_class)) return; // doesn't want to be deleted if (!__has_trivial_destructor(T)) @@ -121,7 +118,6 @@ void memdelete(T *p_class) { template <class T, class A> void memdelete_allocator(T *p_class) { - if (!predelete_handler(p_class)) return; // doesn't want to be deleted if (!__has_trivial_destructor(T)) @@ -140,7 +136,6 @@ void memdelete_allocator(T *p_class) { template <typename T> T *memnew_arr_template(size_t p_elements, const char *p_descr = "") { - if (p_elements == 0) return nullptr; /** overloading operator new[] cannot be done , because it may not return the real allocated address (it may pad the 'element count' before the actual array). Because of that, it must be done by hand. This is the @@ -171,14 +166,12 @@ T *memnew_arr_template(size_t p_elements, const char *p_descr = "") { template <typename T> size_t memarr_len(const T *p_class) { - uint64_t *ptr = (uint64_t *)p_class; return *(ptr - 1); } template <typename T> void memdelete_arr(T *p_class) { - uint64_t *ptr = (uint64_t *)p_class; if (!__has_trivial_destructor(T)) { @@ -193,7 +186,6 @@ void memdelete_arr(T *p_class) { } struct _GlobalNil { - int color = 1; _GlobalNil *right; _GlobalNil *left; @@ -203,7 +195,6 @@ struct _GlobalNil { }; struct _GlobalNilClass { - static _GlobalNil _nil; }; diff --git a/core/os/midi_driver.cpp b/core/os/midi_driver.cpp index efd87d3ab6..e9919aeb86 100644 --- a/core/os/midi_driver.cpp +++ b/core/os/midi_driver.cpp @@ -36,17 +36,14 @@ uint8_t MIDIDriver::last_received_message = 0x00; MIDIDriver *MIDIDriver::singleton = nullptr; MIDIDriver *MIDIDriver::get_singleton() { - return singleton; } void MIDIDriver::set_singleton() { - singleton = this; } void MIDIDriver::receive_input_packet(uint64_t timestamp, uint8_t *data, uint32_t length) { - Ref<InputEventMIDI> event; event.instance(); uint32_t param_position = 1; @@ -122,12 +119,10 @@ void MIDIDriver::receive_input_packet(uint64_t timestamp, uint8_t *data, uint32_ } PackedStringArray MIDIDriver::get_connected_inputs() { - PackedStringArray list; return list; } MIDIDriver::MIDIDriver() { - set_singleton(); } diff --git a/core/os/midi_driver.h b/core/os/midi_driver.h index b7377a8a40..bc922e1fcf 100644 --- a/core/os/midi_driver.h +++ b/core/os/midi_driver.h @@ -39,7 +39,6 @@ */ class MIDIDriver { - static MIDIDriver *singleton; static uint8_t last_received_message; diff --git a/core/os/mutex.h b/core/os/mutex.h index 69a15f96de..d42cbed821 100644 --- a/core/os/mutex.h +++ b/core/os/mutex.h @@ -82,7 +82,6 @@ extern template class MutexLock<MutexImpl<std::mutex>>; #else class FakeMutex { - FakeMutex() {} }; diff --git a/core/os/os.cpp b/core/os/os.cpp index cdc9f1e0ff..02d1dfe895 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -43,7 +43,6 @@ OS *OS::singleton = nullptr; OS *OS::get_singleton() { - return singleton; } @@ -84,7 +83,6 @@ uint64_t OS::get_splash_tick_msec() const { return _msec_splash; } uint64_t OS::get_unix_time() const { - return 0; }; uint64_t OS::get_system_time_secs() const { @@ -116,12 +114,10 @@ void OS::add_logger(Logger *p_logger) { } void OS::print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, Logger::ErrorType p_type) { - _logger->log_error(p_function, p_file, p_line, p_code, p_rationale, p_type); } void OS::print(const char *p_format, ...) { - va_list argp; va_start(argp, p_format); @@ -140,54 +136,44 @@ void OS::printerr(const char *p_format, ...) { }; void OS::set_low_processor_usage_mode(bool p_enabled) { - low_processor_usage_mode = p_enabled; } bool OS::is_in_low_processor_usage_mode() const { - return low_processor_usage_mode; } void OS::set_low_processor_usage_mode_sleep_usec(int p_usec) { - low_processor_usage_mode_sleep_usec = p_usec; } int OS::get_low_processor_usage_mode_sleep_usec() const { - return low_processor_usage_mode_sleep_usec; } String OS::get_executable_path() const { - return _execpath; } int OS::get_process_id() const { - return -1; }; void OS::vibrate_handheld(int p_duration_ms) { - WARN_PRINT("vibrate_handheld() only works with Android and iOS"); } bool OS::is_stdout_verbose() const { - return _verbose_stdout; } void OS::dump_memory_to_file(const char *p_file) { - //Memory::dump_static_mem_to_file(p_file); } static FileAccess *_OSPRF = nullptr; static void _OS_printres(Object *p_obj) { - Resource *res = Object::cast_to<Resource>(p_obj); if (!res) return; @@ -200,10 +186,8 @@ static void _OS_printres(Object *p_obj) { } void OS::print_all_resources(String p_to_file) { - ERR_FAIL_COND(p_to_file != "" && _OSPRF); if (p_to_file != "") { - Error err; _OSPRF = FileAccess::open(p_to_file, FileAccess::WRITE, &err); if (err != OK) { @@ -215,7 +199,6 @@ void OS::print_all_resources(String p_to_file) { ObjectDB::debug_objects(_OS_printres); if (p_to_file != "") { - if (_OSPRF) memdelete(_OSPRF); _OSPRF = nullptr; @@ -223,42 +206,34 @@ void OS::print_all_resources(String p_to_file) { } void OS::print_resources_in_use(bool p_short) { - ResourceCache::dump(nullptr, p_short); } void OS::dump_resources_to_file(const char *p_file) { - ResourceCache::dump(p_file); } void OS::set_no_window_mode(bool p_enable) { - _no_window = p_enable; } bool OS::is_no_window_mode_enabled() const { - return _no_window; } int OS::get_exit_code() const { - return _exit_code; } void OS::set_exit_code(int p_code) { - _exit_code = p_code; } String OS::get_locale() const { - return "en"; } // Helper function to ensure that a dir name/path will be valid on the OS String OS::get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator) const { - Vector<String> invalid_chars = String(": * ? \" < > |").split(" "); if (p_allow_dir_separator) { // Dir separators are allowed, but disallow ".." to avoid going up the filesystem @@ -278,50 +253,42 @@ String OS::get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separato // Get properly capitalized engine name for system paths String OS::get_godot_dir_name() const { - // Default to lowercase, so only override when different case is needed return String(VERSION_SHORT_NAME).to_lower(); } // OS equivalent of XDG_DATA_HOME String OS::get_data_path() const { - return "."; } // OS equivalent of XDG_CONFIG_HOME String OS::get_config_path() const { - return "."; } // OS equivalent of XDG_CACHE_HOME String OS::get_cache_path() const { - return "."; } // Path to macOS .app bundle resources String OS::get_bundle_resource_dir() const { - return "."; }; // OS specific path for user:// String OS::get_user_data_dir() const { - return "."; }; // Absolute path to res:// String OS::get_resource_dir() const { - return ProjectSettings::get_singleton()->get_resource_path(); } // Access system-specific dirs like Documents, Downloads, etc. String OS::get_system_dir(SystemDir p_dir) const { - return "."; } @@ -332,22 +299,18 @@ Error OS::shell_open(String p_uri) { // implement these with the canvas? uint64_t OS::get_static_memory_usage() const { - return Memory::get_mem_usage(); } uint64_t OS::get_static_memory_peak_usage() const { - return Memory::get_mem_max_usage(); } Error OS::set_cwd(const String &p_cwd) { - return ERR_CANT_OPEN; } uint64_t OS::get_free_static_memory() const { - return Memory::get_mem_available(); } @@ -355,7 +318,6 @@ void OS::yield() { } void OS::ensure_user_data_dir() { - String dd = get_user_data_dir(); DirAccess *da = DirAccess::open(dd); if (da) { @@ -371,28 +333,23 @@ void OS::ensure_user_data_dir() { } String OS::get_model_name() const { - return "GenericDevice"; } void OS::set_cmdline(const char *p_execpath, const List<String> &p_args) { - _execpath = p_execpath; _cmdline = p_args; }; String OS::get_unique_id() const { - ERR_FAIL_V(""); } int OS::get_processor_count() const { - return 1; } bool OS::can_use_threads() const { - #ifdef NO_THREADS return false; #else @@ -401,12 +358,10 @@ bool OS::can_use_threads() const { } void OS::set_has_server_feature_callback(HasServerFeatureCallback p_callback) { - has_server_feature_callback = p_callback; } bool OS::has_feature(const String &p_feature) { - if (p_feature == get_name()) return true; #ifdef DEBUG_ENABLED @@ -485,7 +440,6 @@ List<String> OS::get_restart_on_exit_arguments() const { } PackedStringArray OS::get_connected_midi_inputs() { - if (MIDIDriver::get_singleton()) return MIDIDriver::get_singleton()->get_connected_inputs(); @@ -494,13 +448,11 @@ PackedStringArray OS::get_connected_midi_inputs() { } void OS::open_midi_inputs() { - if (MIDIDriver::get_singleton()) MIDIDriver::get_singleton()->open(); } void OS::close_midi_inputs() { - if (MIDIDriver::get_singleton()) MIDIDriver::get_singleton()->close(); } diff --git a/core/os/os.h b/core/os/os.h index 4340823cf4..9296e17bb2 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -42,7 +42,6 @@ #include <stdarg.h> class OS { - static OS *singleton; String _execpath; List<String> _cmdline; @@ -185,7 +184,6 @@ public: }; struct Date { - int year; Month month; int day; @@ -194,7 +192,6 @@ public: }; struct Time { - int hour; int min; int sec; diff --git a/core/os/rw_lock.cpp b/core/os/rw_lock.cpp index 81df7f7ea6..a668fe2b4c 100644 --- a/core/os/rw_lock.cpp +++ b/core/os/rw_lock.cpp @@ -37,7 +37,6 @@ RWLock *(*RWLock::create_func)() = nullptr; RWLock *RWLock::create() { - ERR_FAIL_COND_V(!create_func, nullptr); return create_func(); diff --git a/core/os/rw_lock.h b/core/os/rw_lock.h index 8dca8a230a..e519cea439 100644 --- a/core/os/rw_lock.h +++ b/core/os/rw_lock.h @@ -52,7 +52,6 @@ public: }; class RWLockRead { - RWLock *lock; public: @@ -68,7 +67,6 @@ public: }; class RWLockWrite { - RWLock *lock; public: diff --git a/core/os/thread.cpp b/core/os/thread.cpp index a8eb0b2a9f..399efb19a4 100644 --- a/core/os/thread.cpp +++ b/core/os/thread.cpp @@ -38,29 +38,24 @@ Error (*Thread::set_name_func)(const String &) = nullptr; Thread::ID Thread::_main_thread_id = 0; Thread::ID Thread::get_caller_id() { - if (get_thread_id_func) return get_thread_id_func(); return 0; } Thread *Thread::create(ThreadCreateCallback p_callback, void *p_user, const Settings &p_settings) { - if (create_func) { - return create_func(p_callback, p_user, p_settings); } return nullptr; } void Thread::wait_to_finish(Thread *p_thread) { - if (wait_to_finish_func) wait_to_finish_func(p_thread); } Error Thread::set_name(const String &p_name) { - if (set_name_func) return set_name_func(p_name); diff --git a/core/os/thread.h b/core/os/thread.h index 005217dca7..f761d4ca43 100644 --- a/core/os/thread.h +++ b/core/os/thread.h @@ -46,7 +46,6 @@ public: }; struct Settings { - Priority priority; Settings() { priority = PRIORITY_NORMAL; } }; diff --git a/core/os/thread_dummy.h b/core/os/thread_dummy.h index 066ee498ac..37d9ee0846 100644 --- a/core/os/thread_dummy.h +++ b/core/os/thread_dummy.h @@ -36,7 +36,6 @@ #include "core/os/thread.h" class ThreadDummy : public Thread { - static Thread *create(ThreadCreateCallback p_callback, void *p_user, const Settings &p_settings = Settings()); public: @@ -46,7 +45,6 @@ public: }; class RWLockDummy : public RWLock { - static RWLock *create(); public: diff --git a/core/os/threaded_array_processor.h b/core/os/threaded_array_processor.h index 00dc53286e..0a435961e1 100644 --- a/core/os/threaded_array_processor.h +++ b/core/os/threaded_array_processor.h @@ -54,7 +54,6 @@ struct ThreadArrayProcessData { template <class T> void process_array_thread(void *ud) { - T &data = *(T *)ud; while (true) { uint32_t index = atomic_increment(&data.index); @@ -66,7 +65,6 @@ void process_array_thread(void *ud) { 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; @@ -93,7 +91,6 @@ void thread_process_array(uint32_t p_elements, C *p_instance, M p_method, U p_us 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; diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp index 17b5905a93..b8f83f96a5 100644 --- a/core/packed_data_container.cpp +++ b/core/packed_data_container.cpp @@ -34,7 +34,6 @@ #include "core/io/marshalls.h" Variant PackedDataContainer::getvar(const Variant &p_key, bool *r_valid) const { - bool err = false; Variant ret = _key_at_ofs(0, p_key, err); if (r_valid) @@ -43,12 +42,10 @@ Variant PackedDataContainer::getvar(const Variant &p_key, bool *r_valid) const { } int PackedDataContainer::size() const { - return _size(0); }; Variant PackedDataContainer::_iter_init_ofs(const Array &p_iter, uint32_t p_offset) { - Array ref = p_iter; uint32_t size = _size(p_offset); if (size == 0 || ref.size() != 1) @@ -60,7 +57,6 @@ Variant PackedDataContainer::_iter_init_ofs(const Array &p_iter, uint32_t p_offs } Variant PackedDataContainer::_iter_next_ofs(const Array &p_iter, uint32_t p_offset) { - Array ref = p_iter; int size = _size(p_offset); if (ref.size() != 1) @@ -74,7 +70,6 @@ Variant PackedDataContainer::_iter_next_ofs(const Array &p_iter, uint32_t p_offs } Variant PackedDataContainer::_iter_get_ofs(const Variant &p_iter, uint32_t p_offset) { - int size = _size(p_offset); int pos = p_iter; if (pos < 0 || pos >= size) @@ -86,12 +81,10 @@ Variant PackedDataContainer::_iter_get_ofs(const Variant &p_iter, uint32_t p_off bool err = false; if (type == TYPE_ARRAY) { - uint32_t vpos = decode_uint32(rd + p_offset + 8 + pos * 4); return _get_at_ofs(vpos, rd, err); } else if (type == TYPE_DICT) { - uint32_t vpos = decode_uint32(rd + p_offset + 8 + pos * 12 + 4); return _get_at_ofs(vpos, rd, err); } else { @@ -100,11 +93,9 @@ Variant PackedDataContainer::_iter_get_ofs(const Variant &p_iter, uint32_t p_off } Variant PackedDataContainer::_get_at_ofs(uint32_t p_ofs, const uint8_t *p_buf, bool &err) const { - uint32_t type = decode_uint32(p_buf + p_ofs); if (type == TYPE_ARRAY || type == TYPE_DICT) { - Ref<PackedDataContainerRef> pdcr = memnew(PackedDataContainerRef); Ref<PackedDataContainer> pdc = Ref<PackedDataContainer>((PackedDataContainer *)this); @@ -112,12 +103,10 @@ Variant PackedDataContainer::_get_at_ofs(uint32_t p_ofs, const uint8_t *p_buf, b pdcr->offset = p_ofs; return pdcr; } else { - Variant v; Error rerr = decode_variant(v, p_buf + p_ofs, datalen - p_ofs, nullptr, false); if (rerr != OK) { - err = true; ERR_FAIL_COND_V_MSG(err != OK, Variant(), "Error when trying to decode Variant."); } @@ -126,7 +115,6 @@ Variant PackedDataContainer::_get_at_ofs(uint32_t p_ofs, const uint8_t *p_buf, b } uint32_t PackedDataContainer::_type_at_ofs(uint32_t p_ofs) const { - const uint8_t *rd = data.ptr(); const uint8_t *r = &rd[p_ofs]; uint32_t type = decode_uint32(r); @@ -135,19 +123,16 @@ uint32_t PackedDataContainer::_type_at_ofs(uint32_t p_ofs) const { }; int PackedDataContainer::_size(uint32_t p_ofs) const { - const uint8_t *rd = data.ptr(); ERR_FAIL_COND_V(!rd, 0); const uint8_t *r = &rd[p_ofs]; uint32_t type = decode_uint32(r); if (type == TYPE_ARRAY) { - uint32_t len = decode_uint32(r + 4); return len; } else if (type == TYPE_DICT) { - uint32_t len = decode_uint32(r + 4); return len; }; @@ -156,15 +141,12 @@ int PackedDataContainer::_size(uint32_t p_ofs) const { }; Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs, const Variant &p_key, bool &err) const { - const uint8_t *rd = data.ptr(); const uint8_t *r = &rd[p_ofs]; uint32_t type = decode_uint32(r); if (type == TYPE_ARRAY) { - if (p_key.is_num()) { - int idx = p_key; int len = decode_uint32(r + 4); if (idx < 0 || idx >= len) { @@ -180,7 +162,6 @@ Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs, const Variant &p_key, b } } else if (type == TYPE_DICT) { - uint32_t hash = p_key.hash(); uint32_t len = decode_uint32(r + 4); @@ -206,18 +187,14 @@ Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs, const Variant &p_key, b return Variant(); } else { - err = true; return Variant(); } } uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpdata, Map<String, uint32_t> &string_cache) { - switch (p_data.get_type()) { - case Variant::STRING: { - String s = p_data; if (string_cache.has(s)) { return string_cache[s]; @@ -251,7 +228,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd case Variant::PACKED_COLOR_ARRAY: case Variant::STRING_NAME: case Variant::NODE_PATH: { - uint32_t pos = tmpdata.size(); int len; encode_variant(p_data, nullptr, len, false); @@ -263,11 +239,9 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd // misc types case Variant::_RID: case Variant::OBJECT: { - return _pack(Variant(), tmpdata, string_cache); } break; case Variant::DICTIONARY: { - Dictionary d = p_data; //size is known, use sort uint32_t pos = tmpdata.size(); @@ -281,7 +255,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd List<DictKey> sortk; for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { - DictKey dk; dk.hash = E->get().hash(); dk.key = E->get(); @@ -292,7 +265,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd int idx = 0; for (List<DictKey>::Element *E = sortk.front(); E; E = E->next()) { - encode_uint32(E->get().hash, &tmpdata.write[pos + 8 + idx * 12 + 0]); uint32_t ofs = _pack(E->get().key, tmpdata, string_cache); encode_uint32(ofs, &tmpdata.write[pos + 8 + idx * 12 + 4]); @@ -305,7 +277,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd } break; case Variant::ARRAY: { - Array a = p_data; //size is known, use sort uint32_t pos = tmpdata.size(); @@ -315,7 +286,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd encode_uint32(len, &tmpdata.write[pos + 4]); for (int i = 0; i < len; i++) { - uint32_t ofs = _pack(a[i], tmpdata, string_cache); encode_uint32(ofs, &tmpdata.write[pos + 8 + i * 4]); } @@ -332,7 +302,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd } Error PackedDataContainer::pack(const Variant &p_data) { - Vector<uint8_t> tmpdata; Map<String, uint32_t> string_cache; _pack(p_data, tmpdata, string_cache); @@ -345,7 +314,6 @@ Error PackedDataContainer::pack(const Variant &p_data) { } void PackedDataContainer::_set_data(const Vector<uint8_t> &p_data) { - data = p_data; datalen = data.size(); } @@ -355,21 +323,17 @@ Vector<uint8_t> PackedDataContainer::_get_data() const { } Variant PackedDataContainer::_iter_init(const Array &p_iter) { - return _iter_init_ofs(p_iter, 0); } Variant PackedDataContainer::_iter_next(const Array &p_iter) { - return _iter_next_ofs(p_iter, 0); } Variant PackedDataContainer::_iter_get(const Variant &p_iter) { - return _iter_get_ofs(p_iter, 0); } void PackedDataContainer::_bind_methods() { - ClassDB::bind_method(D_METHOD("_set_data"), &PackedDataContainer::_set_data); ClassDB::bind_method(D_METHOD("_get_data"), &PackedDataContainer::_get_data); ClassDB::bind_method(D_METHOD("_iter_init"), &PackedDataContainer::_iter_init); @@ -384,26 +348,21 @@ void PackedDataContainer::_bind_methods() { ////////////////// Variant PackedDataContainerRef::_iter_init(const Array &p_iter) { - return from->_iter_init_ofs(p_iter, offset); } Variant PackedDataContainerRef::_iter_next(const Array &p_iter) { - return from->_iter_next_ofs(p_iter, offset); } Variant PackedDataContainerRef::_iter_get(const Variant &p_iter) { - return from->_iter_get_ofs(p_iter, offset); } bool PackedDataContainerRef::_is_dictionary() const { - return from->_type_at_ofs(offset) == PackedDataContainer::TYPE_DICT; }; void PackedDataContainerRef::_bind_methods() { - ClassDB::bind_method(D_METHOD("size"), &PackedDataContainerRef::size); ClassDB::bind_method(D_METHOD("_iter_init"), &PackedDataContainerRef::_iter_init); ClassDB::bind_method(D_METHOD("_iter_get"), &PackedDataContainerRef::_iter_get); @@ -412,7 +371,6 @@ void PackedDataContainerRef::_bind_methods() { } Variant PackedDataContainerRef::getvar(const Variant &p_key, bool *r_valid) const { - bool err = false; Variant ret = from->_key_at_ofs(offset, p_key, err); if (r_valid) @@ -421,6 +379,5 @@ Variant PackedDataContainerRef::getvar(const Variant &p_key, bool *r_valid) cons } int PackedDataContainerRef::size() const { - return from->_size(offset); }; diff --git a/core/packed_data_container.h b/core/packed_data_container.h index 00ec4248ee..b41e9aaefc 100644 --- a/core/packed_data_container.h +++ b/core/packed_data_container.h @@ -34,7 +34,6 @@ #include "core/resource.h" class PackedDataContainer : public Resource { - GDCLASS(PackedDataContainer, Resource); enum { diff --git a/core/pair.h b/core/pair.h index 26a317e9d4..89ea2b9fd9 100644 --- a/core/pair.h +++ b/core/pair.h @@ -33,7 +33,6 @@ template <class F, class S> struct Pair { - F first; S second; @@ -60,7 +59,6 @@ bool operator!=(const Pair<F, S> &pair, const Pair<F, S> &other) { template <class F, class S> struct PairSort { - bool operator()(const Pair<F, S> &A, const Pair<F, S> &B) const { return A.first < B.first; } diff --git a/core/pool_allocator.cpp b/core/pool_allocator.cpp index 8fd67a47d2..20b5edd412 100644 --- a/core/pool_allocator.cpp +++ b/core/pool_allocator.cpp @@ -53,12 +53,10 @@ void PoolAllocator::mt_unlock() const { } bool PoolAllocator::get_free_entry(EntryArrayPos *p_pos) { - if (entry_count == entry_max) return false; for (int i = 0; i < entry_max; i++) { - if (entry_array[i].len == 0) { *p_pos = i; return true; @@ -77,13 +75,11 @@ bool PoolAllocator::get_free_entry(EntryArrayPos *p_pos) { * @return false if hole found, true if no hole found */ bool PoolAllocator::find_hole(EntryArrayPos *p_pos, int p_for_size) { - /* position where previous entry ends. Defaults to zero (begin of pool) */ int prev_entry_end_pos = 0; for (int i = 0; i < entry_count; i++) { - Entry &entry = entry_array[entry_indices[i]]; /* determine hole size to previous entry */ @@ -111,13 +107,11 @@ bool PoolAllocator::find_hole(EntryArrayPos *p_pos, int p_for_size) { } void PoolAllocator::compact(int p_up_to) { - uint32_t prev_entry_end_pos = 0; if (p_up_to < 0) p_up_to = entry_count; for (int i = 0; i < p_up_to; i++) { - Entry &entry = entry_array[entry_indices[i]]; /* determine hole size to previous entry */ @@ -126,7 +120,6 @@ void PoolAllocator::compact(int p_up_to) { /* if we can compact, do it */ if (hole_size > 0 && !entry.lock) { - COMPACT_CHUNK(entry, prev_entry_end_pos); } @@ -136,11 +129,9 @@ void PoolAllocator::compact(int p_up_to) { } void PoolAllocator::compact_up(int p_from) { - uint32_t next_entry_end_pos = pool_size; // - static_area_size; for (int i = entry_count - 1; i >= p_from; i--) { - Entry &entry = entry_array[entry_indices[i]]; /* determine hole size to nextious entry */ @@ -149,7 +140,6 @@ void PoolAllocator::compact_up(int p_from) { /* if we can compact, do it */ if (hole_size > 0 && !entry.lock) { - COMPACT_CHUNK(entry, (next_entry_end_pos - aligned(entry.len))); } @@ -159,13 +149,10 @@ void PoolAllocator::compact_up(int p_from) { } bool PoolAllocator::find_entry_index(EntryIndicesPos *p_map_pos, Entry *p_entry) { - EntryArrayPos entry_pos = entry_max; for (int i = 0; i < entry_count; i++) { - if (&entry_array[entry_indices[i]] == p_entry) { - entry_pos = i; break; } @@ -179,7 +166,6 @@ bool PoolAllocator::find_entry_index(EntryIndicesPos *p_map_pos, Entry *p_entry) } PoolAllocator::ID PoolAllocator::alloc(int p_size) { - ERR_FAIL_COND_V(p_size < 1, POOL_ALLOCATOR_INVALID_ID); #ifdef DEBUG_ENABLED if (p_size > free_mem) @@ -221,7 +207,6 @@ PoolAllocator::ID PoolAllocator::alloc(int p_size) { /* move all entry indices up, make room for this one */ for (int i = entry_count; i > new_entry_indices_pos; i--) { - entry_indices[i] = entry_indices[i - 1]; } @@ -248,7 +233,6 @@ PoolAllocator::ID PoolAllocator::alloc(int p_size) { } PoolAllocator::Entry *PoolAllocator::get_entry(ID p_mem) { - unsigned int check = p_mem & CHECK_MASK; int entry = p_mem >> CHECK_BITS; ERR_FAIL_INDEX_V(entry, entry_max, nullptr); @@ -259,7 +243,6 @@ PoolAllocator::Entry *PoolAllocator::get_entry(ID p_mem) { } const PoolAllocator::Entry *PoolAllocator::get_entry(ID p_mem) const { - unsigned int check = p_mem & CHECK_MASK; int entry = p_mem >> CHECK_BITS; ERR_FAIL_INDEX_V(entry, entry_max, nullptr); @@ -270,7 +253,6 @@ const PoolAllocator::Entry *PoolAllocator::get_entry(ID p_mem) const { } void PoolAllocator::free(ID p_mem) { - mt_lock(); Entry *e = get_entry(p_mem); if (!e) { @@ -288,13 +270,11 @@ void PoolAllocator::free(ID p_mem) { bool index_found = find_entry_index(&entry_indices_pos, e); if (!index_found) { - mt_unlock(); ERR_FAIL_COND(!index_found); } for (int i = entry_indices_pos; i < (entry_count - 1); i++) { - entry_indices[i] = entry_indices[i + 1]; } @@ -305,13 +285,11 @@ void PoolAllocator::free(ID p_mem) { } int PoolAllocator::get_size(ID p_mem) const { - int size; mt_lock(); const Entry *e = get_entry(p_mem); if (!e) { - mt_unlock(); ERR_PRINT("!e"); return 0; @@ -325,7 +303,6 @@ int PoolAllocator::get_size(ID p_mem) const { } Error PoolAllocator::resize(ID p_mem, int p_new_size) { - mt_lock(); Entry *e = get_entry(p_mem); @@ -342,12 +319,10 @@ Error PoolAllocator::resize(ID p_mem, int p_new_size) { uint32_t alloc_size = aligned(p_new_size); if ((uint32_t)aligned(e->len) == alloc_size) { - e->len = p_new_size; mt_unlock(); return OK; } else if (e->len > (uint32_t)p_new_size) { - free_mem += aligned(e->len); free_mem -= alloc_size; e->len = p_new_size; @@ -368,7 +343,6 @@ Error PoolAllocator::resize(ID p_mem, int p_new_size) { bool index_found = find_entry_index(&entry_indices_pos, e); if (!index_found) { - mt_unlock(); ERR_FAIL_COND_V(!index_found, ERR_BUG); } @@ -423,13 +397,11 @@ Error PoolAllocator::resize(ID p_mem, int p_new_size) { } Error PoolAllocator::lock(ID p_mem) { - if (!needs_locking) return OK; mt_lock(); Entry *e = get_entry(p_mem); if (!e) { - mt_unlock(); ERR_PRINT("!e"); return ERR_INVALID_PARAMETER; @@ -440,14 +412,12 @@ Error PoolAllocator::lock(ID p_mem) { } bool PoolAllocator::is_locked(ID p_mem) const { - if (!needs_locking) return false; mt_lock(); const Entry *e = ((PoolAllocator *)(this))->get_entry(p_mem); if (!e) { - mt_unlock(); ERR_PRINT("!e"); return false; @@ -458,9 +428,7 @@ bool PoolAllocator::is_locked(ID p_mem) const { } const void *PoolAllocator::get(ID p_mem) const { - if (!needs_locking) { - const Entry *e = get_entry(p_mem); ERR_FAIL_COND_V(!e, nullptr); return &pool[e->pos]; @@ -470,19 +438,16 @@ const void *PoolAllocator::get(ID p_mem) const { const Entry *e = get_entry(p_mem); if (!e) { - mt_unlock(); ERR_FAIL_COND_V(!e, nullptr); } if (e->lock == 0) { - mt_unlock(); ERR_PRINT("e->lock == 0"); return nullptr; } if ((int)e->pos >= pool_size) { - mt_unlock(); ERR_PRINT("e->pos<0 || e->pos>=pool_size"); return nullptr; @@ -495,9 +460,7 @@ const void *PoolAllocator::get(ID p_mem) const { } void *PoolAllocator::get(ID p_mem) { - if (!needs_locking) { - Entry *e = get_entry(p_mem); ERR_FAIL_COND_V(!e, nullptr); return &pool[e->pos]; @@ -507,12 +470,10 @@ void *PoolAllocator::get(ID p_mem) { Entry *e = get_entry(p_mem); if (!e) { - mt_unlock(); ERR_FAIL_COND_V(!e, nullptr); } if (e->lock == 0) { - //assert(0); mt_unlock(); ERR_PRINT("e->lock == 0"); @@ -520,7 +481,6 @@ void *PoolAllocator::get(ID p_mem) { } if ((int)e->pos >= pool_size) { - mt_unlock(); ERR_PRINT("e->pos<0 || e->pos>=pool_size"); return nullptr; @@ -532,7 +492,6 @@ void *PoolAllocator::get(ID p_mem) { return ptr; } void PoolAllocator::unlock(ID p_mem) { - if (!needs_locking) return; mt_lock(); @@ -551,22 +510,18 @@ void PoolAllocator::unlock(ID p_mem) { } int PoolAllocator::get_used_mem() const { - return pool_size - free_mem; } int PoolAllocator::get_free_peak() { - return free_mem_peak; } int PoolAllocator::get_free_mem() { - return free_mem; } void PoolAllocator::create_pool(void *p_mem, int p_size, int p_max_entries) { - pool = (uint8_t *)p_mem; pool_size = p_size; @@ -582,7 +537,6 @@ void PoolAllocator::create_pool(void *p_mem, int p_size, int p_max_entries) { } PoolAllocator::PoolAllocator(int p_size, bool p_needs_locking, int p_max_entries) { - mem_ptr = memalloc(p_size); ERR_FAIL_COND(!mem_ptr); align = 1; @@ -591,9 +545,7 @@ PoolAllocator::PoolAllocator(int p_size, bool p_needs_locking, int p_max_entries } PoolAllocator::PoolAllocator(void *p_mem, int p_size, int p_align, bool p_needs_locking, int p_max_entries) { - if (p_align > 1) { - uint8_t *mem8 = (uint8_t *)p_mem; uint64_t ofs = (uint64_t)mem8; if (ofs % p_align) { @@ -611,7 +563,6 @@ PoolAllocator::PoolAllocator(void *p_mem, int p_size, int p_align, bool p_needs_ } PoolAllocator::PoolAllocator(int p_align, int p_size, bool p_needs_locking, int p_max_entries) { - ERR_FAIL_COND(p_align < 1); mem_ptr = Memory::alloc_static(p_size + p_align, true); uint8_t *mem8 = (uint8_t *)mem_ptr; @@ -624,7 +575,6 @@ PoolAllocator::PoolAllocator(int p_align, int p_size, bool p_needs_locking, int } PoolAllocator::~PoolAllocator() { - if (mem_ptr) memfree(mem_ptr); diff --git a/core/pool_allocator.h b/core/pool_allocator.h index 1cc21afb21..cec95c7323 100644 --- a/core/pool_allocator.h +++ b/core/pool_allocator.h @@ -60,7 +60,6 @@ private: }; struct Entry { - unsigned int pos = 0; unsigned int len = 0; unsigned int lock = 0; @@ -99,7 +98,6 @@ private: return p_entry.pos + aligned(p_entry.len); } inline int aligned(int p_size) const { - int rem = p_size % align; if (rem) p_size += align - rem; diff --git a/core/print_string.cpp b/core/print_string.cpp index 8eb1d9e86a..b7903b6880 100644 --- a/core/print_string.cpp +++ b/core/print_string.cpp @@ -39,7 +39,6 @@ bool _print_line_enabled = true; bool _print_error_enabled = true; void add_print_handler(PrintHandlerList *p_handler) { - _global_lock(); p_handler->next = print_handler_list; print_handler_list = p_handler; @@ -47,16 +46,13 @@ void add_print_handler(PrintHandlerList *p_handler) { } void remove_print_handler(PrintHandlerList *p_handler) { - _global_lock(); PrintHandlerList *prev = nullptr; PrintHandlerList *l = print_handler_list; while (l) { - if (l == p_handler) { - if (prev) prev->next = l->next; else @@ -73,7 +69,6 @@ void remove_print_handler(PrintHandlerList *p_handler) { } void print_line(String p_string) { - if (!_print_line_enabled) return; @@ -82,7 +77,6 @@ void print_line(String p_string) { _global_lock(); PrintHandlerList *l = print_handler_list; while (l) { - l->printfunc(l->userdata, p_string, false); l = l->next; } @@ -91,7 +85,6 @@ void print_line(String p_string) { } void print_error(String p_string) { - if (!_print_error_enabled) return; @@ -100,7 +93,6 @@ void print_error(String p_string) { _global_lock(); PrintHandlerList *l = print_handler_list; while (l) { - l->printfunc(l->userdata, p_string, true); l = l->next; } @@ -109,7 +101,6 @@ void print_error(String p_string) { } void print_verbose(String p_string) { - if (OS::get_singleton()->is_stdout_verbose()) { print_line(p_string); } diff --git a/core/print_string.h b/core/print_string.h index 3e9125bddc..4d03f4a6de 100644 --- a/core/print_string.h +++ b/core/print_string.h @@ -38,7 +38,6 @@ extern void (*_print_func)(String); typedef void (*PrintHandlerFunc)(void *, const String &p_string, bool p_error); struct PrintHandlerList { - PrintHandlerFunc printfunc = nullptr; void *userdata = nullptr; diff --git a/core/project_settings.cpp b/core/project_settings.cpp index e141e54e61..42440c8085 100644 --- a/core/project_settings.cpp +++ b/core/project_settings.cpp @@ -46,17 +46,14 @@ ProjectSettings *ProjectSettings::singleton = nullptr; ProjectSettings *ProjectSettings::get_singleton() { - return singleton; } String ProjectSettings::get_resource_path() const { - return resource_path; }; String ProjectSettings::localize_path(const String &p_path) const { - if (resource_path == "") return p_path; //not initialized yet @@ -69,7 +66,6 @@ String ProjectSettings::localize_path(const String &p_path) const { String path = p_path.replace("\\", "/").simplify_path(); if (dir->change_dir(path) == OK) { - String cwd = dir->get_current_dir(); cwd = cwd.replace("\\", "/"); @@ -93,7 +89,6 @@ String ProjectSettings::localize_path(const String &p_path) const { return cwd.replace_first(res_path, "res://"); } else { - memdelete(dir); int sep = path.find_last("/"); @@ -116,30 +111,23 @@ String ProjectSettings::localize_path(const String &p_path) const { } void ProjectSettings::set_initial_value(const String &p_name, const Variant &p_value) { - ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + "."); props[p_name].initial = p_value; } void ProjectSettings::set_restart_if_changed(const String &p_name, bool p_restart) { - ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + "."); props[p_name].restart_if_changed = p_restart; } String ProjectSettings::globalize_path(const String &p_path) const { - if (p_path.begins_with("res://")) { - if (resource_path != "") { - return p_path.replace("res:/", resource_path); }; return p_path.replace("res://", ""); } else if (p_path.begins_with("user://")) { - String data_dir = OS::get_singleton()->get_user_data_dir(); if (data_dir != "") { - return p_path.replace("user:/", data_dir); }; return p_path.replace("user://", ""); @@ -149,17 +137,14 @@ String ProjectSettings::globalize_path(const String &p_path) const { } bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) { - _THREAD_SAFE_METHOD_ if (p_value.get_type() == Variant::NIL) props.erase(p_name); else { - if (p_name == CoreStringNames::get_singleton()->_custom_features) { Vector<String> custom_feature_array = String(p_value).split(","); for (int i = 0; i < custom_feature_array.size(); i++) { - custom_features.insert(custom_feature_array[i]); } return true; @@ -180,7 +165,6 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) { } if (override_valid) { - feature_overrides[s[0]] = p_name; } } @@ -198,7 +182,6 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) { return true; } bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const { - _THREAD_SAFE_METHOD_ StringName name = p_name; @@ -214,7 +197,6 @@ bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const { } struct _VCSort { - String name; Variant::Type type; int order; @@ -224,13 +206,11 @@ struct _VCSort { }; void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const { - _THREAD_SAFE_METHOD_ Set<_VCSort> vclist; for (Map<StringName, VariantContainer>::Element *E = props.front(); E; E = E->next()) { - const VariantContainer *v = &E->get(); if (v->hide_from_editor) @@ -252,7 +232,6 @@ void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const { } for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) { - String prop_info_name = E->get().name; int dot = prop_info_name.find("."); if (dot != -1) @@ -269,7 +248,6 @@ void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const { } bool ProjectSettings::_load_resource_pack(const String &p_pack, bool p_replace_files) { - if (PackedData::get_singleton()->is_disabled()) return false; @@ -286,7 +264,6 @@ bool ProjectSettings::_load_resource_pack(const String &p_pack, bool p_replace_f } void ProjectSettings::_convert_to_last_version(int p_from_version) { - if (p_from_version <= 3) { // Converts the actions from array to dictionary (array of events to dictionary with deadzone + events) for (Map<StringName, ProjectSettings::VariantContainer>::Element *E = props.front(); E; E = E->next()) { @@ -322,11 +299,9 @@ void ProjectSettings::_convert_to_last_version(int p_from_version) { * If nothing was found, error out. */ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, bool p_upwards) { - // If looking for files in a network client, use it directly if (FileAccessNetworkClient::get_singleton()) { - Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary"); if (err == OK) { // Optional, we don't mind if it fails @@ -338,7 +313,6 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b // Attempt with a user-defined main pack first if (p_main_pack != "") { - bool ok = _load_resource_pack(p_main_pack); ERR_FAIL_COND_V_MSG(!ok, ERR_CANT_OPEN, "Cannot open resource pack '" + p_main_pack + "'."); @@ -477,19 +451,16 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo } bool ProjectSettings::has_setting(String p_var) const { - _THREAD_SAFE_METHOD_ return props.has(p_var); } void ProjectSettings::set_registering_order(bool p_enable) { - registering_order = p_enable; } Error ProjectSettings::_load_settings_binary(const String &p_path) { - Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); if (err != OK) { @@ -499,7 +470,6 @@ Error ProjectSettings::_load_settings_binary(const String &p_path) { uint8_t hdr[4]; f->get_buffer(hdr, 4); if (hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G') { - memdelete(f); ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Corrupted header in binary project.binary (not ECFG)."); } @@ -507,7 +477,6 @@ Error ProjectSettings::_load_settings_binary(const String &p_path) { uint32_t count = f->get_32(); for (uint32_t i = 0; i < count; i++) { - uint32_t slen = f->get_32(); CharString cs; cs.resize(slen + 1); @@ -532,7 +501,6 @@ Error ProjectSettings::_load_settings_binary(const String &p_path) { } Error ProjectSettings::_load_settings_text(const String &p_path) { - Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); @@ -555,7 +523,6 @@ Error ProjectSettings::_load_settings_text(const String &p_path) { int config_version = 0; while (true) { - assign = Variant(); next_tag.fields.clear(); next_tag.name = String(); @@ -594,7 +561,6 @@ Error ProjectSettings::_load_settings_text(const String &p_path) { } Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path, const String &p_bin_path) { - // Attempt first to load the text-based project.godot file Error err_text = _load_settings_text(p_text_path); if (err_text == OK) { @@ -611,19 +577,16 @@ Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path, } int ProjectSettings::get_order(const String &p_name) const { - ERR_FAIL_COND_V_MSG(!props.has(p_name), -1, "Request for nonexistent project setting: " + p_name + "."); return props[p_name].order; } void ProjectSettings::set_order(const String &p_name, int p_order) { - ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + "."); props[p_name].order = p_order; } void ProjectSettings::set_builtin_order(const String &p_name) { - ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + "."); if (props[p_name].order >= NO_BUILTIN_ORDER_BASE) { props[p_name].order = last_builtin_order++; @@ -631,18 +594,15 @@ void ProjectSettings::set_builtin_order(const String &p_name) { } void ProjectSettings::clear(const String &p_name) { - ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + "."); props.erase(p_name); } Error ProjectSettings::save() { - return save_custom(get_resource_path().plus_file("project.godot")); } Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) { - Error err; FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err); ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.binary at " + p_file + "."); @@ -653,9 +613,7 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str int count = 0; for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) { - for (List<String>::Element *F = E->get().front(); F; F = F->next()) { - count++; } } @@ -690,9 +648,7 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str } for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) { - for (List<String>::Element *F = E->get().front(); F; F = F->next()) { - String key = F->get(); if (E->key() != "") key = E->key() + "/" + key; @@ -730,7 +686,6 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str } Error ProjectSettings::_save_settings_text(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) { - Error err; FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err); @@ -751,14 +706,12 @@ Error ProjectSettings::_save_settings_text(const String &p_file, const Map<Strin file->store_string("\n"); for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) { - if (E != props.front()) file->store_string("\n"); if (E->key() != "") file->store_string("[" + E->key() + "]\n\n"); for (List<String>::Element *F = E->get().front(); F; F = F->next()) { - String key = F->get(); if (E->key() != "") key = E->key() + "/" + key; @@ -786,14 +739,12 @@ Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other par }; Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_custom, const Vector<String> &p_custom_features, bool p_merge_with_current) { - ERR_FAIL_COND_V_MSG(p_path == "", ERR_INVALID_PARAMETER, "Project settings save path cannot be empty."); Set<_VCSort> vclist; if (p_merge_with_current) { for (Map<StringName, VariantContainer>::Element *G = props.front(); G; G = G->next()) { - const VariantContainer *v = &G->get(); if (v->hide_from_editor) @@ -815,7 +766,6 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust } for (const Map<String, Variant>::Element *E = p_custom.front(); E; E = E->next()) { - // Lookup global prop to store in the same order Map<StringName, VariantContainer>::Element *global_prop = props.find(E->key()); @@ -830,7 +780,6 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust Map<String, List<String>> props; for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) { - String category = E->get().name; String name = E->get().name; @@ -839,7 +788,6 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust if (div < 0) category = ""; else { - category = category.substr(0, div); name = name.substr(div + 1, name.size()); } @@ -861,13 +809,11 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust else if (p_path.ends_with(".binary")) return _save_settings_binary(p_path, props, p_custom, custom_features); else { - ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Unknown config file format: " + p_path + "."); } } Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default, bool p_restart_if_changed) { - Variant ret; if (!ProjectSettings::get_singleton()->has_setting(p_var)) { ProjectSettings::get_singleton()->set(p_var, p_default); @@ -881,13 +827,11 @@ Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default, bool p_restar } Vector<String> ProjectSettings::get_optimizer_presets() const { - List<PropertyInfo> pi; ProjectSettings::get_singleton()->get_property_list(&pi); Vector<String> names; for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) { - if (!E->get().name.begins_with("optimizer_presets/")) continue; names.push_back(E->get().name.get_slicec('/', 1)); @@ -899,7 +843,6 @@ Vector<String> ProjectSettings::get_optimizer_presets() const { } void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) { - ERR_FAIL_COND(!p_info.has("name")); ERR_FAIL_COND(!p_info.has("type")); @@ -918,7 +861,6 @@ void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) { } void ProjectSettings::set_custom_property_info(const String &p_prop, const PropertyInfo &p_info) { - ERR_FAIL_COND(!props.has(p_prop)); custom_prop_info[p_prop] = p_info; custom_prop_info[p_prop].name = p_prop; @@ -929,17 +871,14 @@ const Map<StringName, PropertyInfo> &ProjectSettings::get_custom_property_info() } void ProjectSettings::set_disable_feature_overrides(bool p_disable) { - disable_feature_overrides = p_disable; } bool ProjectSettings::is_using_datapack() const { - return using_datapack; } bool ProjectSettings::property_can_revert(const String &p_name) { - if (!props.has(p_name)) return false; @@ -947,7 +886,6 @@ bool ProjectSettings::property_can_revert(const String &p_name) { } Variant ProjectSettings::property_get_revert(const String &p_name) { - if (!props.has(p_name)) return Variant(); @@ -967,7 +905,6 @@ bool ProjectSettings::has_custom_feature(const String &p_feature) const { } void ProjectSettings::_bind_methods() { - ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting); ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting); ClassDB::bind_method(D_METHOD("get_setting", "name"), &ProjectSettings::get_setting); @@ -987,7 +924,6 @@ void ProjectSettings::_bind_methods() { } ProjectSettings::ProjectSettings() { - singleton = this; Array events; @@ -1202,6 +1138,5 @@ ProjectSettings::ProjectSettings() { } ProjectSettings::~ProjectSettings() { - singleton = nullptr; } diff --git a/core/project_settings.h b/core/project_settings.h index 87f2a8273f..3ed80738a1 100644 --- a/core/project_settings.h +++ b/core/project_settings.h @@ -36,7 +36,6 @@ #include "core/set.h" class ProjectSettings : public Object { - GDCLASS(ProjectSettings, Object); _THREAD_SAFE_CLASS_ diff --git a/core/reference.cpp b/core/reference.cpp index 57b72dcaad..cc8a9854fb 100644 --- a/core/reference.cpp +++ b/core/reference.cpp @@ -33,22 +33,18 @@ #include "core/script_language.h" bool Reference::init_ref() { - if (reference()) { - if (!is_referenced() && refcount_init.unref()) { unreference(); // first referencing is already 1, so compensate for the ref above } return true; } else { - return false; } } void Reference::_bind_methods() { - ClassDB::bind_method(D_METHOD("init_ref"), &Reference::init_ref); ClassDB::bind_method(D_METHOD("reference"), &Reference::reference); ClassDB::bind_method(D_METHOD("unreference"), &Reference::unreference); @@ -59,7 +55,6 @@ int Reference::reference_get_count() const { } bool Reference::reference() { - uint32_t rc_val = refcount.refval(); bool success = rc_val != 0; @@ -80,7 +75,6 @@ bool Reference::reference() { } bool Reference::unreference() { - uint32_t rc_val = refcount.unrefval(); bool die = rc_val == 0; @@ -104,13 +98,11 @@ bool Reference::unreference() { Reference::Reference() : Object(true) { - refcount.init(); refcount_init.init(); } Variant WeakRef::get_ref() const { - if (ref.is_null()) return Variant(); @@ -119,7 +111,6 @@ Variant WeakRef::get_ref() const { return Variant(); Reference *r = cast_to<Reference>(obj); if (r) { - return REF(r); } @@ -131,11 +122,9 @@ void WeakRef::set_obj(Object *p_object) { } void WeakRef::set_ref(const REF &p_ref) { - ref = p_ref.is_valid() ? p_ref->get_instance_id() : ObjectID(); } void WeakRef::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_ref"), &WeakRef::get_ref); } diff --git a/core/reference.h b/core/reference.h index 5190f6ab11..972fd500d0 100644 --- a/core/reference.h +++ b/core/reference.h @@ -36,7 +36,6 @@ #include "core/safe_refcount.h" class Reference : public Object { - GDCLASS(Reference, Object); SafeRefCount refcount; SafeRefCount refcount_init; @@ -57,11 +56,9 @@ public: template <class T> class Ref { - T *reference = nullptr; void ref(const Ref &p_from) { - if (p_from.reference == reference) return; @@ -73,7 +70,6 @@ class Ref { } void ref_pointer(T *p_ref) { - ERR_FAIL_COND(!p_ref); if (p_ref->init_ref()) @@ -90,60 +86,48 @@ public: } _FORCE_INLINE_ bool operator<(const Ref<T> &p_r) const { - return reference < p_r.reference; } _FORCE_INLINE_ bool operator==(const Ref<T> &p_r) const { - return reference == p_r.reference; } _FORCE_INLINE_ bool operator!=(const Ref<T> &p_r) const { - return reference != p_r.reference; } _FORCE_INLINE_ T *operator->() { - return reference; } _FORCE_INLINE_ T *operator*() { - return reference; } _FORCE_INLINE_ const T *operator->() const { - return reference; } _FORCE_INLINE_ const T *ptr() const { - return reference; } _FORCE_INLINE_ T *ptr() { - return reference; } _FORCE_INLINE_ const T *operator*() const { - return reference; } operator Variant() const { - return Variant(reference); } void operator=(const Ref &p_from) { - ref(p_from); } template <class T_Other> void operator=(const Ref<T_Other> &p_from) { - Reference *refb = const_cast<Reference *>(static_cast<const Reference *>(p_from.ptr())); if (!refb) { unref(); @@ -156,7 +140,6 @@ public: } void operator=(const Variant &p_variant) { - Object *object = p_variant.get_validated_object(); if (object == reference) { @@ -232,7 +215,6 @@ public: // mutexes will avoid more crashes? if (reference && reference->unreference()) { - memdelete(reference); } reference = nullptr; @@ -252,7 +234,6 @@ public: typedef Ref<Reference> REF; class WeakRef : public Reference { - GDCLASS(WeakRef, Reference); ObjectID ref; @@ -272,23 +253,18 @@ public: template <class T> struct PtrToArg<Ref<T>> { - _FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) { - return Ref<T>(const_cast<T *>(reinterpret_cast<const T *>(p_ptr))); } _FORCE_INLINE_ static void encode(Ref<T> p_val, const void *p_ptr) { - *(Ref<Reference> *)p_ptr = p_val; } }; template <class T> struct PtrToArg<const Ref<T> &> { - _FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) { - return Ref<T>((T *)p_ptr); } }; diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index f24397be5b..230acb7e6e 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -97,7 +97,6 @@ extern void register_variant_methods(); extern void unregister_variant_methods(); void register_core_types() { - //consistency check static_assert(sizeof(Callable) <= 16); @@ -237,7 +236,6 @@ void register_core_settings() { } void register_core_singletons() { - ClassDB::register_class<ProjectSettings>(); ClassDB::register_virtual_class<IP>(); ClassDB::register_class<_Geometry>(); @@ -269,7 +267,6 @@ void register_core_singletons() { } void unregister_core_types() { - memdelete(_resource_loader); memdelete(_resource_saver); memdelete(_os); diff --git a/core/resource.cpp b/core/resource.cpp index f8948e9a59..0d8a223b78 100644 --- a/core/resource.cpp +++ b/core/resource.cpp @@ -39,7 +39,6 @@ #include <stdio.h> void Resource::emit_changed() { - emit_signal(CoreStringNames::get_singleton()->changed); } @@ -47,12 +46,10 @@ void Resource::_resource_path_changed() { } void Resource::set_path(const String &p_path, bool p_take_over) { - if (path_cache == p_path) return; if (path_cache != "") { - ResourceCache::lock->write_lock(); ResourceCache::resources.erase(path_cache); ResourceCache::lock->write_unlock(); @@ -66,7 +63,6 @@ void Resource::set_path(const String &p_path, bool p_take_over) { if (has_path) { if (p_take_over) { - ResourceCache::lock->write_lock(); Resource **res = ResourceCache::resources.getptr(p_path); if (res) { @@ -84,7 +80,6 @@ void Resource::set_path(const String &p_path, bool p_take_over) { path_cache = p_path; if (path_cache != "") { - ResourceCache::lock->write_lock(); ResourceCache::resources[path_cache] = this; ResourceCache::lock->write_unlock(); @@ -95,37 +90,30 @@ void Resource::set_path(const String &p_path, bool p_take_over) { } String Resource::get_path() const { - return path_cache; } void Resource::set_subindex(int p_sub_index) { - subindex = p_sub_index; } int Resource::get_subindex() const { - return subindex; } void Resource::set_name(const String &p_name) { - name = p_name; _change_notify("resource_name"); } String Resource::get_name() const { - return name; } bool Resource::editor_can_reload_from_file() { - return true; //by default yes } void Resource::reload_from_file() { - String path = get_path(); if (!path.is_resource_file()) return; @@ -139,7 +127,6 @@ void Resource::reload_from_file() { s->get_property_list(&pi); for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) continue; if (E->get().name == "resource_path") @@ -150,7 +137,6 @@ void Resource::reload_from_file() { } Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource>> &remap_cache) { - List<PropertyInfo> plist; get_property_list(&plist); @@ -160,20 +146,16 @@ Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Res r->local_scene = p_for_scene; for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) continue; Variant p = get(E->get().name); if (p.get_type() == Variant::OBJECT) { - RES sr = p; if (sr.is_valid()) { - if (sr->is_local_to_scene()) { if (remap_cache.has(sr)) { p = remap_cache[sr]; } else { - RES dupe = sr->duplicate_for_local_scene(p_for_scene, remap_cache); p = dupe; remap_cache[sr] = dupe; @@ -191,22 +173,18 @@ Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Res } void Resource::configure_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource>> &remap_cache) { - List<PropertyInfo> plist; get_property_list(&plist); local_scene = p_for_scene; for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) continue; Variant p = get(E->get().name); if (p.get_type() == Variant::OBJECT) { - RES sr = p; if (sr.is_valid()) { - if (sr->is_local_to_scene()) { if (!remap_cache.has(sr)) { sr->configure_for_local_scene(p_for_scene, remap_cache); @@ -219,7 +197,6 @@ void Resource::configure_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, R } Ref<Resource> Resource::duplicate(bool p_subresources) const { - List<PropertyInfo> plist; get_property_list(&plist); @@ -227,7 +204,6 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const { ERR_FAIL_COND_V(!r, Ref<Resource>()); for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) continue; Variant p = get(E->get().name); @@ -235,13 +211,11 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const { if ((p.get_type() == Variant::DICTIONARY || p.get_type() == Variant::ARRAY)) { r->set(E->get().name, p.duplicate(p_subresources)); } else if (p.get_type() == Variant::OBJECT && (p_subresources || (E->get().usage & PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE))) { - RES sr = p; if (sr.is_valid()) { r->set(E->get().name, sr->duplicate(p_subresources)); } } else { - r->set(E->get().name, p); } } @@ -250,34 +224,27 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const { } void Resource::_set_path(const String &p_path) { - set_path(p_path, false); } void Resource::_take_over_path(const String &p_path) { - set_path(p_path, true); } RID Resource::get_rid() const { - return RID(); } void Resource::register_owner(Object *p_owner) { - owners.insert(p_owner->get_instance_id()); } void Resource::unregister_owner(Object *p_owner) { - owners.erase(p_owner->get_instance_id()); } void Resource::notify_change_to_owners() { - for (Set<ObjectID>::Element *E = owners.front(); E; E = E->next()) { - Object *obj = ObjectDB::get_instance(E->get()); ERR_CONTINUE_MSG(!obj, "Object was deleted, while still owning a resource."); //wtf //TODO store string @@ -288,14 +255,12 @@ void Resource::notify_change_to_owners() { #ifdef TOOLS_ENABLED uint32_t Resource::hash_edited_version() const { - uint32_t hash = hash_djb2_one_32(get_edited_version()); List<PropertyInfo> plist; get_property_list(&plist); for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (E->get().usage & PROPERTY_USAGE_STORAGE && E->get().type == Variant::OBJECT && E->get().hint == PROPERTY_HINT_RESOURCE_TYPE) { RES res = get(E->get().name); if (res.is_valid()) { @@ -310,17 +275,14 @@ uint32_t Resource::hash_edited_version() const { #endif void Resource::set_local_to_scene(bool p_enable) { - local_to_scene = p_enable; } bool Resource::is_local_to_scene() const { - return local_to_scene; } Node *Resource::get_local_scene() const { - if (local_scene) return local_scene; @@ -332,7 +294,6 @@ Node *Resource::get_local_scene() const { } void Resource::setup_local_to_scene() { - if (get_script_instance()) get_script_instance()->call("_setup_local_to_scene"); } @@ -340,7 +301,6 @@ void Resource::setup_local_to_scene() { Node *(*Resource::_get_local_scene_func)() = nullptr; void Resource::set_as_translation_remapped(bool p_remapped) { - if (remapped_list.in_list() == p_remapped) return; @@ -360,7 +320,6 @@ void Resource::set_as_translation_remapped(bool p_remapped) { } bool Resource::is_translation_remapped() const { - return remapped_list.in_list(); } @@ -406,7 +365,6 @@ int Resource::get_id_for_path(const String &p_path) const { #endif void Resource::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_path", "path"), &Resource::_set_path); ClassDB::bind_method(D_METHOD("take_over_path", "path"), &Resource::_take_over_path); ClassDB::bind_method(D_METHOD("get_path"), &Resource::get_path); @@ -432,7 +390,6 @@ Resource::Resource() : remapped_list(this) {} Resource::~Resource() { - if (path_cache != "") { ResourceCache::lock->write_lock(); ResourceCache::resources.erase(path_cache); @@ -454,7 +411,6 @@ RWLock *ResourceCache::path_cache_lock = nullptr; #endif void ResourceCache::setup() { - lock = RWLock::create(); #ifdef TOOLS_ENABLED path_cache_lock = RWLock::create(); @@ -473,7 +429,6 @@ void ResourceCache::clear() { } void ResourceCache::reload_externals() { - /* const String *K=nullptr; while ((K=resources.next(K))) { @@ -483,7 +438,6 @@ void ResourceCache::reload_externals() { } bool ResourceCache::has(const String &p_path) { - lock->read_lock(); bool b = resources.has(p_path); lock->read_unlock(); @@ -491,7 +445,6 @@ bool ResourceCache::has(const String &p_path) { return b; } Resource *ResourceCache::get(const String &p_path) { - lock->read_lock(); Resource **res = resources.getptr(p_path); @@ -506,11 +459,9 @@ Resource *ResourceCache::get(const String &p_path) { } void ResourceCache::get_cached_resources(List<Ref<Resource>> *p_resources) { - lock->read_lock(); const String *K = nullptr; while ((K = resources.next(K))) { - Resource *r = resources[*K]; p_resources->push_back(Ref<Resource>(r)); } @@ -518,7 +469,6 @@ void ResourceCache::get_cached_resources(List<Ref<Resource>> *p_resources) { } int ResourceCache::get_cached_resource_count() { - lock->read_lock(); int rc = resources.size(); lock->read_unlock(); @@ -540,7 +490,6 @@ void ResourceCache::dump(const char *p_file, bool p_short) { const String *K = nullptr; while ((K = resources.next(K))) { - Resource *r = resources[*K]; if (!type_count.has(r->get_class())) { @@ -556,7 +505,6 @@ void ResourceCache::dump(const char *p_file, bool p_short) { } for (Map<String, int>::Element *E = type_count.front(); E; E = E->next()) { - if (f) f->store_line(E->key() + " count: " + itos(E->get())); } diff --git a/core/resource.h b/core/resource.h index 7d92b843dc..ad2f3ce913 100644 --- a/core/resource.h +++ b/core/resource.h @@ -45,7 +45,6 @@ public: private: class Resource : public Reference { - GDCLASS(Resource, Reference); OBJ_CATEGORY("Resources"); RES_BASE_EXTENSION("res"); diff --git a/core/rid.h b/core/rid.h index ac07eacd08..4b65f3fb6a 100644 --- a/core/rid.h +++ b/core/rid.h @@ -41,23 +41,18 @@ class RID { public: _FORCE_INLINE_ bool operator==(const RID &p_rid) const { - return _id == p_rid._id; } _FORCE_INLINE_ bool operator<(const RID &p_rid) const { - return _id < p_rid._id; } _FORCE_INLINE_ bool operator<=(const RID &p_rid) const { - return _id <= p_rid._id; } _FORCE_INLINE_ bool operator>(const RID &p_rid) const { - return _id > p_rid._id; } _FORCE_INLINE_ bool operator!=(const RID &p_rid) const { - return _id != p_rid._id; } _FORCE_INLINE_ bool is_valid() const { return _id != 0; } diff --git a/core/rid_owner.h b/core/rid_owner.h index 77bbc3c83c..2489475c68 100644 --- a/core/rid_owner.h +++ b/core/rid_owner.h @@ -44,7 +44,6 @@ #include <typeinfo> class RID_AllocBase { - static volatile uint64_t base_id; protected: @@ -68,7 +67,6 @@ public: template <class T, bool THREAD_SAFE = false> class RID_Alloc : public RID_AllocBase { - T **chunks = nullptr; uint32_t **free_list_chunks = nullptr; uint32_t **validator_chunks = nullptr; @@ -83,7 +81,6 @@ class RID_Alloc : public RID_AllocBase { public: RID make_rid(const T &p_value) { - if (THREAD_SAFE) { spin_lock.lock(); } @@ -137,7 +134,6 @@ public: } _FORCE_INLINE_ T *getornull(const RID &p_rid) { - if (THREAD_SAFE) { spin_lock.lock(); } @@ -172,7 +168,6 @@ public: } _FORCE_INLINE_ bool owns(const RID &p_rid) { - if (THREAD_SAFE) { spin_lock.lock(); } @@ -201,7 +196,6 @@ public: } _FORCE_INLINE_ void free(const RID &p_rid) { - if (THREAD_SAFE) { spin_lock.lock(); } diff --git a/core/ring_buffer.h b/core/ring_buffer.h index 8ef9b1a15c..816a5f33e1 100644 --- a/core/ring_buffer.h +++ b/core/ring_buffer.h @@ -35,7 +35,6 @@ template <typename T> class RingBuffer { - Vector<T> data; int read_pos = 0; int write_pos = 0; @@ -78,7 +77,6 @@ public: }; int copy(T *p_buf, int p_offset, int p_size) const { - int left = data_left(); if ((p_offset + p_size) > left) { p_size -= left - p_offset; @@ -104,7 +102,6 @@ public: }; int find(const T &t, int p_offset, int p_max_size) const { - int left = data_left(); if ((p_offset + p_max_size) > left) { p_max_size -= left - p_offset; @@ -148,7 +145,6 @@ public: }; int write(const T *p_buf, int p_size) { - int left = space_left(); p_size = MIN(left, p_size); @@ -156,7 +152,6 @@ public: int to_write = p_size; int src = 0; while (to_write) { - int end = pos + to_write; end = MIN(end, size()); int total = end - pos; diff --git a/core/safe_refcount.cpp b/core/safe_refcount.cpp index e4604faa09..22b9ff9741 100644 --- a/core/safe_refcount.cpp +++ b/core/safe_refcount.cpp @@ -63,22 +63,18 @@ _ALWAYS_INLINE_ uint32_t _atomic_conditional_increment_impl(volatile uint32_t *p } _ALWAYS_INLINE_ uint32_t _atomic_decrement_impl(volatile uint32_t *pw) { - return InterlockedDecrement((LONG volatile *)pw); } _ALWAYS_INLINE_ uint32_t _atomic_increment_impl(volatile uint32_t *pw) { - return InterlockedIncrement((LONG volatile *)pw); } _ALWAYS_INLINE_ uint32_t _atomic_sub_impl(volatile uint32_t *pw, volatile uint32_t val) { - return InterlockedExchangeAdd((LONG volatile *)pw, -(int32_t)val) - val; } _ALWAYS_INLINE_ uint32_t _atomic_add_impl(volatile uint32_t *pw, volatile uint32_t val) { - return InterlockedAdd((LONG volatile *)pw, val); } @@ -93,22 +89,18 @@ _ALWAYS_INLINE_ uint64_t _atomic_conditional_increment_impl(volatile uint64_t *p } _ALWAYS_INLINE_ uint64_t _atomic_decrement_impl(volatile uint64_t *pw) { - return InterlockedDecrement64((LONGLONG volatile *)pw); } _ALWAYS_INLINE_ uint64_t _atomic_increment_impl(volatile uint64_t *pw) { - return InterlockedIncrement64((LONGLONG volatile *)pw); } _ALWAYS_INLINE_ uint64_t _atomic_sub_impl(volatile uint64_t *pw, volatile uint64_t val) { - return InterlockedExchangeAdd64((LONGLONG volatile *)pw, -(int64_t)val) - val; } _ALWAYS_INLINE_ uint64_t _atomic_add_impl(volatile uint64_t *pw, volatile uint64_t val) { - return InterlockedAdd64((LONGLONG volatile *)pw, val); } diff --git a/core/safe_refcount.h b/core/safe_refcount.h index 953a877397..8e23a0cf94 100644 --- a/core/safe_refcount.h +++ b/core/safe_refcount.h @@ -43,7 +43,6 @@ template <class T> static _ALWAYS_INLINE_ T atomic_conditional_increment(volatile T *pw) { - if (*pw == 0) return 0; @@ -54,7 +53,6 @@ static _ALWAYS_INLINE_ T atomic_conditional_increment(volatile T *pw) { template <class T> static _ALWAYS_INLINE_ T atomic_decrement(volatile T *pw) { - (*pw)--; return *pw; @@ -62,7 +60,6 @@ static _ALWAYS_INLINE_ T atomic_decrement(volatile T *pw) { template <class T> static _ALWAYS_INLINE_ T atomic_increment(volatile T *pw) { - (*pw)++; return *pw; @@ -70,7 +67,6 @@ static _ALWAYS_INLINE_ T atomic_increment(volatile T *pw) { template <class T, class V> static _ALWAYS_INLINE_ T atomic_sub(volatile T *pw, volatile V val) { - (*pw) -= val; return *pw; @@ -78,7 +74,6 @@ static _ALWAYS_INLINE_ T atomic_sub(volatile T *pw, volatile V val) { template <class T, class V> static _ALWAYS_INLINE_ T atomic_add(volatile T *pw, volatile V val) { - (*pw) += val; return *pw; @@ -86,7 +81,6 @@ static _ALWAYS_INLINE_ T atomic_add(volatile T *pw, volatile V val) { template <class T, class V> static _ALWAYS_INLINE_ T atomic_exchange_if_greater(volatile T *pw, volatile V val) { - if (val > *pw) *pw = val; @@ -102,7 +96,6 @@ static _ALWAYS_INLINE_ T atomic_exchange_if_greater(volatile T *pw, volatile V v template <class T> static _ALWAYS_INLINE_ T atomic_conditional_increment(volatile T *pw) { - while (true) { T tmp = static_cast<T const volatile &>(*pw); if (tmp == 0) @@ -114,31 +107,26 @@ static _ALWAYS_INLINE_ T atomic_conditional_increment(volatile T *pw) { template <class T> static _ALWAYS_INLINE_ T atomic_decrement(volatile T *pw) { - return __sync_sub_and_fetch(pw, 1); } template <class T> static _ALWAYS_INLINE_ T atomic_increment(volatile T *pw) { - return __sync_add_and_fetch(pw, 1); } template <class T, class V> static _ALWAYS_INLINE_ T atomic_sub(volatile T *pw, volatile V val) { - return __sync_sub_and_fetch(pw, val); } template <class T, class V> static _ALWAYS_INLINE_ T atomic_add(volatile T *pw, volatile V val) { - return __sync_add_and_fetch(pw, val); } template <class T, class V> static _ALWAYS_INLINE_ T atomic_exchange_if_greater(volatile T *pw, volatile V val) { - while (true) { T tmp = static_cast<T const volatile &>(*pw); if (tmp >= val) @@ -171,7 +159,6 @@ uint64_t atomic_exchange_if_greater(volatile uint64_t *pw, volatile uint64_t val #endif struct SafeRefCount { - uint32_t count; public: @@ -203,7 +190,6 @@ public: } _ALWAYS_INLINE_ void init(uint32_t p_value = 1) { - count = p_value; } }; diff --git a/core/script_language.cpp b/core/script_language.cpp index 603b4dc13d..d7287d9532 100644 --- a/core/script_language.cpp +++ b/core/script_language.cpp @@ -46,9 +46,7 @@ bool ScriptServer::languages_finished = false; ScriptEditRequestFunction ScriptServer::edit_request_func = nullptr; void Script::_notification(int p_what) { - if (p_what == NOTIFICATION_POSTINITIALIZE) { - if (EngineDebugger::is_active()) EngineDebugger::get_script_debugger()->set_break_language(get_language()); } @@ -101,7 +99,6 @@ Dictionary Script::_get_script_constant_map() { } void Script::_bind_methods() { - ClassDB::bind_method(D_METHOD("can_instance"), &Script::can_instance); //ClassDB::bind_method(D_METHOD("instance_create","base_object"),&Script::instance_create); ClassDB::bind_method(D_METHOD("instance_has", "base_object"), &Script::instance_has); @@ -126,30 +123,25 @@ void Script::_bind_methods() { } void ScriptServer::set_scripting_enabled(bool p_enabled) { - scripting_enabled = p_enabled; } bool ScriptServer::is_scripting_enabled() { - return scripting_enabled; } ScriptLanguage *ScriptServer::get_language(int p_idx) { - ERR_FAIL_INDEX_V(p_idx, _language_count, nullptr); return _languages[p_idx]; } void ScriptServer::register_language(ScriptLanguage *p_language) { - ERR_FAIL_COND(_language_count >= MAX_LANGUAGES); _languages[_language_count++] = p_language; } void ScriptServer::unregister_language(ScriptLanguage *p_language) { - for (int i = 0; i < _language_count; i++) { if (_languages[i] == p_language) { _language_count--; @@ -162,7 +154,6 @@ void ScriptServer::unregister_language(ScriptLanguage *p_language) { } void ScriptServer::init_languages() { - { //load global classes global_classes_clear(); if (ProjectSettings::get_singleton()->has_setting("_global_script_classes")) { @@ -183,7 +174,6 @@ void ScriptServer::init_languages() { } void ScriptServer::finish_languages() { - for (int i = 0; i < _language_count; i++) { _languages[i]->finish(); } @@ -192,24 +182,20 @@ void ScriptServer::finish_languages() { } void ScriptServer::set_reload_scripts_on_save(bool p_enable) { - reload_scripts_on_save = p_enable; } bool ScriptServer::is_reload_scripts_on_save_enabled() { - return reload_scripts_on_save; } void ScriptServer::thread_enter() { - for (int i = 0; i < _language_count; i++) { _languages[i]->thread_enter(); } } void ScriptServer::thread_exit() { - for (int i = 0; i < _language_count; i++) { _languages[i]->thread_exit(); } @@ -286,11 +272,9 @@ void ScriptServer::save_global_classes() { //////////////////// void ScriptInstance::get_property_state(List<Pair<StringName, Variant>> &state) { - List<PropertyInfo> pinfo; get_property_list(&pinfo); for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (E->get().usage & PROPERTY_USAGE_STORAGE) { Pair<StringName, Variant> p; p.first = E->get().name; @@ -301,7 +285,6 @@ void ScriptInstance::get_property_state(List<Pair<StringName, Variant>> &state) } Variant ScriptInstance::call(const StringName &p_method, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS; int argc = 0; for (int i = 0; i < VARIANT_ARG_MAX; i++) { @@ -336,7 +319,6 @@ Variant ScriptInstance::property_get_fallback(const StringName &, bool *r_valid) } void ScriptInstance::call_multilevel(const StringName &p_method, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS; int argc = 0; for (int i = 0; i < VARIANT_ARG_MAX; i++) { @@ -360,7 +342,6 @@ void ScriptLanguage::frame() { } bool PlaceHolderScriptInstance::set(const StringName &p_name, const Variant &p_value) { - if (script->is_placeholder_fallback_enabled()) return false; @@ -386,7 +367,6 @@ bool PlaceHolderScriptInstance::set(const StringName &p_name, const Variant &p_v return false; } bool PlaceHolderScriptInstance::get(const StringName &p_name, Variant &r_ret) const { - if (values.has(p_name)) { r_ret = values[p_name]; return true; @@ -409,7 +389,6 @@ bool PlaceHolderScriptInstance::get(const StringName &p_name, Variant &r_ret) co } void PlaceHolderScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const { - if (script->is_placeholder_fallback_enabled()) { for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { p_properties->push_back(E->get()); @@ -426,7 +405,6 @@ void PlaceHolderScriptInstance::get_property_list(List<PropertyInfo> *p_properti } Variant::Type PlaceHolderScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { - if (values.has(p_name)) { if (r_is_valid) *r_is_valid = true; @@ -446,7 +424,6 @@ Variant::Type PlaceHolderScriptInstance::get_property_type(const StringName &p_n } void PlaceHolderScriptInstance::get_method_list(List<MethodInfo> *p_list) const { - if (script->is_placeholder_fallback_enabled()) return; @@ -455,7 +432,6 @@ void PlaceHolderScriptInstance::get_method_list(List<MethodInfo> *p_list) const } } bool PlaceHolderScriptInstance::has_method(const StringName &p_method) const { - if (script->is_placeholder_fallback_enabled()) return false; @@ -466,15 +442,12 @@ bool PlaceHolderScriptInstance::has_method(const StringName &p_method) const { } void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, const Map<StringName, Variant> &p_values) { - Set<StringName> new_values; for (const List<PropertyInfo>::Element *E = p_properties.front(); E; E = E->next()) { - StringName n = E->get().name; new_values.insert(n); if (!values.has(n) || values[n].get_type() != E->get().type) { - if (p_values.has(n)) values[n] = p_values[n]; } @@ -484,7 +457,6 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c List<StringName> to_remove; for (Map<StringName, Variant>::Element *E = values.front(); E; E = E->next()) { - if (!new_values.has(E->key())) to_remove.push_back(E->key()); @@ -498,13 +470,11 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c } while (to_remove.size()) { - values.erase(to_remove.front()->get()); to_remove.pop_front(); } if (owner && owner->get_script_instance() == this) { - owner->_change_notify(); } //change notify @@ -514,7 +484,6 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c } void PlaceHolderScriptInstance::property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid) { - if (script->is_placeholder_fallback_enabled()) { Map<StringName, Variant>::Element *E = values.find(p_name); @@ -541,7 +510,6 @@ void PlaceHolderScriptInstance::property_set_fallback(const StringName &p_name, } Variant PlaceHolderScriptInstance::property_get_fallback(const StringName &p_name, bool *r_valid) { - if (script->is_placeholder_fallback_enabled()) { const Map<StringName, Variant>::Element *E = values.find(p_name); @@ -580,7 +548,6 @@ PlaceHolderScriptInstance::PlaceHolderScriptInstance(ScriptLanguage *p_language, } PlaceHolderScriptInstance::~PlaceHolderScriptInstance() { - if (script.is_valid()) { script->_placeholder_erased(this); } diff --git a/core/script_language.h b/core/script_language.h index 544de26d81..602ac42b2f 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -112,7 +112,6 @@ class ScriptInstance; class PlaceHolderScriptInstance; class Script : public Resource { - GDCLASS(Script, Resource); OBJ_SAVE_TYPE(Script); @@ -268,7 +267,6 @@ struct ScriptCodeCompletionOption { }; class ScriptCodeCompletionCache { - static ScriptCodeCompletionCache *singleton; public: @@ -406,7 +404,6 @@ public: extern uint8_t script_encryption_key[32]; class PlaceHolderScriptInstance : public ScriptInstance { - Object *owner; List<PropertyInfo> properties; Map<StringName, Variant> values; diff --git a/core/self_list.h b/core/self_list.h index 74c585e60e..c70d2a8c0a 100644 --- a/core/self_list.h +++ b/core/self_list.h @@ -38,13 +38,11 @@ template <class T> class SelfList { public: class List { - SelfList<T> *_first = nullptr; SelfList<T> *_last = nullptr; public: void add(SelfList<T> *p_elem) { - ERR_FAIL_COND(p_elem->_root); p_elem->_root = this; @@ -62,7 +60,6 @@ public: } void add_last(SelfList<T> *p_elem) { - ERR_FAIL_COND(p_elem->_root); p_elem->_root = this; @@ -80,7 +77,6 @@ public: } void remove(SelfList<T> *p_elem) { - ERR_FAIL_COND(p_elem->_root != this); if (p_elem->_next) { p_elem->_next->_prev = p_elem->_prev; diff --git a/core/set.h b/core/set.h index 851a33b43a..88eccc7ea8 100644 --- a/core/set.h +++ b/core/set.h @@ -39,7 +39,6 @@ template <class T, class C = Comparator<T>, class A = DefaultAllocator> class Set { - enum Color { RED, BLACK @@ -48,7 +47,6 @@ class Set { public: class Element { - private: friend class Set<T, C, A>; int color = RED; @@ -62,19 +60,15 @@ public: public: const Element *next() const { - return _next; } Element *next() { - return _next; } const Element *prev() const { - return _prev; } Element *prev() { - return _prev; } const T &get() const { @@ -85,7 +79,6 @@ public: private: struct _Data { - Element *_root = nullptr; Element *_nil; int size_cache = 0; @@ -101,14 +94,12 @@ private: } void _create_root() { - _root = memnew_allocator(Element, A); _root->parent = _root->left = _root->right = _nil; _root->color = BLACK; } void _free_root() { - if (_root) { memdelete_allocator<Element, A>(_root); _root = nullptr; @@ -116,7 +107,6 @@ private: } ~_Data() { - _free_root(); #ifdef GLOBALNIL_DISABLED @@ -128,13 +118,11 @@ private: _Data _data; inline void _set_color(Element *p_node, int p_color) { - 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; p_node->right = r->left; if (r->left != _data._nil) @@ -150,7 +138,6 @@ private: } inline void _rotate_right(Element *p_node) { - Element *l = p_node->left; p_node->left = l->right; if (l->right != _data._nil) @@ -166,18 +153,15 @@ private: } inline Element *_successor(Element *p_node) const { - Element *node = p_node; if (node->right != _data._nil) { - node = node->right; while (node->left != _data._nil) { /* returns the minimum of the right subtree of node */ node = node->left; } return node; } else { - while (node == node->parent->right) { node = node->parent; } @@ -192,14 +176,12 @@ private: Element *node = p_node; if (node->left != _data._nil) { - node = node->left; while (node->right != _data._nil) { /* returns the minimum of the left subtree of node */ node = node->right; } return node; } else { - while (node == node->parent->left) { node = node->parent; } @@ -211,7 +193,6 @@ private: } Element *_find(const T &p_value) const { - Element *node = _data._root->left; C less; @@ -228,7 +209,6 @@ private: } Element *_lower_bound(const T &p_value) const { - Element *node = _data._root->left; Element *prev = nullptr; C less; @@ -254,7 +234,6 @@ private: } void _insert_rb_fix(Element *p_new_node) { - Element *node = p_new_node; Element *nparent = node->parent; Element *ngrand_parent; @@ -303,13 +282,11 @@ private: } Element *_insert(const T &p_value) { - Element *new_parent = _data._root; Element *node = _data._root->left; C less; while (node != _data._nil) { - new_parent = node; if (less(p_value, node->value)) @@ -347,7 +324,6 @@ private: } void _erase_fix_rb(Element *p_node) { - Element *root = _data._root->left; Element *node = _data._nil; Element *sibling = p_node; @@ -409,7 +385,6 @@ private: } void _erase(Element *p_node) { - 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; @@ -430,7 +405,6 @@ private: } if (rp != p_node) { - ERR_FAIL_COND(rp == _data._nil); rp->left = p_node->left; @@ -460,7 +434,6 @@ private: } void _calculate_depth(Element *p_element, int &max_d, int d) const { - if (p_element == _data._nil) return; @@ -472,7 +445,6 @@ private: } void _cleanup_tree(Element *p_element) { - if (p_element == _data._nil) return; @@ -482,18 +454,15 @@ private: } void _copy_from(const Set &p_set) { - clear(); // not the fastest way, but safeset to write. for (Element *I = p_set.front(); I; I = I->next()) { - insert(I->get()); } } public: const Element *find(const T &p_value) const { - if (!_data._root) return nullptr; @@ -502,7 +471,6 @@ public: } Element *find(const T &p_value) { - if (!_data._root) return nullptr; @@ -511,24 +479,20 @@ public: } Element *lower_bound(const T &p_value) const { - return _lower_bound(p_value); } bool has(const T &p_value) const { - return find(p_value) != nullptr; } Element *insert(const T &p_value) { - if (!_data._root) _data._create_root(); return _insert(p_value); } void erase(Element *p_element) { - if (!_data._root || !p_element) return; @@ -538,7 +502,6 @@ public: } bool erase(const T &p_value) { - if (!_data._root) return false; @@ -553,7 +516,6 @@ public: } Element *front() const { - if (!_data._root) return nullptr; @@ -568,7 +530,6 @@ public: } Element *back() const { - if (!_data._root) return nullptr; @@ -596,7 +557,6 @@ public: } void clear() { - if (!_data._root) return; @@ -607,12 +567,10 @@ public: } void operator=(const Set &p_set) { - _copy_from(p_set); } Set(const Set &p_set) { - _copy_from(p_set); } diff --git a/core/simple_type.h b/core/simple_type.h index da031854c6..10dc36cbd4 100644 --- a/core/simple_type.h +++ b/core/simple_type.h @@ -35,19 +35,16 @@ template <class T> struct GetSimpleTypeT { - typedef T type_t; }; template <class T> struct GetSimpleTypeT<T &> { - typedef T type_t; }; template <class T> struct GetSimpleTypeT<T const> { - typedef T type_t; }; diff --git a/core/sort_array.h b/core/sort_array.h index 8aff0fb502..2dd7c20eae 100644 --- a/core/sort_array.h +++ b/core/sort_array.h @@ -42,7 +42,6 @@ template <class T> struct _DefaultComparator { - _FORCE_INLINE_ bool operator()(const T &a, const T &b) const { return (a < b); } }; @@ -54,7 +53,6 @@ struct _DefaultComparator { template <class T, class Comparator = _DefaultComparator<T>, bool Validate = SORT_ARRAY_VALIDATE_ENABLED> class SortArray { - enum { INTROSORT_THRESHOLD = 16 @@ -64,7 +62,6 @@ public: Comparator compare; inline const T &median_of_3(const T &a, const T &b, const T &c) const { - if (compare(a, b)) if (compare(b, c)) return b; @@ -90,10 +87,8 @@ public: /* Heap / Heapsort functions */ inline void push_heap(int p_first, int p_hole_idx, int p_top_index, T p_value, T *p_array) const { - int parent = (p_hole_idx - 1) / 2; while (p_hole_idx > p_top_index && compare(p_array[p_first + parent], p_value)) { - p_array[p_first + p_hole_idx] = p_array[p_first + parent]; p_hole_idx = parent; parent = (p_hole_idx - 1) / 2; @@ -102,22 +97,18 @@ public: } inline void pop_heap(int p_first, int p_last, int p_result, T p_value, T *p_array) const { - p_array[p_result] = p_array[p_first]; adjust_heap(p_first, 0, p_last - p_first, p_value, p_array); } inline void pop_heap(int p_first, int p_last, T *p_array) const { - pop_heap(p_first, p_last - 1, p_last - 1, p_array[p_last - 1], p_array); } inline void adjust_heap(int p_first, int p_hole_idx, int p_len, T p_value, T *p_array) const { - int top_index = p_hole_idx; int second_child = 2 * p_hole_idx + 2; while (second_child < p_len) { - if (compare(p_array[p_first + second_child], p_array[p_first + (second_child - 1)])) second_child--; @@ -134,9 +125,7 @@ public: } inline void sort_heap(int p_first, int p_last, T *p_array) const { - while (p_last - p_first > 1) { - pop_heap(p_first, p_last--, p_array); } } @@ -156,7 +145,6 @@ public: } inline void partial_sort(int p_first, int p_last, int p_middle, T *p_array) const { - make_heap(p_first, p_middle, p_array); for (int i = p_middle; i < p_last; i++) if (compare(p_array[i], p_array[p_first])) @@ -165,7 +153,6 @@ public: } inline void partial_select(int p_first, int p_last, int p_middle, T *p_array) const { - make_heap(p_first, p_middle, p_array); for (int i = p_middle; i < p_last; i++) if (compare(p_array[i], p_array[p_first])) @@ -173,7 +160,6 @@ public: } inline int partitioner(int p_first, int p_last, T p_pivot, T *p_array) const { - const int unmodified_first = p_first; const int unmodified_last = p_last; @@ -201,9 +187,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_THRESHOLD) { - if (p_max_depth == 0) { partial_sort(p_first, p_last, p_last, p_array); return; @@ -226,9 +210,7 @@ public: } inline void introselect(int p_first, int p_nth, int p_last, T *p_array, int p_max_depth) const { - while (p_last - p_first > 3) { - if (p_max_depth == 0) { partial_select(p_first, p_nth + 1, p_last, p_array); SWAP(p_first, p_nth); @@ -256,7 +238,6 @@ public: } inline void unguarded_linear_insert(int p_last, T p_value, T *p_array) const { - int next = p_last - 1; while (compare(p_value, p_array[next])) { if (Validate) { @@ -270,10 +251,8 @@ public: } inline void linear_insert(int p_first, int p_last, T *p_array) const { - T val = p_array[p_last]; if (compare(val, p_array[p_first])) { - for (int i = p_last; i > p_first; i--) p_array[i] = p_array[i - 1]; @@ -283,7 +262,6 @@ public: } inline void insertion_sort(int p_first, int p_last, T *p_array) const { - if (p_first == p_last) return; for (int i = p_first + 1; i != p_last; i++) @@ -291,24 +269,20 @@ public: } inline void unguarded_insertion_sort(int p_first, int p_last, T *p_array) const { - for (int i = p_first; i != p_last; i++) unguarded_linear_insert(i, p_array[i], p_array); } inline void final_insertion_sort(int p_first, int p_last, T *p_array) const { - 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); } } inline void sort_range(int p_first, int p_last, T *p_array) const { - if (p_first != p_last) { introsort(p_first, p_last, p_array, bitlog(p_last - p_first) * 2); final_insertion_sort(p_first, p_last, p_array); @@ -316,12 +290,10 @@ public: } inline void sort(T *p_array, int p_len) const { - sort_range(0, p_len, p_array); } inline void nth_element(int p_first, int p_last, int p_nth, T *p_array) const { - if (p_first == p_last || p_nth == p_last) return; introselect(p_first, p_nth, p_last, p_array, bitlog(p_last - p_first) * 2); diff --git a/core/string_buffer.h b/core/string_buffer.h index cfe7cdabfe..0f0b572efb 100644 --- a/core/string_buffer.h +++ b/core/string_buffer.h @@ -35,7 +35,6 @@ template <int SHORT_BUFFER_SIZE = 64> class StringBuffer { - CharType short_buffer[SHORT_BUFFER_SIZE]; String buffer; int string_length = 0; diff --git a/core/string_builder.cpp b/core/string_builder.cpp index 46c7e1c53f..6b105611f0 100644 --- a/core/string_builder.cpp +++ b/core/string_builder.cpp @@ -33,7 +33,6 @@ #include <string.h> StringBuilder &StringBuilder::append(const String &p_string) { - if (p_string == String()) return *this; @@ -46,7 +45,6 @@ StringBuilder &StringBuilder::append(const String &p_string) { } StringBuilder &StringBuilder::append(const char *p_cstring) { - int32_t len = strlen(p_cstring); c_strings.push_back(p_cstring); @@ -58,7 +56,6 @@ StringBuilder &StringBuilder::append(const char *p_cstring) { } String StringBuilder::as_string() const { - if (string_length == 0) return ""; @@ -80,7 +77,6 @@ String StringBuilder::as_string() const { godot_string_elem++; } else { - const char *s = c_strings[c_string_elem]; for (int32_t j = 0; j < appended_strings[i]; j++) { diff --git a/core/string_builder.h b/core/string_builder.h index 8fcd6669bd..2a37d14218 100644 --- a/core/string_builder.h +++ b/core/string_builder.h @@ -35,7 +35,6 @@ #include "core/vector.h" class StringBuilder { - uint32_t string_length = 0; Vector<String> strings; diff --git a/core/string_name.cpp b/core/string_name.cpp index bfc10d96e4..5e6d56e516 100644 --- a/core/string_name.cpp +++ b/core/string_name.cpp @@ -42,7 +42,6 @@ StaticCString StaticCString::create(const char *p_ptr) { StringName::_Data *StringName::_table[STRING_TABLE_LEN]; StringName _scs_create(const char *p_chr) { - return (p_chr[0] ? StringName(StaticCString::create(p_chr)) : StringName()); } @@ -50,24 +49,19 @@ bool StringName::configured = false; Mutex StringName::mutex; void StringName::setup() { - ERR_FAIL_COND(configured); for (int i = 0; i < STRING_TABLE_LEN; i++) { - _table[i] = nullptr; } configured = true; } void StringName::cleanup() { - MutexLock lock(mutex); int lost_strings = 0; for (int i = 0; i < STRING_TABLE_LEN; i++) { - while (_table[i]) { - _Data *d = _table[i]; lost_strings++; if (OS::get_singleton()->is_stdout_verbose()) { @@ -88,11 +82,9 @@ void StringName::cleanup() { } void StringName::unref() { - ERR_FAIL_COND(!configured); if (_data && _data->refcount.unref()) { - MutexLock lock(mutex); if (_data->prev) { @@ -114,9 +106,7 @@ void StringName::unref() { } bool StringName::operator==(const String &p_name) const { - if (!_data) { - return (p_name.length() == 0); } @@ -124,9 +114,7 @@ bool StringName::operator==(const String &p_name) const { } bool StringName::operator==(const char *p_name) const { - if (!_data) { - return (p_name[0] == 0); } @@ -134,32 +122,27 @@ bool StringName::operator==(const char *p_name) const { } bool StringName::operator!=(const String &p_name) const { - return !(operator==(p_name)); } bool StringName::operator!=(const StringName &p_name) const { - // the real magic of all this mess happens here. // this is why path comparisons are very fast return _data != p_name._data; } void StringName::operator=(const StringName &p_name) { - if (this == &p_name) return; unref(); if (p_name._data && p_name._data->refcount.ref()) { - _data = p_name._data; } } StringName::StringName(const StringName &p_name) { - _data = nullptr; ERR_FAIL_COND(!configured); @@ -170,7 +153,6 @@ StringName::StringName(const StringName &p_name) { } StringName::StringName(const char *p_name) { - _data = nullptr; ERR_FAIL_COND(!configured); @@ -187,7 +169,6 @@ StringName::StringName(const char *p_name) { _data = _table[idx]; while (_data) { - // compare hash first if (_data->hash == hash && _data->get_name() == p_name) break; @@ -215,7 +196,6 @@ StringName::StringName(const char *p_name) { } StringName::StringName(const StaticCString &p_static_string) { - _data = nullptr; ERR_FAIL_COND(!configured); @@ -231,7 +211,6 @@ StringName::StringName(const StaticCString &p_static_string) { _data = _table[idx]; while (_data) { - // compare hash first if (_data->hash == hash && _data->get_name() == p_static_string.ptr) break; @@ -259,7 +238,6 @@ StringName::StringName(const StaticCString &p_static_string) { } StringName::StringName(const String &p_name) { - _data = nullptr; ERR_FAIL_COND(!configured); @@ -275,7 +253,6 @@ StringName::StringName(const String &p_name) { _data = _table[idx]; while (_data) { - if (_data->hash == hash && _data->get_name() == p_name) break; _data = _data->next; @@ -302,7 +279,6 @@ StringName::StringName(const String &p_name) { } StringName StringName::search(const char *p_name) { - ERR_FAIL_COND_V(!configured, StringName()); ERR_FAIL_COND_V(!p_name, StringName()); @@ -317,7 +293,6 @@ StringName StringName::search(const char *p_name) { _Data *_data = _table[idx]; while (_data) { - // compare hash first if (_data->hash == hash && _data->get_name() == p_name) break; @@ -332,7 +307,6 @@ StringName StringName::search(const char *p_name) { } StringName StringName::search(const CharType *p_name) { - ERR_FAIL_COND_V(!configured, StringName()); ERR_FAIL_COND_V(!p_name, StringName()); @@ -348,7 +322,6 @@ StringName StringName::search(const CharType *p_name) { _Data *_data = _table[idx]; while (_data) { - // compare hash first if (_data->hash == hash && _data->get_name() == p_name) break; @@ -362,7 +335,6 @@ StringName StringName::search(const CharType *p_name) { return StringName(); //does not exist } StringName StringName::search(const String &p_name) { - ERR_FAIL_COND_V(p_name == "", StringName()); MutexLock lock(mutex); @@ -374,7 +346,6 @@ StringName StringName::search(const String &p_name) { _Data *_data = _table[idx]; while (_data) { - // compare hash first if (_data->hash == hash && p_name == _data->get_name()) break; diff --git a/core/string_name.h b/core/string_name.h index 762eb43610..0517696ab1 100644 --- a/core/string_name.h +++ b/core/string_name.h @@ -36,13 +36,11 @@ #include "core/ustring.h" struct StaticCString { - const char *ptr; static StaticCString create(const char *p_ptr); }; class StringName { - enum { STRING_TABLE_BITS = 12, @@ -68,7 +66,6 @@ class StringName { _Data *_data = nullptr; union _HashUnion { - _Data *ptr; uint32_t hash; }; @@ -91,7 +88,6 @@ public: bool operator==(const char *p_name) const; bool operator!=(const String &p_name) const; _FORCE_INLINE_ bool operator<(const StringName &p_name) const { - return _data < p_name._data; } _FORCE_INLINE_ bool operator==(const StringName &p_name) const { @@ -100,7 +96,6 @@ public: return _data == p_name._data; } _FORCE_INLINE_ uint32_t hash() const { - if (_data) return _data->hash; else @@ -112,7 +107,6 @@ public: bool operator!=(const StringName &p_name) const; _FORCE_INLINE_ operator String() const { - if (_data) { if (_data->cname) return String(_data->cname); @@ -128,20 +122,16 @@ public: static StringName search(const String &p_name); struct AlphCompare { - _FORCE_INLINE_ bool operator()(const StringName &l, const StringName &r) const { - const char *l_cname = l._data ? l._data->cname : ""; const char *r_cname = r._data ? r._data->cname : ""; if (l_cname) { - if (r_cname) return is_str_less(l_cname, r_cname); else return is_str_less(l_cname, r._data->name.ptr()); } else { - if (r_cname) return is_str_less(l._data->name.ptr(), r_cname); else diff --git a/core/thread_work_pool.cpp b/core/thread_work_pool.cpp index 28e933ac4d..3a95e83ffc 100644 --- a/core/thread_work_pool.cpp +++ b/core/thread_work_pool.cpp @@ -33,7 +33,6 @@ #include "core/os/os.h" void ThreadWorkPool::_thread_function(ThreadData *p_thread) { - while (true) { p_thread->start.wait(); if (p_thread->exit.load()) { @@ -60,7 +59,6 @@ void ThreadWorkPool::init(int p_thread_count) { } void ThreadWorkPool::finish() { - if (threads == nullptr) { return; } @@ -79,6 +77,5 @@ void ThreadWorkPool::finish() { } ThreadWorkPool::~ThreadWorkPool() { - finish(); } diff --git a/core/thread_work_pool.h b/core/thread_work_pool.h index 8005bf80b8..e21d3974ee 100644 --- a/core/thread_work_pool.h +++ b/core/thread_work_pool.h @@ -38,7 +38,6 @@ #include <thread> class ThreadWorkPool { - std::atomic<uint32_t> index; struct BaseWork { @@ -54,7 +53,6 @@ class ThreadWorkPool { M method; U userdata; virtual void work() { - while (true) { uint32_t work_index = index->fetch_add(1, std::memory_order_relaxed); if (work_index >= max_elements) { @@ -81,7 +79,6 @@ class ThreadWorkPool { public: template <class C, class M, class U> void do_work(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) { - ERR_FAIL_COND(!threads); //never initialized index.store(0); diff --git a/core/translation.cpp b/core/translation.cpp index 191349e953..a33cd48b88 100644 --- a/core/translation.cpp +++ b/core/translation.cpp @@ -795,12 +795,10 @@ static const char *locale_renames[][2] = { /////////////////////////////////////////////// Vector<String> Translation::_get_messages() const { - Vector<String> msgs; msgs.resize(translation_map.size() * 2); int idx = 0; for (const Map<StringName, StringName>::Element *E = translation_map.front(); E; E = E->next()) { - msgs.set(idx + 0, E->key()); msgs.set(idx + 1, E->get()); idx += 2; @@ -810,12 +808,10 @@ Vector<String> Translation::_get_messages() const { } Vector<String> Translation::_get_message_list() const { - Vector<String> msgs; msgs.resize(translation_map.size()); int idx = 0; for (const Map<StringName, StringName>::Element *E = translation_map.front(); E; E = E->next()) { - msgs.set(idx, E->key()); idx += 1; } @@ -824,20 +820,17 @@ Vector<String> Translation::_get_message_list() const { } void Translation::_set_messages(const Vector<String> &p_messages) { - int msg_count = p_messages.size(); ERR_FAIL_COND(msg_count % 2); const String *r = p_messages.ptr(); for (int i = 0; i < msg_count; i += 2) { - add_message(r[i + 0], r[i + 1]); } } void Translation::set_locale(const String &p_locale) { - String univ_locale = TranslationServer::standardize_locale(p_locale); if (!TranslationServer::is_locale_valid(univ_locale)) { @@ -856,11 +849,9 @@ void Translation::set_locale(const String &p_locale) { } void Translation::add_message(const StringName &p_src_text, const StringName &p_xlated_text) { - translation_map[p_src_text] = p_xlated_text; } StringName Translation::get_message(const StringName &p_src_text) const { - const Map<StringName, StringName>::Element *E = translation_map.find(p_src_text); if (!E) return StringName(); @@ -869,25 +860,20 @@ StringName Translation::get_message(const StringName &p_src_text) const { } void Translation::erase_message(const StringName &p_src_text) { - translation_map.erase(p_src_text); } void Translation::get_message_list(List<StringName> *r_messages) const { - for (const Map<StringName, StringName>::Element *E = translation_map.front(); E; E = E->next()) { - r_messages->push_back(E->key()); } } int Translation::get_message_count() const { - return translation_map.size(); }; void Translation::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_locale", "locale"), &Translation::set_locale); ClassDB::bind_method(D_METHOD("get_locale"), &Translation::get_locale); ClassDB::bind_method(D_METHOD("add_message", "src_message", "xlated_message"), &Translation::add_message); @@ -905,11 +891,9 @@ void Translation::_bind_methods() { /////////////////////////////////////////////// bool TranslationServer::is_locale_valid(const String &p_locale) { - const char **ptr = locale_list; while (*ptr) { - if (*ptr == p_locale) return true; ptr++; @@ -919,7 +903,6 @@ bool TranslationServer::is_locale_valid(const String &p_locale) { } String TranslationServer::standardize_locale(const String &p_locale) { - // Replaces '-' with '_' for macOS Sierra-style locales String univ_locale = p_locale.replace("-", "_"); @@ -937,7 +920,6 @@ String TranslationServer::standardize_locale(const String &p_locale) { } String TranslationServer::get_language_code(const String &p_locale) { - ERR_FAIL_COND_V_MSG(p_locale.length() < 2, p_locale, "Invalid locale '" + p_locale + "'."); // Most language codes are two letters, but some are three, // so we have to look for a regional code separator ('_' or '-') @@ -954,7 +936,6 @@ String TranslationServer::get_language_code(const String &p_locale) { } void TranslationServer::set_locale(const String &p_locale) { - String univ_locale = standardize_locale(p_locale); if (!is_locale_valid(univ_locale)) { @@ -979,12 +960,10 @@ void TranslationServer::set_locale(const String &p_locale) { } String TranslationServer::get_locale() const { - return locale; } String TranslationServer::get_locale_name(const String &p_locale) const { - if (!locale_name_map.has(p_locale)) return String(); return locale_name_map[p_locale]; @@ -993,7 +972,6 @@ String TranslationServer::get_locale_name(const String &p_locale) const { Array TranslationServer::get_loaded_locales() const { Array locales; for (const Set<Ref<Translation>>::Element *E = translations.front(); E; E = E->next()) { - const Ref<Translation> &t = E->get(); ERR_FAIL_COND_V(t.is_null(), Array()); String l = t->get_locale(); @@ -1005,7 +983,6 @@ Array TranslationServer::get_loaded_locales() const { } Vector<String> TranslationServer::get_all_locales() { - Vector<String> locales; const char **ptr = locale_list; @@ -1019,7 +996,6 @@ Vector<String> TranslationServer::get_all_locales() { } Vector<String> TranslationServer::get_all_locale_names() { - Vector<String> locales; const char **ptr = locale_names; @@ -1033,21 +1009,17 @@ Vector<String> TranslationServer::get_all_locale_names() { } void TranslationServer::add_translation(const Ref<Translation> &p_translation) { - translations.insert(p_translation); } void TranslationServer::remove_translation(const Ref<Translation> &p_translation) { - translations.erase(p_translation); } void TranslationServer::clear() { - translations.clear(); }; StringName TranslationServer::translate(const StringName &p_message) const { - // Match given message against the translation catalog for the project locale. if (!enabled) @@ -1141,7 +1113,6 @@ StringName TranslationServer::translate(const StringName &p_message) const { TranslationServer *TranslationServer::singleton = nullptr; bool TranslationServer::_load_translations(const String &p_from) { - if (ProjectSettings::get_singleton()->has_setting(p_from)) { Vector<String> translations = ProjectSettings::get_singleton()->get(p_from); @@ -1151,7 +1122,6 @@ bool TranslationServer::_load_translations(const String &p_from) { const String *r = translations.ptr(); for (int i = 0; i < tcount; i++) { - Ref<Translation> tr = ResourceLoader::load(r[i]); if (tr.is_valid()) add_translation(tr); @@ -1164,7 +1134,6 @@ bool TranslationServer::_load_translations(const String &p_from) { } void TranslationServer::setup() { - String test = GLOBAL_DEF("locale/test", ""); test = test.strip_edges(); if (test != "") @@ -1216,7 +1185,6 @@ StringName TranslationServer::doc_translate(const StringName &p_message) const { } void TranslationServer::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_locale", "locale"), &TranslationServer::set_locale); ClassDB::bind_method(D_METHOD("get_locale"), &TranslationServer::get_locale); @@ -1233,7 +1201,6 @@ void TranslationServer::_bind_methods() { } void TranslationServer::load_translations() { - String locale = get_locale(); _load_translations("locale/translations"); //all _load_translations("locale/translations_" + locale.substr(0, 2)); diff --git a/core/translation.h b/core/translation.h index 423b3166b1..4f50a1a4bc 100644 --- a/core/translation.h +++ b/core/translation.h @@ -34,7 +34,6 @@ #include "core/resource.h" class Translation : public Resource { - GDCLASS(Translation, Resource); OBJ_SAVE_TYPE(Translation); RES_BASE_EXTENSION("translation"); @@ -65,7 +64,6 @@ public: }; class TranslationServer : public Object { - GDCLASS(TranslationServer, Object); String locale = "en"; diff --git a/core/type_info.h b/core/type_info.h index 816d0d9381..afc0dd2107 100644 --- a/core/type_info.h +++ b/core/type_info.h @@ -35,7 +35,6 @@ template <bool C, typename T = void> struct EnableIf { - typedef T type; }; @@ -45,19 +44,16 @@ struct EnableIf<false, T> { template <typename, typename> struct TypesAreSame { - static bool const value = false; }; template <typename A> struct TypesAreSame<A, A> { - static bool const value = true; }; template <typename B, typename D> struct TypeInherits { - static D *get_d(); static char (&test(B *))[1]; diff --git a/core/typed_array.h b/core/typed_array.h index 2c7b7e0384..86f26d7550 100644 --- a/core/typed_array.h +++ b/core/typed_array.h @@ -124,23 +124,18 @@ MAKE_TYPED_ARRAY(Vector<Color>, Variant::PACKED_COLOR_ARRAY) template <class T> struct PtrToArg<TypedArray<T>> { - _FORCE_INLINE_ static TypedArray<T> convert(const void *p_ptr) { - return TypedArray<T>(*reinterpret_cast<const Array *>(p_ptr)); } _FORCE_INLINE_ static void encode(TypedArray<T> p_val, void *p_ptr) { - *(Array *)p_ptr = p_val; } }; template <class T> struct PtrToArg<const TypedArray<T> &> { - _FORCE_INLINE_ static TypedArray<T> convert(const void *p_ptr) { - return TypedArray<T>(*reinterpret_cast<const Array *>(p_ptr)); } }; diff --git a/core/ucaps.h b/core/ucaps.h index ad71731617..79b346acba 100644 --- a/core/ucaps.h +++ b/core/ucaps.h @@ -1373,7 +1373,6 @@ static const int reverse_caps_table[CAPS_LEN - 1][2] = { }; static int _find_upper(int ch) { - int low = 0; int high = CAPS_LEN - 1; int middle; @@ -1394,7 +1393,6 @@ static int _find_upper(int ch) { } static int _find_lower(int ch) { - int low = 0; int high = CAPS_LEN - 2; int middle; diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index 9324dfb573..da7c0ac248 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -33,16 +33,12 @@ #include "core/os/os.h" void UndoRedo::_discard_redo() { - if (current_action == actions.size() - 1) return; for (int i = current_action + 1; i < actions.size(); i++) { - for (List<Operation>::Element *E = actions.write[i].do_ops.front(); E; E = E->next()) { - if (E->get().type == Operation::TYPE_REFERENCE) { - Object *obj = ObjectDB::get_instance(E->get().object); if (obj) memdelete(obj); @@ -55,27 +51,21 @@ void UndoRedo::_discard_redo() { } void UndoRedo::create_action(const String &p_name, MergeMode p_mode) { - uint32_t ticks = OS::get_singleton()->get_ticks_msec(); if (action_level == 0) { - _discard_redo(); // Check if the merge operation is valid if (p_mode != MERGE_DISABLE && actions.size() && actions[actions.size() - 1].name == p_name && actions[actions.size() - 1].last_tick + 800 > ticks) { - current_action = actions.size() - 2; if (p_mode == MERGE_ENDS) { - // Clear all do ops from last action, and delete all object references List<Operation>::Element *E = actions.write[current_action + 1].do_ops.front(); while (E) { - if (E->get().type == Operation::TYPE_REFERENCE) { - Object *obj = ObjectDB::get_instance(E->get().object); if (obj) @@ -92,7 +82,6 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode) { merge_mode = p_mode; merging = true; } else { - Action new_action; new_action.name = p_name; new_action.last_tick = ticks; @@ -106,7 +95,6 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode) { } void UndoRedo::add_do_method(Object *p_object, const StringName &p_method, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS ERR_FAIL_COND(p_object == nullptr); ERR_FAIL_COND(action_level <= 0); @@ -126,7 +114,6 @@ void UndoRedo::add_do_method(Object *p_object, const StringName &p_method, VARIA } void UndoRedo::add_undo_method(Object *p_object, const StringName &p_method, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS ERR_FAIL_COND(p_object == nullptr); ERR_FAIL_COND(action_level <= 0); @@ -150,7 +137,6 @@ void UndoRedo::add_undo_method(Object *p_object, const StringName &p_method, VAR actions.write[current_action + 1].undo_ops.push_back(undo_op); } void UndoRedo::add_do_property(Object *p_object, const StringName &p_property, const Variant &p_value) { - ERR_FAIL_COND(p_object == nullptr); ERR_FAIL_COND(action_level <= 0); ERR_FAIL_COND((current_action + 1) >= actions.size()); @@ -165,7 +151,6 @@ void UndoRedo::add_do_property(Object *p_object, const StringName &p_property, c actions.write[current_action + 1].do_ops.push_back(do_op); } void UndoRedo::add_undo_property(Object *p_object, const StringName &p_property, const Variant &p_value) { - ERR_FAIL_COND(p_object == nullptr); ERR_FAIL_COND(action_level <= 0); ERR_FAIL_COND((current_action + 1) >= actions.size()); @@ -185,7 +170,6 @@ void UndoRedo::add_undo_property(Object *p_object, const StringName &p_property, actions.write[current_action + 1].undo_ops.push_back(undo_op); } void UndoRedo::add_do_reference(Object *p_object) { - ERR_FAIL_COND(p_object == nullptr); ERR_FAIL_COND(action_level <= 0); ERR_FAIL_COND((current_action + 1) >= actions.size()); @@ -198,7 +182,6 @@ void UndoRedo::add_do_reference(Object *p_object) { actions.write[current_action + 1].do_ops.push_back(do_op); } void UndoRedo::add_undo_reference(Object *p_object) { - ERR_FAIL_COND(p_object == nullptr); ERR_FAIL_COND(action_level <= 0); ERR_FAIL_COND((current_action + 1) >= actions.size()); @@ -217,16 +200,13 @@ void UndoRedo::add_undo_reference(Object *p_object) { } void UndoRedo::_pop_history_tail() { - _discard_redo(); if (!actions.size()) return; for (List<Operation>::Element *E = actions.write[0].undo_ops.front(); E; E = E->next()) { - if (E->get().type == Operation::TYPE_REFERENCE) { - Object *obj = ObjectDB::get_instance(E->get().object); if (obj) memdelete(obj); @@ -244,7 +224,6 @@ bool UndoRedo::is_committing_action() const { } void UndoRedo::commit_action() { - ERR_FAIL_COND(action_level <= 0); action_level--; if (action_level > 0) @@ -264,9 +243,7 @@ void UndoRedo::commit_action() { } void UndoRedo::_process_operation_list(List<Operation>::Element *E) { - for (; E; E = E->next()) { - Operation &op = E->get(); Object *obj = ObjectDB::get_instance(op.object); @@ -274,9 +251,7 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) { continue; switch (op.type) { - case Operation::TYPE_METHOD: { - Vector<const Variant *> argptrs; argptrs.resize(VARIANT_ARG_MAX); int argc = 0; @@ -307,7 +282,6 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) { } } break; case Operation::TYPE_PROPERTY: { - obj->set(op.name, op.args[0]); #ifdef TOOLS_ENABLED Resource *res = Object::cast_to<Resource>(obj); @@ -326,7 +300,6 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) { } bool UndoRedo::redo() { - ERR_FAIL_COND_V(action_level > 0, false); if ((current_action + 1) >= actions.size()) @@ -342,7 +315,6 @@ bool UndoRedo::redo() { } bool UndoRedo::undo() { - ERR_FAIL_COND_V(action_level > 0, false); if (current_action < 0) return false; //nothing to redo @@ -355,7 +327,6 @@ bool UndoRedo::undo() { } void UndoRedo::clear_history(bool p_increase_version) { - ERR_FAIL_COND(action_level > 0); _discard_redo(); @@ -369,7 +340,6 @@ void UndoRedo::clear_history(bool p_increase_version) { } String UndoRedo::get_current_action_name() const { - ERR_FAIL_COND_V(action_level > 0, ""); if (current_action < 0) return ""; @@ -377,45 +347,37 @@ String UndoRedo::get_current_action_name() const { } bool UndoRedo::has_undo() { - return current_action >= 0; } bool UndoRedo::has_redo() { - return (current_action + 1) < actions.size(); } uint64_t UndoRedo::get_version() const { - return version; } void UndoRedo::set_commit_notify_callback(CommitNotifyCallback p_callback, void *p_ud) { - callback = p_callback; callback_ud = p_ud; } void UndoRedo::set_method_notify_callback(MethodNotifyCallback p_method_callback, void *p_ud) { - method_callback = p_method_callback; method_callbck_ud = p_ud; } void UndoRedo::set_property_notify_callback(PropertyNotifyCallback p_property_callback, void *p_ud) { - property_callback = p_property_callback; prop_callback_ud = p_ud; } UndoRedo::~UndoRedo() { - clear_history(); } Variant UndoRedo::_add_do_method(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (p_argcount < 2) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 0; @@ -444,7 +406,6 @@ Variant UndoRedo::_add_do_method(const Variant **p_args, int p_argcount, Callabl Variant v[VARIANT_ARG_MAX]; for (int i = 0; i < MIN(VARIANT_ARG_MAX, p_argcount - 2); ++i) { - v[i] = *p_args[i + 2]; } @@ -453,7 +414,6 @@ Variant UndoRedo::_add_do_method(const Variant **p_args, int p_argcount, Callabl } Variant UndoRedo::_add_undo_method(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (p_argcount < 2) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 0; @@ -482,7 +442,6 @@ Variant UndoRedo::_add_undo_method(const Variant **p_args, int p_argcount, Calla Variant v[VARIANT_ARG_MAX]; for (int i = 0; i < MIN(VARIANT_ARG_MAX, p_argcount - 2); ++i) { - v[i] = *p_args[i + 2]; } @@ -491,7 +450,6 @@ Variant UndoRedo::_add_undo_method(const Variant **p_args, int p_argcount, Calla } void UndoRedo::_bind_methods() { - ClassDB::bind_method(D_METHOD("create_action", "name", "merge_mode"), &UndoRedo::create_action, DEFVAL(MERGE_DISABLE)); ClassDB::bind_method(D_METHOD("commit_action"), &UndoRedo::commit_action); ClassDB::bind_method(D_METHOD("is_committing_action"), &UndoRedo::is_committing_action); diff --git a/core/undo_redo.h b/core/undo_redo.h index 5b74ffcbb8..b46f7ff867 100644 --- a/core/undo_redo.h +++ b/core/undo_redo.h @@ -35,7 +35,6 @@ #include "core/resource.h" class UndoRedo : public Object { - GDCLASS(UndoRedo, Object); OBJ_SAVE_TYPE(UndoRedo); @@ -55,7 +54,6 @@ public: private: struct Operation { - enum Type { TYPE_METHOD, TYPE_PROPERTY, diff --git a/core/ustring.cpp b/core/ustring.cpp index 992424f057..249a61f3f9 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -69,13 +69,11 @@ bool is_symbol(CharType c) { } bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end) { - const String &s = p_s; int beg = CLAMP(p_col, 0, s.length()); int end = beg; if (s[beg] > 32 || beg == s.length()) { - bool symbol = beg < s.length() && is_symbol(s[beg]); while (beg > 0 && s[beg - 1] > 32 && (symbol == is_symbol(s[beg - 1]))) { @@ -93,7 +91,6 @@ bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end) { return true; } else { - return false; } } @@ -101,7 +98,6 @@ bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end) { /** STRING **/ bool CharString::operator<(const CharString &p_right) const { - if (length() == 0) { return p_right.length() != 0; } @@ -110,7 +106,6 @@ bool CharString::operator<(const CharString &p_right) const { } CharString &CharString::operator+=(char p_char) { - resize(size() ? size() + 1 : 2); set(length(), 0); set(length() - 1, p_char); @@ -119,7 +114,6 @@ CharString &CharString::operator+=(char p_char) { } const char *CharString::get_data() const { - if (size()) return &operator[](0); else @@ -127,13 +121,11 @@ const char *CharString::get_data() const { } CharString &CharString::operator=(const char *p_cstr) { - copy_from(p_cstr); return *this; } void CharString::copy_from(const char *p_cstr) { - if (!p_cstr) { resize(0); return; @@ -154,9 +146,7 @@ void CharString::copy_from(const char *p_cstr) { } void String::copy_from(const char *p_cstr) { - if (!p_cstr) { - resize(0); return; } @@ -167,7 +157,6 @@ void String::copy_from(const char *p_cstr) { len++; if (len == 0) { - resize(0); return; } @@ -177,15 +166,12 @@ void String::copy_from(const char *p_cstr) { CharType *dst = this->ptrw(); for (int i = 0; i < len + 1; i++) { - dst[i] = p_cstr[i]; } } void String::copy_from(const CharType *p_cstr, const int p_clip_to) { - if (!p_cstr) { - resize(0); return; } @@ -196,7 +182,6 @@ void String::copy_from(const CharType *p_cstr, const int p_clip_to) { len++; if (len == 0) { - resize(0); return; } @@ -220,14 +205,12 @@ void String::copy_from_unchecked(const CharType *p_char, const int p_length) { } void String::copy_from(const CharType &p_char) { - resize(2); set(0, p_char); set(1, 0); } bool String::operator==(const String &p_str) const { - if (length() != p_str.length()) return false; if (empty()) @@ -240,7 +223,6 @@ bool String::operator==(const String &p_str) const { /* Compare char by char */ for (int i = 0; i < l; i++) { - if (src[i] != dst[i]) return false; } @@ -249,12 +231,10 @@ bool String::operator==(const String &p_str) const { } bool String::operator!=(const String &p_str) const { - return !(*this == p_str); } String String::operator+(const String &p_str) const { - String res = *this; res += p_str; return res; @@ -269,7 +249,6 @@ String String::operator+(CharType p_chr) const { } */ String &String::operator+=(const String &p_str) { - if (empty()) { *this = p_str; return *this; @@ -294,13 +273,11 @@ String &String::operator+=(const String &p_str) { } String &String::operator+=(const CharType *p_str) { - *this += String(p_str); return *this; } String &String::operator+=(CharType p_char) { - resize(size() ? size() + 1 : 2); set(length(), 0); set(length() - 1, p_char); @@ -309,7 +286,6 @@ String &String::operator+=(CharType p_char) { } String &String::operator+=(const char *p_str) { - if (!p_str || p_str[0] == 0) return *this; @@ -333,17 +309,14 @@ String &String::operator+=(const char *p_str) { } void String::operator=(const char *p_str) { - copy_from(p_str); } void String::operator=(const CharType *p_str) { - copy_from(p_str); } bool String::operator==(const StrRange &p_str_range) const { - int len = p_str_range.len; if (length() != len) @@ -356,7 +329,6 @@ bool String::operator==(const StrRange &p_str_range) const { /* Compare char by char */ for (int i = 0; i < len; i++) { - if (c_str[i] != dst[i]) return false; } @@ -365,7 +337,6 @@ bool String::operator==(const StrRange &p_str_range) const { } bool String::operator==(const char *p_str) const { - int len = 0; const char *aux = p_str; @@ -383,7 +354,6 @@ bool String::operator==(const char *p_str) const { /* Compare char by char */ for (int i = 0; i < l; i++) { - if (p_str[i] != dst[i]) return false; } @@ -392,7 +362,6 @@ bool String::operator==(const char *p_str) const { } bool String::operator==(const CharType *p_str) const { - int len = 0; const CharType *aux = p_str; @@ -410,7 +379,6 @@ bool String::operator==(const CharType *p_str) const { /* Compare char by char */ for (int i = 0; i < l; i++) { - if (p_str[i] != dst[i]) return false; } @@ -419,17 +387,14 @@ bool String::operator==(const CharType *p_str) const { } bool String::operator!=(const char *p_str) const { - return (!(*this == p_str)); } bool String::operator!=(const CharType *p_str) const { - return (!(*this == p_str)); } bool String::operator<(const CharType *p_str) const { - if (empty() && p_str[0] == 0) return false; if (empty()) @@ -439,12 +404,10 @@ bool String::operator<(const CharType *p_str) const { } bool String::operator<=(const String &p_str) const { - return (*this < p_str) || (*this == p_str); } bool String::operator<(const char *p_str) const { - if (empty() && p_str[0] == 0) return false; if (empty()) @@ -454,12 +417,10 @@ bool String::operator<(const char *p_str) const { } bool String::operator<(const String &p_str) const { - return operator<(p_str.c_str()); } signed char String::nocasecmp_to(const String &p_str) const { - if (empty() && p_str.empty()) return 0; if (empty()) @@ -471,7 +432,6 @@ signed char String::nocasecmp_to(const String &p_str) const { const CharType *this_str = c_str(); while (true) { - if (*that_str == 0 && *this_str == 0) return 0; //we're equal else if (*this_str == 0) @@ -489,7 +449,6 @@ signed char String::nocasecmp_to(const String &p_str) const { } signed char String::casecmp_to(const String &p_str) const { - if (empty() && p_str.empty()) return 0; if (empty()) @@ -501,7 +460,6 @@ signed char String::casecmp_to(const String &p_str) const { const CharType *this_str = c_str(); while (true) { - if (*that_str == 0 && *this_str == 0) return 0; //we're equal else if (*this_str == 0) @@ -519,12 +477,10 @@ signed char String::casecmp_to(const String &p_str) const { } signed char String::naturalnocasecmp_to(const String &p_str) const { - const CharType *this_str = c_str(); const CharType *that_str = p_str.c_str(); if (this_str && that_str) { - while (*this_str == '.' || *that_str == '.') { if (*this_str++ != '.') return 1; @@ -537,11 +493,9 @@ signed char String::naturalnocasecmp_to(const String &p_str) const { } while (*this_str) { - if (!*that_str) return 1; else if (IS_DIGIT(*this_str)) { - int64_t this_int, that_int; if (!IS_DIGIT(*that_str)) @@ -581,19 +535,15 @@ signed char String::naturalnocasecmp_to(const String &p_str) const { } void String::erase(int p_pos, int p_chars) { - *this = left(p_pos) + substr(p_pos + p_chars, length() - ((p_pos + p_chars))); } String String::capitalize() const { - String aux = this->camelcase_to_underscore(true).replace("_", " ").strip_edges(); String cap; for (int i = 0; i < aux.get_slice_count(" "); i++) { - String slice = aux.get_slicec(' ', i); if (slice.length() > 0) { - slice[0] = _find_upper(slice[0]); if (i > 0) cap += " "; @@ -658,7 +608,6 @@ String String::get_with_code_lines() const { return ret; } int String::get_slice_count(String p_splitter) const { - if (empty()) return 0; if (p_splitter.empty()) @@ -668,7 +617,6 @@ int String::get_slice_count(String p_splitter) const { int slices = 1; while ((pos = find(p_splitter, pos)) >= 0) { - slices++; pos += p_splitter.length(); } @@ -677,7 +625,6 @@ int String::get_slice_count(String p_splitter) const { } String String::get_slice(String p_splitter, int p_slice) const { - if (empty() || p_splitter.empty()) return ""; @@ -691,7 +638,6 @@ String String::get_slice(String p_splitter, int p_slice) const { int i = 0; while (true) { - pos = find(p_splitter, pos); if (pos == -1) pos = length(); //reached end @@ -700,7 +646,6 @@ String String::get_slice(String p_splitter, int p_slice) const { //int to=pos; if (p_slice == i) { - return substr(from, pos - from); } @@ -715,7 +660,6 @@ String String::get_slice(String p_splitter, int p_slice) const { } String String::get_slicec(CharType p_splitter, int p_slice) const { - if (empty()) return String(); @@ -727,11 +671,8 @@ String String::get_slicec(CharType p_splitter, int p_slice) const { int prev = 0; int count = 0; while (true) { - if (c[i] == 0 || c[i] == p_splitter) { - if (p_slice == count) { - return substr(prev, i - prev); } else if (c[i] == 0) { return String(); @@ -746,7 +687,6 @@ String String::get_slicec(CharType p_splitter, int p_slice) const { } Vector<String> String::split_spaces() const { - Vector<String> ret; int from = 0; int i = 0; @@ -757,7 +697,6 @@ Vector<String> String::split_spaces() const { bool inside = false; while (true) { - bool empty = operator[](i) < 33; if (i == 0) @@ -769,7 +708,6 @@ Vector<String> String::split_spaces() const { } if (empty && inside) { - ret.push_back(substr(from, i - from)); inside = false; } @@ -783,13 +721,11 @@ Vector<String> String::split_spaces() const { } Vector<String> String::split(const String &p_splitter, bool p_allow_empty, int p_maxsplit) const { - Vector<String> ret; int from = 0; int len = length(); while (true) { - int end = find(p_splitter, from); if (end < 0) end = len; @@ -797,7 +733,6 @@ Vector<String> String::split(const String &p_splitter, bool p_allow_empty, int p if (p_maxsplit <= 0) ret.push_back(substr(from, end - from)); else { - // Put rest of the string and leave cycle. if (p_maxsplit == ret.size()) { ret.push_back(substr(from, len)); @@ -819,13 +754,11 @@ Vector<String> String::split(const String &p_splitter, bool p_allow_empty, int p } Vector<String> String::rsplit(const String &p_splitter, bool p_allow_empty, int p_maxsplit) const { - Vector<String> ret; const int len = length(); int remaining_len = len; while (true) { - if (remaining_len < p_splitter.length() || (p_maxsplit > 0 && p_maxsplit == ret.size())) { // no room for another splitter or hit max splits, push what's left and we're done if (p_allow_empty || remaining_len > 0) { @@ -855,13 +788,11 @@ Vector<String> String::rsplit(const String &p_splitter, bool p_allow_empty, int } Vector<float> String::split_floats(const String &p_splitter, bool p_allow_empty) const { - Vector<float> ret; int from = 0; int len = length(); while (true) { - int end = find(p_splitter, from); if (end < 0) end = len; @@ -878,13 +809,11 @@ Vector<float> String::split_floats(const String &p_splitter, bool p_allow_empty) } Vector<float> String::split_floats_mk(const Vector<String> &p_splitters, bool p_allow_empty) const { - Vector<float> ret; int from = 0; int len = length(); while (true) { - int idx; int end = findmk(p_splitters, from, &idx); int spl_len = 1; @@ -908,13 +837,11 @@ Vector<float> String::split_floats_mk(const Vector<String> &p_splitters, bool p_ } Vector<int> String::split_ints(const String &p_splitter, bool p_allow_empty) const { - Vector<int> ret; int from = 0; int len = length(); while (true) { - int end = find(p_splitter, from); if (end < 0) end = len; @@ -931,13 +858,11 @@ Vector<int> String::split_ints(const String &p_splitter, bool p_allow_empty) con } Vector<int> String::split_ints_mk(const Vector<String> &p_splitters, bool p_allow_empty) const { - Vector<int> ret; int from = 0; int len = length(); while (true) { - int idx; int end = findmk(p_splitters, from, &idx); int spl_len = 1; @@ -971,21 +896,17 @@ String String::join(Vector<String> parts) { } CharType String::char_uppercase(CharType p_char) { - return _find_upper(p_char); } CharType String::char_lowercase(CharType p_char) { - return _find_lower(p_char); } String String::to_upper() const { - String upper = *this; for (int i = 0; i < upper.size(); i++) { - const CharType s = upper[i]; const CharType t = _find_upper(s); if (s != t) // avoid copy on write @@ -996,11 +917,9 @@ String String::to_upper() const { } String String::to_lower() const { - String lower = *this; for (int i = 0; i < lower.size(); i++) { - const CharType s = lower[i]; const CharType t = _find_lower(s); if (s != t) // avoid copy on write @@ -1011,7 +930,6 @@ String String::to_lower() const { } const CharType *String::c_str() const { - static const CharType zero = 0; return size() ? &operator[](0) : &zero; @@ -1038,12 +956,10 @@ String String::hex_encode_buffer(const uint8_t *p_buffer, int p_len) { } String String::chr(CharType p_char) { - CharType c[2] = { p_char, 0 }; return String(c); } String String::num(double p_num, int p_decimals) { - #ifndef NO_USE_STDLIB if (p_decimals > 16) @@ -1054,7 +970,6 @@ String String::num(double p_num, int p_decimals) { fmt[1] = '.'; if (p_decimals < 0) { - fmt[1] = 'l'; fmt[2] = 'f'; fmt[3] = 0; @@ -1082,7 +997,6 @@ String String::num(double p_num, int p_decimals) { buf[255] = 0; //destroy trailing zeroes { - bool period = false; int z = 0; while (buf[z]) { @@ -1094,16 +1008,12 @@ String String::num(double p_num, int p_decimals) { if (period) { z--; while (z > 0) { - if (buf[z] == '0') { - buf[z] = 0; } else if (buf[z] == '.') { - buf[z] = 0; break; } else { - break; } @@ -1126,7 +1036,6 @@ String String::num(double p_num, int p_decimals) { /* decimal part */ if (p_decimals > 0 || (p_decimals == -1 && (int)p_num != p_num)) { - double dec = p_num - (float)((int)p_num); int digit = 0; @@ -1137,14 +1046,12 @@ String String::num(double p_num, int p_decimals) { int dec_max = 0; while (true) { - dec *= 10.0; dec_int = dec_int * 10 + (int)dec % 10; dec_max = dec_max * 10 + 9; digit++; if (p_decimals == -1) { - if (digit == MAX_DIGITS) //no point in going to infinite break; @@ -1160,18 +1067,15 @@ String String::num(double p_num, int p_decimals) { if (last > 5) { if (dec_int == dec_max) { - dec_int = 0; intn++; } else { - dec_int++; } } String decimal; for (int i = 0; i < digit; i++) { - char num[2] = { 0, 0 }; num[0] = '0' + dec_int % 10; decimal = num + decimal; @@ -1185,7 +1089,6 @@ String String::num(double p_num, int p_decimals) { s = "0"; else { while (intn) { - CharType num = '0' + (intn % 10); intn /= 10; s = num + s; @@ -1200,7 +1103,6 @@ String String::num(double p_num, int p_decimals) { } String String::num_int64(int64_t p_num, int base, bool capitalize_hex) { - bool sign = p_num < 0; int64_t n = p_num; @@ -1237,7 +1139,6 @@ String String::num_int64(int64_t p_num, int base, bool capitalize_hex) { } String String::num_uint64(uint64_t p_num, int base, bool capitalize_hex) { - uint64_t n = p_num; int chars = 0; @@ -1267,7 +1168,6 @@ String String::num_uint64(uint64_t p_num, int base, bool capitalize_hex) { } String String::num_real(double p_num) { - String s; String sd; /* integer part */ @@ -1279,7 +1179,6 @@ String String::num_real(double p_num) { /* decimal part */ if ((int)p_num != p_num) { - double dec = p_num - (float)((int)p_num); int digit = 0; @@ -1289,7 +1188,6 @@ String String::num_real(double p_num) { int dec_max = 0; while (true) { - dec *= 10.0; dec_int = dec_int * 10 + (int)dec % 10; dec_max = dec_max * 10 + 9; @@ -1307,18 +1205,15 @@ String String::num_real(double p_num) { if (last > 5) { if (dec_int == dec_max) { - dec_int = 0; intn++; } else { - dec_int++; } } String decimal; for (int i = 0; i < digit; i++) { - char num[2] = { 0, 0 }; num[0] = '0' + dec_int % 10; decimal = num + decimal; @@ -1334,7 +1229,6 @@ String String::num_real(double p_num) { s = "0"; else { while (intn) { - CharType num = '0' + (intn % 10); intn /= 10; s = num + s; @@ -1348,7 +1242,6 @@ String String::num_real(double p_num) { } String String::num_scientific(double p_num) { - #ifndef NO_USE_STDLIB char buf[256]; @@ -1379,7 +1272,6 @@ String String::num_scientific(double p_num) { } CharString String::ascii(bool p_allow_extended) const { - if (!length()) return CharString(); @@ -1393,7 +1285,6 @@ CharString String::ascii(bool p_allow_extended) const { } String String::utf8(const char *p_utf8, int p_len) { - String ret; ret.parse_utf8(p_utf8, p_len); @@ -1401,7 +1292,6 @@ String String::utf8(const char *p_utf8, int p_len) { }; bool String::parse_utf8(const char *p_utf8, int p_len) { - #define _UNICERROR(m_err) print_line("Unicode parsing error: " + String(m_err) + ". Is the string valid UTF-8?"); if (!p_utf8) @@ -1414,10 +1304,8 @@ bool String::parse_utf8(const char *p_utf8, int p_len) { /* HANDLE BOM (Byte Order Mark) */ if (p_len < 0 || p_len >= 3) { - bool has_bom = uint8_t(p_utf8[0]) == 0xEF && uint8_t(p_utf8[1]) == 0xBB && uint8_t(p_utf8[2]) == 0xBF; if (has_bom) { - //just skip it if (p_len >= 0) p_len -= 3; @@ -1430,9 +1318,7 @@ bool String::parse_utf8(const char *p_utf8, int p_len) { const char *ptrtmp_limit = &p_utf8[p_len]; int skip = 0; while (ptrtmp != ptrtmp_limit && *ptrtmp) { - if (skip == 0) { - uint8_t c = *ptrtmp >= 0 ? *ptrtmp : uint8_t(256 + *ptrtmp); /* Determine the number of characters in sequence */ @@ -1462,7 +1348,6 @@ bool String::parse_utf8(const char *p_utf8, int p_len) { str_size++; } else { - --skip; } @@ -1486,7 +1371,6 @@ bool String::parse_utf8(const char *p_utf8, int p_len) { dst[str_size] = 0; while (cstr_size) { - int len = 0; /* Determine the number of characters in sequence */ @@ -1526,11 +1410,9 @@ bool String::parse_utf8(const char *p_utf8, int p_len) { if (len == 1) unichar = *p_utf8; else { - unichar = (0xFF >> (len + 1)) & *p_utf8; for (int i = 1; i < len; i++) { - if ((p_utf8[i] & 0xC0) != 0x80) { _UNICERROR("invalid utf8"); return true; //invalid utf8 @@ -1557,7 +1439,6 @@ bool String::parse_utf8(const char *p_utf8, int p_len) { } CharString String::utf8() const { - int l = length(); if (!l) return CharString(); @@ -1565,7 +1446,6 @@ CharString String::utf8() const { const CharType *d = &operator[](0); int fl = 0; for (int i = 0; i < l; i++) { - uint32_t c = d[i]; if (c <= 0x7f) // 7 bits. fl += 1; @@ -1594,7 +1474,6 @@ CharString String::utf8() const { #define APPEND_CHAR(m_c) *(cdst++) = m_c for (int i = 0; i < l; i++) { - uint32_t c = d[i]; if (c <= 0x7f) // 7 bits. @@ -1646,17 +1525,14 @@ String::String(CharType p_char) { */ String::String(const char *p_str) { - copy_from(p_str); } String::String(const CharType *p_str, int p_clip_to_len) { - copy_from(p_str, p_clip_to_len); } String::String(const StrRange &p_range) { - if (!p_range.c_str) return; @@ -1664,7 +1540,6 @@ String::String(const StrRange &p_range) { } int String::hex_to_int(bool p_with_prefix) const { - if (p_with_prefix && length() < 3) return 0; @@ -1685,7 +1560,6 @@ int String::hex_to_int(bool p_with_prefix) const { int hex = 0; while (*s) { - CharType c = LOWERCASE(*s); int n; if (c >= '0' && c <= '9') { @@ -1706,7 +1580,6 @@ int String::hex_to_int(bool p_with_prefix) const { } int64_t String::hex_to_int64(bool p_with_prefix) const { - if (p_with_prefix && length() < 3) return 0; @@ -1727,7 +1600,6 @@ int64_t String::hex_to_int64(bool p_with_prefix) const { int64_t hex = 0; while (*s) { - CharType c = LOWERCASE(*s); int64_t n; if (c >= '0' && c <= '9') { @@ -1748,7 +1620,6 @@ int64_t String::hex_to_int64(bool p_with_prefix) const { } int64_t String::bin_to_int64(bool p_with_prefix) const { - if (p_with_prefix && length() < 3) return 0; @@ -1769,7 +1640,6 @@ int64_t String::bin_to_int64(bool p_with_prefix) const { int64_t binary = 0; while (*s) { - CharType c = LOWERCASE(*s); int64_t n; if (c == '0' || c == '1') { @@ -1788,7 +1658,6 @@ int64_t String::bin_to_int64(bool p_with_prefix) const { } int String::to_int() const { - if (length() == 0) return 0; @@ -1798,16 +1667,13 @@ int String::to_int() const { int sign = 1; for (int i = 0; i < to; i++) { - CharType c = operator[](i); if (c >= '0' && c <= '9') { - ERR_FAIL_COND_V_MSG(integer > INT32_MAX / 10, sign == 1 ? INT32_MAX : INT32_MIN, "Cannot represent " + *this + " as integer, provided value is " + (sign == 1 ? "too big." : "too small.")); integer *= 10; integer += c - '0'; } else if (integer == 0 && c == '-') { - sign = -sign; } } @@ -1816,7 +1682,6 @@ int String::to_int() const { } int64_t String::to_int64() const { - if (length() == 0) return 0; @@ -1826,16 +1691,13 @@ int64_t String::to_int64() const { int64_t sign = 1; for (int i = 0; i < to; i++) { - CharType c = operator[](i); if (c >= '0' && c <= '9') { - ERR_FAIL_COND_V_MSG(integer > INT64_MAX / 10, sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + *this + " as 64-bit integer, provided value is " + (sign == 1 ? "too big." : "too small.")); integer *= 10; integer += c - '0'; } else if (integer == 0 && c == '-') { - sign = -sign; } } @@ -1844,7 +1706,6 @@ int64_t String::to_int64() const { } int String::to_int(const char *p_str, int p_len) { - int to = 0; if (p_len >= 0) to = p_len; @@ -1857,16 +1718,13 @@ int String::to_int(const char *p_str, int p_len) { int sign = 1; for (int i = 0; i < to; i++) { - char c = p_str[i]; if (c >= '0' && c <= '9') { - ERR_FAIL_COND_V_MSG(integer > INT32_MAX / 10, sign == 1 ? INT32_MAX : INT32_MIN, "Cannot represent " + String(p_str).substr(0, to) + " as integer, provided value is " + (sign == 1 ? "too big." : "too small.")); integer *= 10; integer += c - '0'; } else if (c == '-' && integer == 0) { - sign = -sign; } else if (c != ' ') break; @@ -1876,7 +1734,6 @@ int String::to_int(const char *p_str, int p_len) { } bool String::is_numeric() const { - if (length() == 0) { return false; }; @@ -1886,7 +1743,6 @@ bool String::is_numeric() const { ++s; bool dot = false; for (int i = s; i < length(); i++) { - CharType c = operator[](i); if (c == '.') { if (dot) { @@ -1917,7 +1773,6 @@ static double built_in_strtod(const C *string, /* A decimal ASCII floating-point C **endPtr = nullptr) /* If non-nullptr, store terminating Cacter's * address here. */ { - static const int maxExponent = 511; /* Largest possible base 10 exponent. Any * exponent larger than this will already * produce underflow or overflow, so there's @@ -2119,7 +1974,6 @@ done: #define READING_DONE 4 double String::to_double(const char *p_str) { - #ifndef NO_USE_STDLIB return built_in_strtod<char>(p_str); //return atof(p_str); DOES NOT WORK ON ANDROID(??) @@ -2129,17 +1983,14 @@ double String::to_double(const char *p_str) { } float String::to_float() const { - return to_double(); } double String::to_double(const CharType *p_str, const CharType **r_end) { - return built_in_strtod<CharType>(p_str, (CharType **)r_end); } int64_t String::to_int(const CharType *p_str, int p_len, bool p_clamp) { - if (p_len == 0 || !p_str[0]) return 0; ///@todo make more exact so saving and loading does not lose precision @@ -2152,7 +2003,6 @@ int64_t String::to_int(const CharType *p_str, int p_len, bool p_clamp) { const CharType *limit = &p_str[p_len]; while (*str && reading != READING_DONE && str != limit) { - CharType c = *(str++); switch (reading) { case READING_SIGN: { @@ -2173,9 +2023,7 @@ int64_t String::to_int(const CharType *p_str, int p_len, bool p_clamp) { [[fallthrough]]; } case READING_INT: { - if (c >= '0' && c <= '9') { - if (integer > INT64_MAX / 10) { String number(""); str = p_str; @@ -2206,7 +2054,6 @@ int64_t String::to_int(const CharType *p_str, int p_len, bool p_clamp) { } double String::to_double() const { - if (empty()) return 0; #ifndef NO_USE_STDLIB @@ -2218,23 +2065,19 @@ double String::to_double() const { } bool operator==(const char *p_chr, const String &p_str) { - return p_str == p_chr; } String operator+(const char *p_chr, const String &p_str) { - String tmp = p_chr; tmp += p_str; return tmp; } String operator+(CharType p_chr, const String &p_str) { - return (String::chr(p_chr) + p_str); } uint32_t String::hash(const char *p_cstr) { - uint32_t hashv = 5381; uint32_t c; @@ -2245,7 +2088,6 @@ uint32_t String::hash(const char *p_cstr) { } uint32_t String::hash(const char *p_cstr, int p_len) { - uint32_t hashv = 5381; for (int i = 0; i < p_len; i++) hashv = ((hashv << 5) + hashv) + p_cstr[i]; /* hash * 33 + c */ @@ -2254,7 +2096,6 @@ uint32_t String::hash(const char *p_cstr, int p_len) { } uint32_t String::hash(const CharType *p_cstr, int p_len) { - uint32_t hashv = 5381; for (int i = 0; i < p_len; i++) hashv = ((hashv << 5) + hashv) + p_cstr[i]; /* hash * 33 + c */ @@ -2263,7 +2104,6 @@ uint32_t String::hash(const CharType *p_cstr, int p_len) { } uint32_t String::hash(const CharType *p_cstr) { - uint32_t hashv = 5381; uint32_t c; @@ -2274,7 +2114,6 @@ uint32_t String::hash(const CharType *p_cstr) { } uint32_t String::hash() const { - /* simple djb2 hashing */ const CharType *chr = c_str(); @@ -2288,7 +2127,6 @@ uint32_t String::hash() const { } uint64_t String::hash64() const { - /* simple djb2 hashing */ const CharType *chr = c_str(); @@ -2302,7 +2140,6 @@ uint64_t String::hash64() const { } String String::md5_text() const { - CharString cs = utf8(); unsigned char hash[16]; CryptoCore::md5((unsigned char *)cs.ptr(), cs.length(), hash); @@ -2324,7 +2161,6 @@ String String::sha256_text() const { } Vector<uint8_t> String::md5_buffer() const { - CharString cs = utf8(); unsigned char hash[16]; CryptoCore::md5((unsigned char *)cs.ptr(), cs.length(), hash); @@ -2365,7 +2201,6 @@ Vector<uint8_t> String::sha256_buffer() const { } String String::insert(int p_at_pos, const String &p_string) const { - if (p_at_pos < 0) return *this; @@ -2383,7 +2218,6 @@ String String::insert(int p_at_pos, const String &p_string) const { return pre + p_string + post; } String String::substr(int p_from, int p_chars) const { - if (p_chars == -1) p_chars = length() - p_from; @@ -2391,12 +2225,10 @@ String String::substr(int p_from, int p_chars) const { return ""; if ((p_from + p_chars) > length()) { - p_chars = length() - p_from; } if (p_from == 0 && p_chars >= length()) { - return String(*this); } @@ -2406,12 +2238,10 @@ String String::substr(int p_from, int p_chars) const { } int String::find_last(const String &p_str) const { - int pos = -1; int findfrom = 0; int findres = -1; while ((findres = find(p_str, findfrom)) != -1) { - pos = findres; findfrom = pos + 1; } @@ -2420,7 +2250,6 @@ int String::find_last(const String &p_str) const { } int String::find(const String &p_str, int p_from) const { - if (p_from < 0) return -1; @@ -2435,14 +2264,11 @@ int String::find(const String &p_str, int p_from) const { const CharType *str = p_str.c_str(); 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; }; @@ -2461,7 +2287,6 @@ int String::find(const String &p_str, int p_from) const { } int String::find(const char *p_str, int p_from) const { - if (p_from < 0) return -1; @@ -2477,27 +2302,21 @@ int String::find(const char *p_str, int p_from) const { 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; }; @@ -2521,7 +2340,6 @@ int String::find_char(const CharType &p_char, int p_from) const { } int String::findmk(const Vector<String> &p_keys, int p_from, int *r_key) const { - if (p_from < 0) return -1; if (p_keys.size() == 0) @@ -2538,10 +2356,8 @@ int String::findmk(const Vector<String> &p_keys, int p_from, int *r_key) const { const CharType *src = c_str(); for (int i = p_from; i < len; i++) { - bool found = true; for (int k = 0; k < key_count; k++) { - found = true; if (r_key) *r_key = k; @@ -2549,11 +2365,9 @@ int String::findmk(const Vector<String> &p_keys, int p_from, int *r_key) const { int l = keys[k].length(); for (int j = 0; j < l; j++) { - int read_pos = i + j; if (read_pos >= len) { - found = false; break; }; @@ -2575,7 +2389,6 @@ int String::findmk(const Vector<String> &p_keys, int p_from, int *r_key) const { } int String::findn(const String &p_str, int p_from) const { - if (p_from < 0) return -1; @@ -2587,14 +2400,11 @@ int String::findn(const String &p_str, int p_from) const { const CharType *srcd = c_str(); for (int i = p_from; i <= (length() - src_len); i++) { - bool found = true; for (int j = 0; j < src_len; j++) { - int read_pos = i + j; if (read_pos >= length()) { - ERR_PRINT("read_pos>=length()"); return -1; }; @@ -2616,7 +2426,6 @@ int String::findn(const 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(); if (limit < 0) @@ -2637,14 +2446,11 @@ int String::rfind(const String &p_str, int p_from) const { const CharType *src = c_str(); for (int i = p_from; i >= 0; 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; }; @@ -2662,7 +2468,6 @@ int String::rfind(const String &p_str, int p_from) const { return -1; } int String::rfindn(const String &p_str, int p_from) const { - // establish a limit int limit = length() - p_str.length(); if (limit < 0) @@ -2683,14 +2488,11 @@ int String::rfindn(const String &p_str, int p_from) const { const CharType *src = c_str(); for (int i = p_from; i >= 0; 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; }; @@ -2712,7 +2514,6 @@ int String::rfindn(const String &p_str, int p_from) const { } bool String::ends_with(const String &p_string) const { - int pos = find_last(p_string); if (pos == -1) return false; @@ -2720,7 +2521,6 @@ bool String::ends_with(const String &p_string) const { } bool String::begins_with(const String &p_string) const { - if (p_string.length() > length()) return false; @@ -2733,7 +2533,6 @@ bool String::begins_with(const String &p_string) const { int i = 0; for (; i < l; i++) { - if (src[i] != str[i]) return false; } @@ -2742,7 +2541,6 @@ bool String::begins_with(const String &p_string) const { return i == l; } bool String::begins_with(const char *p_string) const { - int l = length(); if (l == 0 || !p_string) return false; @@ -2751,7 +2549,6 @@ bool String::begins_with(const char *p_string) const { int i = 0; while (*p_string && i < l) { - if (*p_string != str[i]) return false; i++; @@ -2762,22 +2559,18 @@ bool String::begins_with(const char *p_string) const { } bool String::is_enclosed_in(const String &p_string) const { - return begins_with(p_string) && ends_with(p_string); } bool String::is_subsequence_of(const String &p_string) const { - return _base_is_subsequence_of(p_string, false); } bool String::is_subsequence_ofi(const String &p_string) const { - return _base_is_subsequence_of(p_string, true); } bool String::is_quoted() const { - return is_enclosed_in("\"") || is_enclosed_in("'"); } @@ -2827,7 +2620,6 @@ int String::countn(const String &p_string, int p_from, int p_to) const { } bool String::_base_is_subsequence_of(const String &p_string, bool case_insensitive) const { - int len = length(); if (len == 0) { // Technically an empty string is subsequence of any string @@ -2920,7 +2712,6 @@ static bool _wildcard_match(const CharType *p_pattern, const CharType *p_string, } bool String::match(const String &p_wildcard) const { - if (!p_wildcard.length() || !length()) return false; @@ -2928,14 +2719,12 @@ bool String::match(const String &p_wildcard) const { } bool String::matchn(const String &p_wildcard) const { - if (!p_wildcard.length() || !length()) return false; return _wildcard_match(p_wildcard.c_str(), c_str(), false); } String String::format(const Variant &values, String placeholder) const { - String new_string = String(this->ptr()); if (values.get_type() == Variant::ARRAY) { @@ -3007,20 +2796,17 @@ String String::format(const Variant &values, String placeholder) const { } String String::replace(const String &p_key, const String &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; search_from = result + p_key.length(); } if (search_from == 0) { - return *this; } @@ -3030,13 +2816,11 @@ String String::replace(const String &p_key, const 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; @@ -3046,7 +2830,6 @@ String String::replace(const char *p_key, const char *p_with) const { } if (search_from == 0) { - return *this; } @@ -3056,7 +2839,6 @@ String String::replace(const char *p_key, const char *p_with) const { } String String::replace_first(const String &p_key, const String &p_with) const { - int pos = find(p_key); if (pos >= 0) { return substr(0, pos) + p_with + substr(pos + p_key.length(), length()); @@ -3065,20 +2847,17 @@ String String::replace_first(const String &p_key, const String &p_with) const { return *this; } String String::replacen(const String &p_key, const String &p_with) const { - String new_string; int search_from = 0; int result = 0; while ((result = findn(p_key, search_from)) >= 0) { - new_string += substr(search_from, result - search_from); new_string += p_with; search_from = result + p_key.length(); } if (search_from == 0) { - return *this; } @@ -3087,7 +2866,6 @@ String String::replacen(const String &p_key, const String &p_with) const { } String String::repeat(int p_count) const { - ERR_FAIL_COND_V_MSG(p_count < 0, "", "Parameter count should be a positive number."); String new_string; @@ -3103,7 +2881,6 @@ String String::repeat(int p_count) const { } String String::left(int p_pos) const { - if (p_pos <= 0) return ""; @@ -3114,7 +2891,6 @@ String String::left(int p_pos) const { } String String::right(int p_pos) const { - if (p_pos >= length()) return ""; @@ -3125,13 +2901,11 @@ String String::right(int p_pos) const { } CharType String::ord_at(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, length(), 0); return operator[](p_idx); } String String::dedent() const { - String new_string; String indent; bool has_indent = false; @@ -3140,7 +2914,6 @@ String String::dedent() const { int indent_stop = -1; for (int i = 0; i < length(); i++) { - CharType c = operator[](i); if (c == '\n') { if (has_text) @@ -3173,13 +2946,11 @@ String String::dedent() const { } String String::strip_edges(bool left, bool right) const { - int len = length(); int beg = 0, end = len; if (left) { for (int i = 0; i < len; i++) { - if (operator[](i) <= 32) beg++; else @@ -3189,7 +2960,6 @@ String String::strip_edges(bool left, bool right) const { if (right) { for (int i = (int)(len - 1); i >= 0; i--) { - if (operator[](i) <= 32) end--; else @@ -3204,10 +2974,8 @@ String String::strip_edges(bool left, bool right) const { } String String::strip_escapes() const { - String new_string; for (int i = 0; i < length(); i++) { - // Escape characters on first page of the ASCII table, before 32 (Space). if (operator[](i) < 32) continue; @@ -3218,12 +2986,10 @@ String String::strip_escapes() const { } String String::lstrip(const String &p_chars) const { - int len = length(); int beg; for (beg = 0; beg < len; beg++) { - if (p_chars.find_char(get(beg)) == -1) break; } @@ -3235,12 +3001,10 @@ String String::lstrip(const String &p_chars) const { } String String::rstrip(const String &p_chars) const { - int len = length(); int end; for (end = len - 1; end >= 0; end--) { - if (p_chars.find_char(get(end)) == -1) break; } @@ -3252,31 +3016,25 @@ String String::rstrip(const String &p_chars) const { } String String::simplify_path() const { - String s = *this; String drive; if (s.begins_with("local://")) { drive = "local://"; s = s.substr(8, s.length()); } else if (s.begins_with("res://")) { - drive = "res://"; s = s.substr(6, s.length()); } else if (s.begins_with("user://")) { - drive = "user://"; s = s.substr(7, s.length()); } else if (s.begins_with("/") || s.begins_with("\\")) { - drive = s.substr(0, 1); s = s.substr(1, s.length() - 1); } else { - int p = s.find(":/"); if (p == -1) p = s.find(":\\"); if (p != -1 && p < s.find("/")) { - drive = s.substr(0, p + 2); s = s.substr(p + 2, s.length()); } @@ -3293,13 +3051,11 @@ String String::simplify_path() const { Vector<String> dirs = s.split("/", false); for (int i = 0; i < dirs.size(); i++) { - String d = dirs[i]; if (d == ".") { dirs.remove(i); i--; } else if (d == "..") { - if (i == 0) { dirs.remove(i); i--; @@ -3314,7 +3070,6 @@ String String::simplify_path() const { s = ""; for (int i = 0; i < dirs.size(); i++) { - if (i > 0) s += "/"; s += dirs[i]; @@ -3324,7 +3079,6 @@ String String::simplify_path() const { } static int _humanize_digits(int p_num) { - if (p_num < 100) return 2; else if (p_num < 1024) @@ -3334,7 +3088,6 @@ static int _humanize_digits(int p_num) { } String String::humanize_size(uint64_t p_size) { - uint64_t _div = 1; Vector<String> prefixes; prefixes.push_back(RTR("B")); @@ -3358,7 +3111,6 @@ String String::humanize_size(uint64_t p_size) { return String::num(p_size / divisor).pad_decimals(digits) + " " + prefixes[prefix_idx]; } bool String::is_abs_path() const { - if (length() > 1) return (operator[](0) == '/' || operator[](0) == '\\' || find(":/") != -1 || find(":\\") != -1); else if ((length()) == 1) @@ -3368,7 +3120,6 @@ bool String::is_abs_path() const { } bool String::is_valid_identifier() const { - int len = length(); if (len == 0) @@ -3377,7 +3128,6 @@ bool String::is_valid_identifier() const { const wchar_t *str = &operator[](0); for (int i = 0; i < len; i++) { - if (i == 0) { if (str[0] >= '0' && str[0] <= '9') return false; // no start with number plz @@ -3395,7 +3145,6 @@ bool String::is_valid_identifier() const { //kind of poor should be rewritten properly String String::word_wrap(int p_chars_per_line) const { - int from = 0; int last_space = 0; String ret; @@ -3472,7 +3221,6 @@ String String::http_unescape() const { } String String::c_unescape() const { - String escaped = *this; escaped = escaped.replace("\\a", "\a"); escaped = escaped.replace("\\b", "\b"); @@ -3490,7 +3238,6 @@ String String::c_unescape() const { } String String::c_escape() const { - String escaped = *this; escaped = escaped.replace("\\", "\\\\"); escaped = escaped.replace("\a", "\\a"); @@ -3508,7 +3255,6 @@ String String::c_escape() const { } String String::c_escape_multiline() const { - String escaped = *this; escaped = escaped.replace("\\", "\\\\"); escaped = escaped.replace("\"", "\\\""); @@ -3517,7 +3263,6 @@ String String::c_escape_multiline() const { } String String::json_escape() const { - String escaped = *this; escaped = escaped.replace("\\", "\\\\"); escaped = escaped.replace("\b", "\\b"); @@ -3532,7 +3277,6 @@ String String::json_escape() const { } String String::xml_escape(bool p_escape_quotes) const { - String str = *this; str = str.replace("&", "&"); str = str.replace("<", "<"); @@ -3551,20 +3295,15 @@ String String::xml_escape(bool p_escape_quotes) const { } static _FORCE_INLINE_ int _xml_unescape(const CharType *p_src, int p_src_len, CharType *p_dst) { - int len = 0; while (p_src_len) { - if (*p_src == '&') { - int eat = 0; if (p_src_len >= 4 && p_src[1] == '#') { - CharType c = 0; for (int i = 2; i < p_src_len; i++) { - eat = i + 1; CharType ct = p_src[i]; if (ct == ';') { @@ -3586,32 +3325,26 @@ static _FORCE_INLINE_ int _xml_unescape(const CharType *p_src, int p_src_len, Ch *p_dst = c; } else if (p_src_len >= 4 && p_src[1] == 'g' && p_src[2] == 't' && p_src[3] == ';') { - if (p_dst) *p_dst = '>'; eat = 4; } else if (p_src_len >= 4 && p_src[1] == 'l' && p_src[2] == 't' && p_src[3] == ';') { - if (p_dst) *p_dst = '<'; eat = 4; } else if (p_src_len >= 5 && p_src[1] == 'a' && p_src[2] == 'm' && p_src[3] == 'p' && p_src[4] == ';') { - if (p_dst) *p_dst = '&'; eat = 5; } else if (p_src_len >= 6 && p_src[1] == 'q' && p_src[2] == 'u' && p_src[3] == 'o' && p_src[4] == 't' && p_src[5] == ';') { - if (p_dst) *p_dst = '"'; eat = 6; } else if (p_src_len >= 6 && p_src[1] == 'a' && p_src[2] == 'p' && p_src[3] == 'o' && p_src[4] == 's' && p_src[5] == ';') { - if (p_dst) *p_dst = '\''; eat = 6; } else { - if (p_dst) *p_dst = *p_src; eat = 1; @@ -3624,7 +3357,6 @@ static _FORCE_INLINE_ int _xml_unescape(const CharType *p_src, int p_src_len, Ch p_src += eat; p_src_len -= eat; } else { - if (p_dst) { *p_dst = *p_src; p_dst++; @@ -3639,7 +3371,6 @@ static _FORCE_INLINE_ int _xml_unescape(const CharType *p_src, int p_src_len, Ch } String String::xml_unescape() const { - String str; int l = length(); int len = _xml_unescape(c_str(), l, nullptr); @@ -3652,7 +3383,6 @@ String String::xml_unescape() const { } String String::pad_decimals(int p_digits) const { - String s = *this; int c = s.find("."); @@ -3679,7 +3409,6 @@ String String::pad_decimals(int p_digits) const { } String String::pad_zeros(int p_digits) const { - String s = *this; int end = s.find("."); @@ -3700,7 +3429,6 @@ String String::pad_zeros(int p_digits) const { return s; while (end - begin < p_digits) { - s = s.insert(begin, "0"); end++; } @@ -3709,7 +3437,6 @@ String String::pad_zeros(int p_digits) const { } String String::trim_prefix(const String &p_prefix) const { - String s = *this; if (s.begins_with(p_prefix)) { return s.substr(p_prefix.length(), s.length() - p_prefix.length()); @@ -3718,7 +3445,6 @@ String String::trim_prefix(const String &p_prefix) const { } String String::trim_suffix(const String &p_suffix) const { - String s = *this; if (s.ends_with(p_suffix)) { return s.substr(0, s.length() - p_suffix.length()); @@ -3727,7 +3453,6 @@ String String::trim_suffix(const String &p_suffix) const { } bool String::is_valid_integer() const { - int len = length(); if (len == 0) @@ -3738,7 +3463,6 @@ bool String::is_valid_integer() const { from++; for (int i = from; i < len; i++) { - if (operator[](i) < '0' || operator[](i) > '9') return false; // no start with number plz } @@ -3747,7 +3471,6 @@ bool String::is_valid_integer() const { } bool String::is_valid_hex_number(bool p_with_prefix) const { - int len = length(); if (len == 0) @@ -3758,7 +3481,6 @@ bool String::is_valid_hex_number(bool p_with_prefix) const { from++; if (p_with_prefix) { - if (len < 3) return false; if (operator[](from) != '0' || operator[](from + 1) != 'x') { @@ -3768,7 +3490,6 @@ bool String::is_valid_hex_number(bool p_with_prefix) const { } for (int i = from; i < len; i++) { - CharType c = operator[](i); if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) continue; @@ -3779,7 +3500,6 @@ bool String::is_valid_hex_number(bool p_with_prefix) const { }; bool String::is_valid_float() const { - int len = length(); if (len == 0) @@ -3797,9 +3517,7 @@ bool String::is_valid_float() const { bool numbers_found = false; for (int i = from; i < len; i++) { - if (operator[](i) >= '0' && operator[](i) <= '9') { - if (exponent_found) exponent_values_found = true; else @@ -3818,7 +3536,6 @@ bool String::is_valid_float() const { } String String::path_to_file(const String &p_path) const { - // Don't get base dir for src, this is expected to be a dir already. String src = this->replace("\\", "/"); String dst = p_path.replace("\\", "/").get_base_dir(); @@ -3830,7 +3547,6 @@ String String::path_to_file(const String &p_path) const { } String String::path_to(const String &p_path) const { - String src = this->replace("\\", "/"); String dst = p_path.replace("\\", "/"); if (!src.ends_with("/")) @@ -3841,19 +3557,16 @@ String String::path_to(const String &p_path) const { String base; if (src.begins_with("res://") && dst.begins_with("res://")) { - base = "res:/"; src = src.replace("res://", "/"); dst = dst.replace("res://", "/"); } else if (src.begins_with("user://") && dst.begins_with("user://")) { - base = "user:/"; src = src.replace("user://", "/"); dst = dst.replace("user://", "/"); } else if (src.begins_with("/") && dst.begins_with("/")) { - //nothing } else { //dos style @@ -3890,12 +3603,10 @@ String String::path_to(const String &p_path) const { String dir; for (int i = src_dirs.size() - 1; i > common_parent; i--) { - dir += "../"; } for (int i = common_parent + 1; i < dst_dirs.size(); i++) { - dir += dst_dirs[i] + "/"; } @@ -3905,12 +3616,10 @@ String String::path_to(const String &p_path) const { } bool String::is_valid_html_color() const { - return Color::html_is_valid(*this); } bool String::is_valid_filename() const { - String stripped = strip_edges(); if (*this != stripped) { return false; @@ -3924,12 +3633,9 @@ bool String::is_valid_filename() const { } bool String::is_valid_ip_address() const { - if (find(":") >= 0) { - Vector<String> ip = split(":"); for (int i = 0; i < ip.size(); i++) { - String n = ip[i]; if (n.empty()) continue; @@ -3948,7 +3654,6 @@ bool String::is_valid_ip_address() const { if (ip.size() != 4) return false; for (int i = 0; i < ip.size(); i++) { - String n = ip[i]; if (!n.is_valid_integer()) return false; @@ -3962,17 +3667,14 @@ bool String::is_valid_ip_address() const { } bool String::is_resource_file() const { - return begins_with("res://") && find("::") == -1; } bool String::is_rel_path() const { - return !is_abs_path(); } String String::get_base_dir() const { - int basepos = find("://"); String rs; String base; @@ -3985,7 +3687,6 @@ String String::get_base_dir() const { rs = substr(1, length()); base = "/"; } else { - rs = *this; } } @@ -3998,7 +3699,6 @@ String String::get_base_dir() const { } String String::get_file() const { - int sep = MAX(find_last("/"), find_last("\\")); if (sep == -1) return *this; @@ -4007,7 +3707,6 @@ String String::get_file() const { } String String::get_extension() const { - int pos = find_last("."); if (pos < 0 || pos < MAX(find_last("/"), find_last("\\"))) return ""; @@ -4024,13 +3723,11 @@ String String::plus_file(const String &p_file) const { } String String::percent_encode() const { - CharString cs = utf8(); String encoded; for (int i = 0; i < cs.length(); i++) { uint8_t c = cs[i]; if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '-' || c == '_' || c == '~' || c == '.') { - char p[2] = { (char)c, 0 }; encoded += p; } else { @@ -4046,15 +3743,12 @@ String String::percent_encode() const { return encoded; } String String::percent_decode() const { - CharString pe; CharString cs = utf8(); for (int i = 0; i < cs.length(); i++) { - uint8_t c = cs[i]; if (c == '%' && i < length() - 2) { - uint8_t a = LOWERCASE(cs[i + 1]); uint8_t b = LOWERCASE(cs[i + 2]); @@ -4096,7 +3790,6 @@ String String::property_name_encode() const { } String String::get_basename() const { - int pos = find_last("."); if (pos < 0 || pos < MAX(find_last("/"), find_last("\\"))) return *this; @@ -4105,22 +3798,18 @@ String String::get_basename() const { } String itos(int64_t p_val) { - return String::num_int64(p_val); } String uitos(uint64_t p_val) { - return String::num_uint64(p_val); } String rtos(double p_val) { - return String::num(p_val); } String rtoss(double p_val) { - return String::num_scientific(p_val); } diff --git a/core/ustring.h b/core/ustring.h index 15bc2b323c..34f9c18bad 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -71,7 +71,6 @@ public: }; class CharString { - CowData<char> _cowdata; static const char _null; @@ -113,7 +112,6 @@ protected: typedef wchar_t CharType; struct StrRange { - const CharType *c_str; int len; @@ -124,7 +122,6 @@ struct StrRange { }; class String { - CowData<CharType> _cowdata; static const CharType _null; @@ -377,26 +374,20 @@ String rtos(double p_val); String rtoss(double p_val); //scientific version struct NoCaseComparator { - bool operator()(const String &p_a, const String &p_b) const { - return p_a.nocasecmp_to(p_b) < 0; } }; struct NaturalNoCaseComparator { - bool operator()(const String &p_a, const String &p_b) const { - return p_a.naturalnocasecmp_to(p_b) < 0; } }; template <typename L, typename R> _FORCE_INLINE_ bool is_str_less(const L *l_ptr, const R *r_ptr) { - while (true) { - if (*l_ptr == 0 && *r_ptr == 0) return false; else if (*l_ptr == 0) diff --git a/core/variant.cpp b/core/variant.cpp index 162d409026..b2bb7fe309 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -41,172 +41,136 @@ #include "scene/main/node.h" String Variant::get_type_name(Variant::Type p_type) { - switch (p_type) { case NIL: { - return "Nil"; } break; // atomic types case BOOL: { - return "bool"; } break; case INT: { - return "int"; } break; case FLOAT: { - return "float"; } break; case STRING: { - return "String"; } break; // math types case VECTOR2: { - return "Vector2"; } break; case VECTOR2I: { - return "Vector2i"; } break; case RECT2: { - return "Rect2"; } break; case RECT2I: { - return "Rect2i"; } break; case TRANSFORM2D: { - return "Transform2D"; } break; case VECTOR3: { - return "Vector3"; } break; case VECTOR3I: { - return "Vector3i"; } break; case PLANE: { - return "Plane"; } break; case AABB: { - return "AABB"; } break; case QUAT: { - return "Quat"; } break; case BASIS: { - return "Basis"; } break; case TRANSFORM: { - return "Transform"; } break; // misc types case COLOR: { - return "Color"; } break; case _RID: { - return "RID"; } break; case OBJECT: { - return "Object"; } break; case CALLABLE: { - return "Callable"; } break; case SIGNAL: { - return "Signal"; } break; case STRING_NAME: { - return "StringName"; } break; case NODE_PATH: { - return "NodePath"; } break; case DICTIONARY: { - return "Dictionary"; } break; case ARRAY: { - return "Array"; } break; // arrays case PACKED_BYTE_ARRAY: { - return "PackedByteArray"; } break; case PACKED_INT32_ARRAY: { - return "PackedInt32Array"; } break; case PACKED_INT64_ARRAY: { - return "PackedInt64Array"; } break; case PACKED_FLOAT32_ARRAY: { - return "PackedFloat32Array"; } break; case PACKED_FLOAT64_ARRAY: { - return "PackedFloat64Array"; } break; case PACKED_STRING_ARRAY: { - return "PackedStringArray"; } break; case PACKED_VECTOR2_ARRAY: { - return "PackedVector2Array"; } break; case PACKED_VECTOR3_ARRAY: { - return "PackedVector3Array"; } break; case PACKED_COLOR_ARRAY: { - return "PackedColorArray"; } break; @@ -218,7 +182,6 @@ String Variant::get_type_name(Variant::Type p_type) { } bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { - if (p_type_from == p_type_to) return true; if (p_type_to == NIL && p_type_from != NIL) //nil can convert to anything @@ -233,7 +196,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { switch (p_type_to) { case BOOL: { - static const Type valid[] = { INT, FLOAT, @@ -244,7 +206,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { valid_types = valid; } break; case INT: { - static const Type valid[] = { BOOL, FLOAT, @@ -256,7 +217,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } break; case FLOAT: { - static const Type valid[] = { BOOL, INT, @@ -268,7 +228,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } break; case STRING: { - static const Type invalid[] = { OBJECT, NIL @@ -277,7 +236,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { invalid_types = invalid; } break; case VECTOR2: { - static const Type valid[] = { VECTOR2I, NIL, @@ -287,7 +245,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } break; case VECTOR2I: { - static const Type valid[] = { VECTOR2, NIL, @@ -297,7 +254,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } break; case RECT2: { - static const Type valid[] = { RECT2I, NIL, @@ -307,7 +263,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } break; case RECT2I: { - static const Type valid[] = { RECT2, NIL, @@ -317,7 +272,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } break; case TRANSFORM2D: { - static const Type valid[] = { TRANSFORM, NIL @@ -326,7 +280,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { valid_types = valid; } break; case VECTOR3: { - static const Type valid[] = { VECTOR3I, NIL, @@ -336,7 +289,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } break; case VECTOR3I: { - static const Type valid[] = { VECTOR3, NIL, @@ -347,7 +299,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } break; case QUAT: { - static const Type valid[] = { BASIS, NIL @@ -357,7 +308,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } break; case BASIS: { - static const Type valid[] = { QUAT, VECTOR3, @@ -368,7 +318,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } break; case TRANSFORM: { - static const Type valid[] = { TRANSFORM2D, QUAT, @@ -381,7 +330,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } break; case COLOR: { - static const Type valid[] = { STRING, INT, @@ -393,7 +341,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } break; case _RID: { - static const Type valid[] = { OBJECT, NIL @@ -402,7 +349,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { valid_types = valid; } break; case OBJECT: { - static const Type valid[] = { NIL }; @@ -410,7 +356,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { valid_types = valid; } break; case STRING_NAME: { - static const Type valid[] = { STRING, NIL @@ -419,7 +364,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { valid_types = valid; } break; case NODE_PATH: { - static const Type valid[] = { STRING, NIL @@ -428,7 +372,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { valid_types = valid; } break; case ARRAY: { - static const Type valid[] = { PACKED_BYTE_ARRAY, PACKED_INT32_ARRAY, @@ -446,7 +389,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } break; // arrays case PACKED_BYTE_ARRAY: { - static const Type valid[] = { ARRAY, NIL @@ -455,7 +397,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { valid_types = valid; } break; case PACKED_INT32_ARRAY: { - static const Type valid[] = { ARRAY, NIL @@ -463,7 +404,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { valid_types = valid; } break; case PACKED_INT64_ARRAY: { - static const Type valid[] = { ARRAY, NIL @@ -471,7 +411,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { valid_types = valid; } break; case PACKED_FLOAT32_ARRAY: { - static const Type valid[] = { ARRAY, NIL @@ -480,7 +419,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { valid_types = valid; } break; case PACKED_FLOAT64_ARRAY: { - static const Type valid[] = { ARRAY, NIL @@ -489,7 +427,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { valid_types = valid; } break; case PACKED_STRING_ARRAY: { - static const Type valid[] = { ARRAY, NIL @@ -497,7 +434,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { valid_types = valid; } break; case PACKED_VECTOR2_ARRAY: { - static const Type valid[] = { ARRAY, NIL @@ -506,7 +442,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } break; case PACKED_VECTOR3_ARRAY: { - static const Type valid[] = { ARRAY, NIL @@ -515,7 +450,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } break; case PACKED_COLOR_ARRAY: { - static const Type valid[] = { ARRAY, NIL @@ -529,20 +463,16 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } if (valid_types) { - int i = 0; while (valid_types[i] != NIL) { - if (p_type_from == valid_types[i]) return true; i++; } } else if (invalid_types) { - int i = 0; while (invalid_types[i] != NIL) { - if (p_type_from == invalid_types[i]) return false; i++; @@ -555,7 +485,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type_to) { - if (p_type_from == p_type_to) return true; if (p_type_to == NIL && p_type_from != NIL) //nil can convert to anything @@ -569,7 +498,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type switch (p_type_to) { case BOOL: { - static const Type valid[] = { INT, FLOAT, @@ -580,7 +508,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; case INT: { - static const Type valid[] = { BOOL, FLOAT, @@ -592,7 +519,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } break; case FLOAT: { - static const Type valid[] = { BOOL, INT, @@ -604,7 +530,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } break; case STRING: { - static const Type valid[] = { NODE_PATH, STRING_NAME, @@ -614,7 +539,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; case VECTOR2: { - static const Type valid[] = { VECTOR2I, NIL, @@ -624,7 +548,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } break; case VECTOR2I: { - static const Type valid[] = { VECTOR2, NIL, @@ -634,7 +557,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } break; case RECT2: { - static const Type valid[] = { RECT2I, NIL, @@ -644,7 +566,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } break; case RECT2I: { - static const Type valid[] = { RECT2, NIL, @@ -654,7 +575,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } break; case TRANSFORM2D: { - static const Type valid[] = { TRANSFORM, NIL @@ -663,7 +583,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; case VECTOR3: { - static const Type valid[] = { VECTOR3I, NIL, @@ -673,7 +592,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } break; case VECTOR3I: { - static const Type valid[] = { VECTOR3, NIL, @@ -684,7 +602,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } break; case QUAT: { - static const Type valid[] = { BASIS, NIL @@ -694,7 +611,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } break; case BASIS: { - static const Type valid[] = { QUAT, VECTOR3, @@ -705,7 +621,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } break; case TRANSFORM: { - static const Type valid[] = { TRANSFORM2D, QUAT, @@ -718,7 +633,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } break; case COLOR: { - static const Type valid[] = { STRING, INT, @@ -730,7 +644,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } break; case _RID: { - static const Type valid[] = { OBJECT, NIL @@ -739,7 +652,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; case OBJECT: { - static const Type valid[] = { NIL }; @@ -747,7 +659,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; case STRING_NAME: { - static const Type valid[] = { STRING, NIL @@ -756,7 +667,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; case NODE_PATH: { - static const Type valid[] = { STRING, NIL @@ -765,7 +675,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; case ARRAY: { - static const Type valid[] = { PACKED_BYTE_ARRAY, PACKED_INT32_ARRAY, @@ -783,7 +692,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } break; // arrays case PACKED_BYTE_ARRAY: { - static const Type valid[] = { ARRAY, NIL @@ -792,7 +700,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; case PACKED_INT32_ARRAY: { - static const Type valid[] = { ARRAY, NIL @@ -800,7 +707,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; case PACKED_INT64_ARRAY: { - static const Type valid[] = { ARRAY, NIL @@ -808,7 +714,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; case PACKED_FLOAT32_ARRAY: { - static const Type valid[] = { ARRAY, NIL @@ -817,7 +722,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; case PACKED_FLOAT64_ARRAY: { - static const Type valid[] = { ARRAY, NIL @@ -826,7 +730,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; case PACKED_STRING_ARRAY: { - static const Type valid[] = { ARRAY, NIL @@ -834,7 +737,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; case PACKED_VECTOR2_ARRAY: { - static const Type valid[] = { ARRAY, NIL @@ -843,7 +745,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } break; case PACKED_VECTOR3_ARRAY: { - static const Type valid[] = { ARRAY, NIL @@ -852,7 +753,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } break; case PACKED_COLOR_ARRAY: { - static const Type valid[] = { ARRAY, NIL @@ -866,10 +766,8 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } if (valid_types) { - int i = 0; while (valid_types[i] != NIL) { - if (p_type_from == valid_types[i]) return true; i++; @@ -880,7 +778,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } bool Variant::operator==(const Variant &p_variant) const { - if (type != p_variant.type) //evaluation of operator== needs to be more strict return false; bool v; @@ -890,7 +787,6 @@ bool Variant::operator==(const Variant &p_variant) const { } bool Variant::operator!=(const Variant &p_variant) const { - if (type != p_variant.type) //evaluation of operator== needs to be more strict return true; bool v; @@ -909,72 +805,58 @@ bool Variant::operator<(const Variant &p_variant) const { } bool Variant::is_zero() const { - switch (type) { case NIL: { - return true; } break; // atomic types case BOOL: { - return !(_data._bool); } break; case INT: { - return _data._int == 0; } break; case FLOAT: { - return _data._float == 0; } break; case STRING: { - return *reinterpret_cast<const String *>(_data._mem) == String(); } break; // math types case VECTOR2: { - return *reinterpret_cast<const Vector2 *>(_data._mem) == Vector2(); } break; case VECTOR2I: { - return *reinterpret_cast<const Vector2i *>(_data._mem) == Vector2i(); } break; case RECT2: { - return *reinterpret_cast<const Rect2 *>(_data._mem) == Rect2(); } break; case RECT2I: { - return *reinterpret_cast<const Rect2i *>(_data._mem) == Rect2i(); } break; case TRANSFORM2D: { - return *_data._transform2d == Transform2D(); } break; case VECTOR3: { - return *reinterpret_cast<const Vector3 *>(_data._mem) == Vector3(); } break; case VECTOR3I: { - return *reinterpret_cast<const Vector3i *>(_data._mem) == Vector3i(); } break; case PLANE: { - return *reinterpret_cast<const Plane *>(_data._mem) == Plane(); } break; @@ -984,111 +866,89 @@ bool Variant::is_zero() const { } break;*/ case AABB: { - return *_data._aabb == ::AABB(); } break; case QUAT: { - return *reinterpret_cast<const Quat *>(_data._mem) == Quat(); } break; case BASIS: { - return *_data._basis == Basis(); } break; case TRANSFORM: { - return *_data._transform == Transform(); } break; // misc types case COLOR: { - return *reinterpret_cast<const Color *>(_data._mem) == Color(); } break; case _RID: { - return *reinterpret_cast<const RID *>(_data._mem) == RID(); } break; case OBJECT: { - return _get_obj().obj == nullptr; } break; case CALLABLE: { - return reinterpret_cast<const Callable *>(_data._mem)->is_null(); } break; case SIGNAL: { - return reinterpret_cast<const Signal *>(_data._mem)->is_null(); } break; case STRING_NAME: { - return *reinterpret_cast<const StringName *>(_data._mem) != StringName(); } break; case NODE_PATH: { - return reinterpret_cast<const NodePath *>(_data._mem)->is_empty(); } break; case DICTIONARY: { - return reinterpret_cast<const Dictionary *>(_data._mem)->empty(); } break; case ARRAY: { - return reinterpret_cast<const Array *>(_data._mem)->empty(); } break; // arrays case PACKED_BYTE_ARRAY: { - return PackedArrayRef<uint8_t>::get_array(_data.packed_array).size() == 0; } break; case PACKED_INT32_ARRAY: { - return PackedArrayRef<int32_t>::get_array(_data.packed_array).size() == 0; } break; case PACKED_INT64_ARRAY: { - return PackedArrayRef<int64_t>::get_array(_data.packed_array).size() == 0; } break; case PACKED_FLOAT32_ARRAY: { - return PackedArrayRef<float>::get_array(_data.packed_array).size() == 0; } break; case PACKED_FLOAT64_ARRAY: { - return PackedArrayRef<double>::get_array(_data.packed_array).size() == 0; } break; case PACKED_STRING_ARRAY: { - return PackedArrayRef<String>::get_array(_data.packed_array).size() == 0; } break; case PACKED_VECTOR2_ARRAY: { - return PackedArrayRef<Vector2>::get_array(_data.packed_array).size() == 0; } break; case PACKED_VECTOR3_ARRAY: { - return PackedArrayRef<Vector3>::get_array(_data.packed_array).size() == 0; } break; case PACKED_COLOR_ARRAY: { - return PackedArrayRef<Color>::get_array(_data.packed_array).size() == 0; } break; @@ -1100,65 +960,52 @@ bool Variant::is_zero() const { } bool Variant::is_one() const { - switch (type) { case NIL: { - return true; } break; // atomic types case BOOL: { - return _data._bool; } break; case INT: { - return _data._int == 1; } break; case FLOAT: { - return _data._float == 1; } break; case VECTOR2: { - return *reinterpret_cast<const Vector2 *>(_data._mem) == Vector2(1, 1); } break; case VECTOR2I: { - return *reinterpret_cast<const Vector2i *>(_data._mem) == Vector2i(1, 1); } break; case RECT2: { - return *reinterpret_cast<const Rect2 *>(_data._mem) == Rect2(1, 1, 1, 1); } break; case RECT2I: { - return *reinterpret_cast<const Rect2i *>(_data._mem) == Rect2i(1, 1, 1, 1); } break; case VECTOR3: { - return *reinterpret_cast<const Vector3 *>(_data._mem) == Vector3(1, 1, 1); } break; case VECTOR3I: { - return *reinterpret_cast<const Vector3i *>(_data._mem) == Vector3i(1, 1, 1); } break; case PLANE: { - return *reinterpret_cast<const Plane *>(_data._mem) == Plane(1, 1, 1, 1); } break; case COLOR: { - return *reinterpret_cast<const Color *>(_data._mem) == Color(1, 1, 1, 1); } break; @@ -1180,7 +1027,6 @@ bool Variant::is_null() const { } void Variant::reference(const Variant &p_variant) { - switch (type) { case NIL: case BOOL: @@ -1195,93 +1041,73 @@ void Variant::reference(const Variant &p_variant) { 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 FLOAT: { - _data._float = p_variant._data._float; } break; case STRING: { - memnew_placement(_data._mem, String(*reinterpret_cast<const String *>(p_variant._data._mem))); } break; // math types case VECTOR2: { - memnew_placement(_data._mem, Vector2(*reinterpret_cast<const Vector2 *>(p_variant._data._mem))); } break; case VECTOR2I: { - memnew_placement(_data._mem, Vector2i(*reinterpret_cast<const Vector2i *>(p_variant._data._mem))); } break; case RECT2: { - memnew_placement(_data._mem, Rect2(*reinterpret_cast<const Rect2 *>(p_variant._data._mem))); } break; case RECT2I: { - memnew_placement(_data._mem, Rect2i(*reinterpret_cast<const Rect2i *>(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 VECTOR3I: { - memnew_placement(_data._mem, Vector3i(*reinterpret_cast<const Vector3i *>(p_variant._data._mem))); } break; case PLANE: { - memnew_placement(_data._mem, Plane(*reinterpret_cast<const Plane *>(p_variant._data._mem))); } break; case AABB: { - _data._aabb = memnew(::AABB(*p_variant._data._aabb)); } break; case QUAT: { - memnew_placement(_data._mem, Quat(*reinterpret_cast<const Quat *>(p_variant._data._mem))); } break; case BASIS: { - _data._basis = memnew(Basis(*p_variant._data._basis)); } break; case TRANSFORM: { - _data._transform = memnew(Transform(*p_variant._data._transform)); } break; // misc types case COLOR: { - memnew_placement(_data._mem, Color(*reinterpret_cast<const Color *>(p_variant._data._mem))); } break; case _RID: { - memnew_placement(_data._mem, RID(*reinterpret_cast<const RID *>(p_variant._data._mem))); } break; case OBJECT: { - memnew_placement(_data._mem, ObjData); if (p_variant._get_obj().obj && p_variant._get_obj().id.is_reference()) { @@ -1298,37 +1124,30 @@ void Variant::reference(const Variant &p_variant) { } break; case CALLABLE: { - memnew_placement(_data._mem, Callable(*reinterpret_cast<const Callable *>(p_variant._data._mem))); } break; case SIGNAL: { - memnew_placement(_data._mem, Signal(*reinterpret_cast<const Signal *>(p_variant._data._mem))); } break; case STRING_NAME: { - memnew_placement(_data._mem, StringName(*reinterpret_cast<const StringName *>(p_variant._data._mem))); } break; case NODE_PATH: { - memnew_placement(_data._mem, NodePath(*reinterpret_cast<const NodePath *>(p_variant._data._mem))); } break; case DICTIONARY: { - memnew_placement(_data._mem, Dictionary(*reinterpret_cast<const Dictionary *>(p_variant._data._mem))); } break; case ARRAY: { - memnew_placement(_data._mem, Array(*reinterpret_cast<const Array *>(p_variant._data._mem))); } break; // arrays case PACKED_BYTE_ARRAY: { - _data.packed_array = static_cast<PackedArrayRef<uint8_t> *>(p_variant._data.packed_array)->reference(); if (!_data.packed_array) { _data.packed_array = PackedArrayRef<uint8_t>::create(); @@ -1336,7 +1155,6 @@ void Variant::reference(const Variant &p_variant) { } break; case PACKED_INT32_ARRAY: { - _data.packed_array = static_cast<PackedArrayRef<int32_t> *>(p_variant._data.packed_array)->reference(); if (!_data.packed_array) { _data.packed_array = PackedArrayRef<int32_t>::create(); @@ -1344,7 +1162,6 @@ void Variant::reference(const Variant &p_variant) { } break; case PACKED_INT64_ARRAY: { - _data.packed_array = static_cast<PackedArrayRef<int64_t> *>(p_variant._data.packed_array)->reference(); if (!_data.packed_array) { _data.packed_array = PackedArrayRef<int64_t>::create(); @@ -1352,7 +1169,6 @@ void Variant::reference(const Variant &p_variant) { } break; case PACKED_FLOAT32_ARRAY: { - _data.packed_array = static_cast<PackedArrayRef<float> *>(p_variant._data.packed_array)->reference(); if (!_data.packed_array) { _data.packed_array = PackedArrayRef<float>::create(); @@ -1360,7 +1176,6 @@ void Variant::reference(const Variant &p_variant) { } break; case PACKED_FLOAT64_ARRAY: { - _data.packed_array = static_cast<PackedArrayRef<double> *>(p_variant._data.packed_array)->reference(); if (!_data.packed_array) { _data.packed_array = PackedArrayRef<double>::create(); @@ -1368,7 +1183,6 @@ void Variant::reference(const Variant &p_variant) { } break; case PACKED_STRING_ARRAY: { - _data.packed_array = static_cast<PackedArrayRef<String> *>(p_variant._data.packed_array)->reference(); if (!_data.packed_array) { _data.packed_array = PackedArrayRef<String>::create(); @@ -1376,7 +1190,6 @@ void Variant::reference(const Variant &p_variant) { } break; case PACKED_VECTOR2_ARRAY: { - _data.packed_array = static_cast<PackedArrayRef<Vector2> *>(p_variant._data.packed_array)->reference(); if (!_data.packed_array) { _data.packed_array = PackedArrayRef<Vector2>::create(); @@ -1384,7 +1197,6 @@ void Variant::reference(const Variant &p_variant) { } break; case PACKED_VECTOR3_ARRAY: { - _data.packed_array = static_cast<PackedArrayRef<Vector3> *>(p_variant._data.packed_array)->reference(); if (!_data.packed_array) { _data.packed_array = PackedArrayRef<Vector3>::create(); @@ -1392,7 +1204,6 @@ void Variant::reference(const Variant &p_variant) { } break; case PACKED_COLOR_ARRAY: { - _data.packed_array = static_cast<PackedArrayRef<Color> *>(p_variant._data.packed_array)->reference(); if (!_data.packed_array) { _data.packed_array = PackedArrayRef<Color>::create(); @@ -1451,10 +1262,8 @@ void Variant::zero() { } void Variant::clear() { - switch (type) { case STRING: { - reinterpret_cast<String *>(_data._mem)->~String(); } break; /* @@ -1467,33 +1276,26 @@ void Variant::clear() { RECT2 */ case TRANSFORM2D: { - memdelete(_data._transform2d); } break; case AABB: { - memdelete(_data._aabb); } break; case BASIS: { - memdelete(_data._basis); } break; case TRANSFORM: { - memdelete(_data._transform); } break; // misc types case STRING_NAME: { - reinterpret_cast<StringName *>(_data._mem)->~StringName(); } break; case NODE_PATH: { - reinterpret_cast<NodePath *>(_data._mem)->~NodePath(); } break; case OBJECT: { - if (_get_obj().id.is_reference()) { //we are safe that there is a reference here Reference *reference = static_cast<Reference *>(_get_obj().obj); @@ -1509,56 +1311,43 @@ void Variant::clear() { reinterpret_cast<RID *>(_data._mem)->~RID(); } break; case CALLABLE: { - reinterpret_cast<Callable *>(_data._mem)->~Callable(); } break; case SIGNAL: { - reinterpret_cast<Signal *>(_data._mem)->~Signal(); } break; case DICTIONARY: { - reinterpret_cast<Dictionary *>(_data._mem)->~Dictionary(); } break; case ARRAY: { - reinterpret_cast<Array *>(_data._mem)->~Array(); } break; // arrays case PACKED_BYTE_ARRAY: { - PackedArrayRefBase::destroy(_data.packed_array); } break; case PACKED_INT32_ARRAY: { - PackedArrayRefBase::destroy(_data.packed_array); } break; case PACKED_INT64_ARRAY: { - PackedArrayRefBase::destroy(_data.packed_array); } break; case PACKED_FLOAT32_ARRAY: { - PackedArrayRefBase::destroy(_data.packed_array); } break; case PACKED_FLOAT64_ARRAY: { - PackedArrayRefBase::destroy(_data.packed_array); } break; case PACKED_STRING_ARRAY: { - PackedArrayRefBase::destroy(_data.packed_array); } break; case PACKED_VECTOR2_ARRAY: { - PackedArrayRefBase::destroy(_data.packed_array); } break; case PACKED_VECTOR3_ARRAY: { - PackedArrayRefBase::destroy(_data.packed_array); } break; case PACKED_COLOR_ARRAY: { - PackedArrayRefBase::destroy(_data.packed_array); } break; default: { @@ -1569,9 +1358,7 @@ void Variant::clear() { } Variant::operator signed int() const { - switch (type) { - case NIL: return 0; case BOOL: @@ -1583,15 +1370,12 @@ Variant::operator signed int() const { case STRING: return operator String().to_int(); default: { - return 0; } } } Variant::operator unsigned int() const { - switch (type) { - case NIL: return 0; case BOOL: @@ -1603,16 +1387,13 @@ Variant::operator unsigned int() const { case STRING: return operator String().to_int(); default: { - return 0; } } } Variant::operator int64_t() const { - switch (type) { - case NIL: return 0; case BOOL: @@ -1624,7 +1405,6 @@ Variant::operator int64_t() const { case STRING: return operator String().to_int64(); default: { - return 0; } } @@ -1651,9 +1431,7 @@ Variant::operator long unsigned int() const { */ Variant::operator uint64_t() const { - switch (type) { - case NIL: return 0; case BOOL: @@ -1665,7 +1443,6 @@ Variant::operator uint64_t() const { case STRING: return operator String().to_int(); default: { - return 0; } } @@ -1683,9 +1460,7 @@ Variant::operator ObjectID() const { #ifdef NEED_LONG_INT Variant::operator signed long() const { - switch (type) { - case NIL: return 0; case BOOL: @@ -1697,7 +1472,6 @@ Variant::operator signed long() const { case STRING: return operator String().to_int(); default: { - return 0; } } @@ -1706,9 +1480,7 @@ Variant::operator signed long() const { }; Variant::operator unsigned long() const { - switch (type) { - case NIL: return 0; case BOOL: @@ -1720,7 +1492,6 @@ Variant::operator unsigned long() const { case STRING: return operator String().to_int(); default: { - return 0; } } @@ -1730,9 +1501,7 @@ Variant::operator unsigned long() const { #endif Variant::operator signed short() const { - switch (type) { - case NIL: return 0; case BOOL: @@ -1744,15 +1513,12 @@ Variant::operator signed short() const { case STRING: return operator String().to_int(); default: { - return 0; } } } Variant::operator unsigned short() const { - switch (type) { - case NIL: return 0; case BOOL: @@ -1764,15 +1530,12 @@ Variant::operator unsigned short() const { case STRING: return operator String().to_int(); default: { - return 0; } } } Variant::operator signed char() const { - switch (type) { - case NIL: return 0; case BOOL: @@ -1784,15 +1547,12 @@ Variant::operator signed char() const { case STRING: return operator String().to_int(); default: { - return 0; } } } Variant::operator unsigned char() const { - switch (type) { - case NIL: return 0; case BOOL: @@ -1804,21 +1564,17 @@ Variant::operator unsigned char() const { case STRING: return operator String().to_int(); default: { - return 0; } } } Variant::operator CharType() const { - return operator unsigned int(); } Variant::operator float() const { - switch (type) { - case NIL: return 0; case BOOL: @@ -1830,15 +1586,12 @@ Variant::operator float() const { case STRING: return operator String().to_double(); default: { - return 0; } } } Variant::operator double() const { - switch (type) { - case NIL: return 0; case BOOL: @@ -1850,14 +1603,12 @@ Variant::operator double() const { case STRING: return operator String().to_double(); default: { - return 0; } } } Variant::operator StringName() const { - if (type == STRING_NAME) { return *reinterpret_cast<const StringName *>(_data._mem); } else if (type == STRING) { @@ -1868,12 +1619,10 @@ Variant::operator StringName() const { } struct _VariantStrPair { - String key; String value; bool operator<(const _VariantStrPair &p) const { - return key < p.key; } }; @@ -1886,7 +1635,6 @@ Variant::operator String() const { String Variant::stringify(List<const void *> &stack) const { switch (type) { - case NIL: return "Null"; case BOOL: @@ -1906,7 +1654,6 @@ String Variant::stringify(List<const void *> &stack) const { case RECT2I: return "(" + operator Rect2i() + ")"; case TRANSFORM2D: { - Transform2D mat32 = operator Transform2D(); return "(" + Variant(mat32.elements[0]).operator String() + ", " + Variant(mat32.elements[1]).operator String() + ", " + Variant(mat32.elements[2]).operator String() + ")"; } break; @@ -1922,19 +1669,16 @@ String Variant::stringify(List<const void *> &stack) const { case QUAT: return "(" + operator Quat() + ")"; case BASIS: { - Basis mat3 = operator Basis(); String mtx("("); for (int i = 0; i < 3; i++) { - if (i != 0) mtx += ", "; mtx += "("; for (int j = 0; j < 3; j++) { - if (j != 0) mtx += ", "; @@ -1955,7 +1699,6 @@ String Variant::stringify(List<const void *> &stack) const { case COLOR: return String::num(operator Color().r) + "," + String::num(operator Color().g) + "," + String::num(operator Color().b) + "," + String::num(operator Color().a); case DICTIONARY: { - const Dictionary &d = *reinterpret_cast<const Dictionary *>(_data._mem); if (stack.find(d.id())) { return "{...}"; @@ -1971,7 +1714,6 @@ String Variant::stringify(List<const void *> &stack) const { Vector<_VariantStrPair> pairs; for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { - _VariantStrPair sp; sp.key = E->get().stringify(stack); sp.value = d[E->get()].stringify(stack); @@ -1991,11 +1733,9 @@ String Variant::stringify(List<const void *> &stack) const { return str; } break; case PACKED_VECTOR2_ARRAY: { - Vector<Vector2> vec = operator Vector<Vector2>(); String str("["); for (int i = 0; i < vec.size(); i++) { - if (i > 0) str += ", "; str = str + Variant(vec[i]); @@ -2004,11 +1744,9 @@ String Variant::stringify(List<const void *> &stack) const { return str; } break; case PACKED_VECTOR3_ARRAY: { - Vector<Vector3> vec = operator Vector<Vector3>(); String str("["); for (int i = 0; i < vec.size(); i++) { - if (i > 0) str += ", "; str = str + Variant(vec[i]); @@ -2017,11 +1755,9 @@ String Variant::stringify(List<const void *> &stack) const { return str; } break; case PACKED_STRING_ARRAY: { - Vector<String> vec = operator Vector<String>(); String str("["); for (int i = 0; i < vec.size(); i++) { - if (i > 0) str += ", "; str = str + vec[i]; @@ -2030,11 +1766,9 @@ String Variant::stringify(List<const void *> &stack) const { return str; } break; case PACKED_INT32_ARRAY: { - Vector<int32_t> vec = operator Vector<int32_t>(); String str("["); for (int i = 0; i < vec.size(); i++) { - if (i > 0) str += ", "; str = str + itos(vec[i]); @@ -2043,11 +1777,9 @@ String Variant::stringify(List<const void *> &stack) const { return str; } break; case PACKED_INT64_ARRAY: { - Vector<int64_t> vec = operator Vector<int64_t>(); String str("["); for (int i = 0; i < vec.size(); i++) { - if (i > 0) str += ", "; str = str + itos(vec[i]); @@ -2056,11 +1788,9 @@ String Variant::stringify(List<const void *> &stack) const { return str; } break; case PACKED_FLOAT32_ARRAY: { - Vector<float> vec = operator Vector<float>(); String str("["); for (int i = 0; i < vec.size(); i++) { - if (i > 0) str += ", "; str = str + rtos(vec[i]); @@ -2069,11 +1799,9 @@ String Variant::stringify(List<const void *> &stack) const { return str; } break; case PACKED_FLOAT64_ARRAY: { - Vector<double> vec = operator Vector<double>(); String str("["); for (int i = 0; i < vec.size(); i++) { - if (i > 0) str += ", "; str = str + rtos(vec[i]); @@ -2082,7 +1810,6 @@ String Variant::stringify(List<const void *> &stack) const { return str; } break; case ARRAY: { - Array arr = operator Array(); if (stack.find(arr.id())) { return "[...]"; @@ -2102,9 +1829,7 @@ String Variant::stringify(List<const void *> &stack) const { } break; case OBJECT: { - if (_get_obj().obj) { - if (!_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { return "[Freed Object]"; }; @@ -2135,7 +1860,6 @@ String Variant::stringify(List<const void *> &stack) const { } Variant::operator Vector2() const { - if (type == VECTOR2) return *reinterpret_cast<const Vector2 *>(_data._mem); else if (type == VECTOR2I) @@ -2149,7 +1873,6 @@ Variant::operator Vector2() const { } Variant::operator Vector2i() const { - if (type == VECTOR2I) return *reinterpret_cast<const Vector2i *>(_data._mem); else if (type == VECTOR2) @@ -2163,7 +1886,6 @@ Variant::operator Vector2i() const { } Variant::operator Rect2() const { - if (type == RECT2) return *reinterpret_cast<const Rect2 *>(_data._mem); else if (type == RECT2I) @@ -2173,7 +1895,6 @@ Variant::operator Rect2() const { } Variant::operator Rect2i() const { - if (type == RECT2I) return *reinterpret_cast<const Rect2i *>(_data._mem); else if (type == RECT2) @@ -2183,7 +1904,6 @@ Variant::operator Rect2i() const { } Variant::operator Vector3() const { - if (type == VECTOR3) return *reinterpret_cast<const Vector3 *>(_data._mem); else if (type == VECTOR3I) @@ -2197,7 +1917,6 @@ Variant::operator Vector3() const { } Variant::operator Vector3i() const { - if (type == VECTOR3I) return *reinterpret_cast<const Vector3i *>(_data._mem); else if (type == VECTOR3) @@ -2211,14 +1930,12 @@ Variant::operator Vector3i() const { } Variant::operator Plane() const { - if (type == PLANE) return *reinterpret_cast<const Plane *>(_data._mem); else return Plane(); } Variant::operator ::AABB() const { - if (type == AABB) return *_data._aabb; else @@ -2226,7 +1943,6 @@ Variant::operator ::AABB() const { } Variant::operator Basis() const { - if (type == BASIS) return *_data._basis; else if (type == QUAT) @@ -2240,7 +1956,6 @@ Variant::operator Basis() const { } Variant::operator Quat() const { - if (type == QUAT) return *reinterpret_cast<const Quat *>(_data._mem); else if (type == BASIS) @@ -2252,7 +1967,6 @@ Variant::operator Quat() const { } Variant::operator Transform() const { - if (type == TRANSFORM) return *_data._transform; else if (type == BASIS) @@ -2274,7 +1988,6 @@ Variant::operator Transform() const { } Variant::operator Transform2D() const { - if (type == TRANSFORM2D) { return *_data._transform2d; } else if (type == TRANSFORM) { @@ -2292,7 +2005,6 @@ Variant::operator Transform2D() const { } Variant::operator Color() const { - if (type == COLOR) return *reinterpret_cast<const Color *>(_data._mem); else if (type == STRING) @@ -2304,7 +2016,6 @@ Variant::operator Color() const { } Variant::operator NodePath() const { - if (type == NODE_PATH) return *reinterpret_cast<const NodePath *>(_data._mem); else if (type == STRING) @@ -2314,7 +2025,6 @@ Variant::operator NodePath() const { } Variant::operator RID() const { - if (type == _RID) return *reinterpret_cast<const RID *>(_data._mem); else if (type == OBJECT && _get_obj().obj == nullptr) { @@ -2337,7 +2047,6 @@ Variant::operator RID() const { } Variant::operator Object *() const { - if (type == OBJECT) return _get_obj().obj; else @@ -2363,14 +2072,12 @@ Object *Variant::get_validated_object() const { } Variant::operator Node *() const { - if (type == OBJECT) return Object::cast_to<Node>(_get_obj().obj); else return nullptr; } Variant::operator Control *() const { - if (type == OBJECT) return Object::cast_to<Control>(_get_obj().obj); else @@ -2378,7 +2085,6 @@ Variant::operator Control *() const { } Variant::operator Dictionary() const { - if (type == DICTIONARY) return *reinterpret_cast<const Dictionary *>(_data._mem); else @@ -2386,7 +2092,6 @@ Variant::operator Dictionary() const { } Variant::operator Callable() const { - if (type == CALLABLE) return *reinterpret_cast<const Callable *>(_data._mem); else @@ -2394,7 +2099,6 @@ Variant::operator Callable() const { } Variant::operator Signal() const { - if (type == SIGNAL) return *reinterpret_cast<const Signal *>(_data._mem); else @@ -2403,12 +2107,10 @@ Variant::operator Signal() const { template <class DA, class SA> inline DA _convert_array(const SA &p_array) { - DA da; da.resize(p_array.size()); for (int i = 0; i < p_array.size(); i++) { - da.set(i, Variant(p_array.get(i))); } @@ -2417,9 +2119,7 @@ inline DA _convert_array(const SA &p_array) { template <class DA> inline DA _convert_array_from_variant(const Variant &p_variant) { - switch (p_variant.get_type()) { - case Variant::ARRAY: { return _convert_array<DA, Array>(p_variant.operator Array()); } @@ -2457,7 +2157,6 @@ inline DA _convert_array_from_variant(const Variant &p_variant) { } Variant::operator Array() const { - if (type == ARRAY) return *reinterpret_cast<const Array *>(_data._mem); else @@ -2465,21 +2164,18 @@ Variant::operator Array() const { } Variant::operator Vector<uint8_t>() const { - if (type == PACKED_BYTE_ARRAY) return static_cast<PackedArrayRef<uint8_t> *>(_data.packed_array)->array; else return _convert_array_from_variant<Vector<uint8_t>>(*this); } Variant::operator Vector<int32_t>() const { - if (type == PACKED_INT32_ARRAY) return static_cast<PackedArrayRef<int32_t> *>(_data.packed_array)->array; else return _convert_array_from_variant<Vector<int>>(*this); } Variant::operator Vector<int64_t>() const { - if (type == PACKED_INT64_ARRAY) return static_cast<PackedArrayRef<int64_t> *>(_data.packed_array)->array; else @@ -2487,7 +2183,6 @@ Variant::operator Vector<int64_t>() const { } Variant::operator Vector<float>() const { - if (type == PACKED_FLOAT32_ARRAY) return static_cast<PackedArrayRef<float> *>(_data.packed_array)->array; else @@ -2495,7 +2190,6 @@ Variant::operator Vector<float>() const { } Variant::operator Vector<double>() const { - if (type == PACKED_FLOAT64_ARRAY) return static_cast<PackedArrayRef<double> *>(_data.packed_array)->array; else @@ -2503,21 +2197,18 @@ Variant::operator Vector<double>() const { } Variant::operator Vector<String>() const { - if (type == PACKED_STRING_ARRAY) return static_cast<PackedArrayRef<String> *>(_data.packed_array)->array; else return _convert_array_from_variant<Vector<String>>(*this); } Variant::operator Vector<Vector3>() const { - if (type == PACKED_VECTOR3_ARRAY) return static_cast<PackedArrayRef<Vector3> *>(_data.packed_array)->array; else return _convert_array_from_variant<Vector<Vector3>>(*this); } Variant::operator Vector<Vector2>() const { - if (type == PACKED_VECTOR2_ARRAY) return static_cast<PackedArrayRef<Vector2> *>(_data.packed_array)->array; else @@ -2525,7 +2216,6 @@ Variant::operator Vector<Vector2>() const { } Variant::operator Vector<Color>() const { - if (type == PACKED_COLOR_ARRAY) return static_cast<PackedArrayRef<Color> *>(_data.packed_array)->array; else @@ -2535,7 +2225,6 @@ Variant::operator Vector<Color>() const { /* helpers */ Variant::operator Vector<RID>() const { - Array va = operator Array(); Vector<RID> rids; rids.resize(va.size()); @@ -2545,7 +2234,6 @@ Variant::operator Vector<RID>() const { } Variant::operator Vector<Plane>() const { - Array va = operator Array(); Vector<Plane> planes; int va_size = va.size(); @@ -2562,7 +2250,6 @@ Variant::operator Vector<Plane>() const { } Variant::operator Vector<Face3>() const { - Vector<Vector3> va = operator Vector<Vector3>(); Vector<Face3> faces; int va_size = va.size(); @@ -2580,7 +2267,6 @@ Variant::operator Vector<Face3>() const { } Variant::operator Vector<Variant>() const { - Array va = operator Array(); Vector<Variant> variants; int va_size = va.size(); @@ -2595,31 +2281,25 @@ Variant::operator Vector<Variant>() const { return variants; } Variant::operator Vector<StringName>() const { - Vector<String> from = operator Vector<String>(); Vector<StringName> to; int len = from.size(); to.resize(len); for (int i = 0; i < len; i++) { - to.write[i] = from[i]; } return to; } Variant::operator Margin() const { - return (Margin) operator int(); } Variant::operator Orientation() const { - return (Orientation) operator int(); } Variant::operator IP_Address() const { - if (type == PACKED_FLOAT32_ARRAY || type == PACKED_INT32_ARRAY || type == PACKED_FLOAT64_ARRAY || type == PACKED_INT64_ARRAY || type == PACKED_BYTE_ARRAY) { - Vector<int> addr = operator Vector<int>(); if (addr.size() == 4) { return IP_Address(addr.get(0), addr.get(1), addr.get(2), addr.get(3)); @@ -2630,7 +2310,6 @@ Variant::operator IP_Address() const { } Variant::Variant(bool p_bool) { - type = BOOL; _data._bool = p_bool; } @@ -2644,12 +2323,10 @@ Variant::Variant(long unsigned int p_long) { */ Variant::Variant(signed int p_int) { - type = INT; _data._int = p_int; } Variant::Variant(unsigned int p_int) { - type = INT; _data._int = p_int; } @@ -2657,56 +2334,46 @@ Variant::Variant(unsigned int p_int) { #ifdef NEED_LONG_INT Variant::Variant(signed long p_int) { - type = INT; _data._int = p_int; } Variant::Variant(unsigned long p_int) { - type = INT; _data._int = p_int; } #endif Variant::Variant(int64_t p_int) { - type = INT; _data._int = p_int; } Variant::Variant(uint64_t p_int) { - type = INT; _data._int = p_int; } Variant::Variant(signed short p_short) { - type = INT; _data._int = p_short; } Variant::Variant(unsigned short p_short) { - type = INT; _data._int = p_short; } Variant::Variant(signed char p_char) { - type = INT; _data._int = p_char; } Variant::Variant(unsigned char p_char) { - type = INT; _data._int = p_char; } Variant::Variant(float p_float) { - type = FLOAT; _data._float = p_float; } Variant::Variant(double p_double) { - type = FLOAT; _data._float = p_double; } @@ -2717,121 +2384,100 @@ Variant::Variant(const ObjectID &p_id) { } Variant::Variant(const StringName &p_string) { - type = STRING_NAME; memnew_placement(_data._mem, StringName(p_string)); } Variant::Variant(const String &p_string) { - type = STRING; memnew_placement(_data._mem, String(p_string)); } Variant::Variant(const char *const p_cstring) { - type = STRING; memnew_placement(_data._mem, String((const char *)p_cstring)); } Variant::Variant(const CharType *p_wstring) { - type = STRING; memnew_placement(_data._mem, String(p_wstring)); } Variant::Variant(const Vector3 &p_vector3) { - type = VECTOR3; memnew_placement(_data._mem, Vector3(p_vector3)); } Variant::Variant(const Vector3i &p_vector3i) { - type = VECTOR3I; memnew_placement(_data._mem, Vector3i(p_vector3i)); } Variant::Variant(const Vector2 &p_vector2) { - type = VECTOR2; memnew_placement(_data._mem, Vector2(p_vector2)); } Variant::Variant(const Vector2i &p_vector2i) { - type = VECTOR2I; memnew_placement(_data._mem, Vector2i(p_vector2i)); } Variant::Variant(const Rect2 &p_rect2) { - type = RECT2; memnew_placement(_data._mem, Rect2(p_rect2)); } Variant::Variant(const Rect2i &p_rect2i) { - type = RECT2I; memnew_placement(_data._mem, Rect2i(p_rect2i)); } Variant::Variant(const Plane &p_plane) { - type = PLANE; memnew_placement(_data._mem, Plane(p_plane)); } Variant::Variant(const ::AABB &p_aabb) { - type = AABB; _data._aabb = memnew(::AABB(p_aabb)); } Variant::Variant(const Basis &p_matrix) { - type = BASIS; _data._basis = memnew(Basis(p_matrix)); } Variant::Variant(const Quat &p_quat) { - type = QUAT; memnew_placement(_data._mem, Quat(p_quat)); } Variant::Variant(const Transform &p_transform) { - type = TRANSFORM; _data._transform = memnew(Transform(p_transform)); } Variant::Variant(const Transform2D &p_transform) { - type = TRANSFORM2D; _data._transform2d = memnew(Transform2D(p_transform)); } Variant::Variant(const Color &p_color) { - type = COLOR; memnew_placement(_data._mem, Color(p_color)); } Variant::Variant(const NodePath &p_node_path) { - type = NODE_PATH; memnew_placement(_data._mem, NodePath(p_node_path)); } Variant::Variant(const RID &p_rid) { - type = _RID; memnew_placement(_data._mem, RID(p_rid)); } Variant::Variant(const Object *p_object) { - type = OBJECT; memnew_placement(_data._mem, ObjData); if (p_object) { - if (p_object->is_reference()) { Reference *reference = const_cast<Reference *>(static_cast<const Reference *>(p_object)); if (!reference->init_ref()) { @@ -2850,30 +2496,25 @@ Variant::Variant(const Object *p_object) { } Variant::Variant(const Callable &p_callable) { - type = CALLABLE; memnew_placement(_data._mem, Callable(p_callable)); } Variant::Variant(const Signal &p_callable) { - type = SIGNAL; memnew_placement(_data._mem, Signal(p_callable)); } Variant::Variant(const Dictionary &p_dictionary) { - type = DICTIONARY; memnew_placement(_data._mem, Dictionary(p_dictionary)); } Variant::Variant(const Array &p_array) { - type = ARRAY; memnew_placement(_data._mem, Array(p_array)); } Variant::Variant(const Vector<Plane> &p_array) { - type = ARRAY; Array *plane_array = memnew_placement(_data._mem, Array); @@ -2881,13 +2522,11 @@ Variant::Variant(const Vector<Plane> &p_array) { plane_array->resize(p_array.size()); for (int i = 0; i < p_array.size(); i++) { - plane_array->operator[](i) = Variant(p_array[i]); } } Variant::Variant(const Vector<RID> &p_array) { - type = ARRAY; Array *rid_array = memnew_placement(_data._mem, Array); @@ -2895,65 +2534,54 @@ Variant::Variant(const Vector<RID> &p_array) { rid_array->resize(p_array.size()); for (int i = 0; i < p_array.size(); i++) { - rid_array->set(i, Variant(p_array[i])); } } Variant::Variant(const Vector<uint8_t> &p_byte_array) { - type = PACKED_BYTE_ARRAY; _data.packed_array = PackedArrayRef<uint8_t>::create(p_byte_array); } Variant::Variant(const Vector<int32_t> &p_int32_array) { - type = PACKED_INT32_ARRAY; _data.packed_array = PackedArrayRef<int32_t>::create(p_int32_array); } Variant::Variant(const Vector<int64_t> &p_int64_array) { - type = PACKED_INT64_ARRAY; _data.packed_array = PackedArrayRef<int64_t>::create(p_int64_array); } Variant::Variant(const Vector<float> &p_float32_array) { - type = PACKED_FLOAT32_ARRAY; _data.packed_array = PackedArrayRef<float>::create(p_float32_array); } Variant::Variant(const Vector<double> &p_float64_array) { - type = PACKED_FLOAT64_ARRAY; _data.packed_array = PackedArrayRef<double>::create(p_float64_array); } Variant::Variant(const Vector<String> &p_string_array) { - type = PACKED_STRING_ARRAY; _data.packed_array = PackedArrayRef<String>::create(p_string_array); } Variant::Variant(const Vector<Vector3> &p_vector3_array) { - type = PACKED_VECTOR3_ARRAY; _data.packed_array = PackedArrayRef<Vector3>::create(p_vector3_array); } Variant::Variant(const Vector<Vector2> &p_vector2_array) { - type = PACKED_VECTOR2_ARRAY; _data.packed_array = PackedArrayRef<Vector2>::create(p_vector2_array); } Variant::Variant(const Vector<Color> &p_color_array) { - type = PACKED_COLOR_ARRAY; _data.packed_array = PackedArrayRef<Color>::create(p_color_array); } Variant::Variant(const Vector<Face3> &p_face_array) { - Vector<Vector3> vertices; int face_count = p_face_array.size(); vertices.resize(face_count * 3); @@ -2963,7 +2591,6 @@ Variant::Variant(const Vector<Face3> &p_face_array) { Vector3 *w = vertices.ptrw(); for (int i = 0; i < face_count; i++) { - for (int j = 0; j < 3; j++) w[i * 3 + j] = r[i].vertex[j]; } @@ -2986,7 +2613,6 @@ Variant::Variant(const Vector<Variant> &p_array) { } Variant::Variant(const Vector<StringName> &p_array) { - type = NIL; Vector<String> v; int len = p_array.size(); @@ -2997,7 +2623,6 @@ Variant::Variant(const Vector<StringName> &p_array) { } void Variant::operator=(const Variant &p_variant) { - if (unlikely(this == &p_variant)) return; @@ -3008,90 +2633,70 @@ void Variant::operator=(const Variant &p_variant) { 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 FLOAT: { - _data._float = p_variant._data._float; } 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 VECTOR2I: { - *reinterpret_cast<Vector2i *>(_data._mem) = *reinterpret_cast<const Vector2i *>(p_variant._data._mem); } break; case RECT2: { - *reinterpret_cast<Rect2 *>(_data._mem) = *reinterpret_cast<const Rect2 *>(p_variant._data._mem); } break; case RECT2I: { - *reinterpret_cast<Rect2i *>(_data._mem) = *reinterpret_cast<const Rect2i *>(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 VECTOR3I: { - *reinterpret_cast<Vector3i *>(_data._mem) = *reinterpret_cast<const Vector3i *>(p_variant._data._mem); } break; case PLANE: { - *reinterpret_cast<Plane *>(_data._mem) = *reinterpret_cast<const Plane *>(p_variant._data._mem); } break; case AABB: { - *_data._aabb = *(p_variant._data._aabb); } 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: { - if (_get_obj().id.is_reference()) { //we are safe that there is a reference here Reference *reference = static_cast<Reference *>(_get_obj().obj); @@ -3114,66 +2719,51 @@ void Variant::operator=(const Variant &p_variant) { } break; case CALLABLE: { - *reinterpret_cast<Callable *>(_data._mem) = *reinterpret_cast<const Callable *>(p_variant._data._mem); } break; case SIGNAL: { - *reinterpret_cast<Signal *>(_data._mem) = *reinterpret_cast<const Signal *>(p_variant._data._mem); } break; case STRING_NAME: { - *reinterpret_cast<StringName *>(_data._mem) = *reinterpret_cast<const StringName *>(p_variant._data._mem); } 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 PACKED_BYTE_ARRAY: { - _data.packed_array = PackedArrayRef<uint8_t>::reference_from(_data.packed_array, p_variant._data.packed_array); } break; case PACKED_INT32_ARRAY: { - _data.packed_array = PackedArrayRef<int32_t>::reference_from(_data.packed_array, p_variant._data.packed_array); } break; case PACKED_INT64_ARRAY: { - _data.packed_array = PackedArrayRef<int64_t>::reference_from(_data.packed_array, p_variant._data.packed_array); } break; case PACKED_FLOAT32_ARRAY: { - _data.packed_array = PackedArrayRef<float>::reference_from(_data.packed_array, p_variant._data.packed_array); } break; case PACKED_FLOAT64_ARRAY: { - _data.packed_array = PackedArrayRef<double>::reference_from(_data.packed_array, p_variant._data.packed_array); } break; case PACKED_STRING_ARRAY: { - _data.packed_array = PackedArrayRef<String>::reference_from(_data.packed_array, p_variant._data.packed_array); } break; case PACKED_VECTOR2_ARRAY: { - _data.packed_array = PackedArrayRef<Vector2>::reference_from(_data.packed_array, p_variant._data.packed_array); } break; case PACKED_VECTOR3_ARRAY: { - _data.packed_array = PackedArrayRef<Vector3>::reference_from(_data.packed_array, p_variant._data.packed_array); } break; case PACKED_COLOR_ARRAY: { - _data.packed_array = PackedArrayRef<Color>::reference_from(_data.packed_array, p_variant._data.packed_array); } break; default: { @@ -3182,70 +2772,56 @@ void Variant::operator=(const Variant &p_variant) { } Variant::Variant(const IP_Address &p_address) { - type = STRING; memnew_placement(_data._mem, String(p_address)); } Variant::Variant(const Variant &p_variant) { - reference(p_variant); } uint32_t Variant::hash() const { - switch (type) { case NIL: { - return 0; } break; case BOOL: { - return _data._bool ? 1 : 0; } break; case INT: { - return _data._int; } break; case FLOAT: { - return hash_djb2_one_float(_data._float); } break; case STRING: { - return reinterpret_cast<const String *>(_data._mem)->hash(); } break; // math types case VECTOR2: { - uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Vector2 *>(_data._mem)->x); return hash_djb2_one_float(reinterpret_cast<const Vector2 *>(_data._mem)->y, hash); } break; case VECTOR2I: { - uint32_t hash = hash_djb2_one_32(reinterpret_cast<const Vector2i *>(_data._mem)->x); return hash_djb2_one_32(reinterpret_cast<const Vector2i *>(_data._mem)->y, hash); } break; case RECT2: { - uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->position.x); hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->position.y, hash); hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->size.x, hash); return hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->size.y, hash); } break; case RECT2I: { - uint32_t hash = hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->position.x); hash = hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->position.y, hash); hash = hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->size.x, hash); return hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->size.y, hash); } break; case TRANSFORM2D: { - uint32_t hash = 5831; for (int i = 0; i < 3; i++) { - for (int j = 0; j < 2; j++) { hash = hash_djb2_one_float(_data._transform2d->elements[i][j], hash); } @@ -3254,19 +2830,16 @@ uint32_t Variant::hash() const { return hash; } break; case VECTOR3: { - uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Vector3 *>(_data._mem)->x); hash = hash_djb2_one_float(reinterpret_cast<const Vector3 *>(_data._mem)->y, hash); return hash_djb2_one_float(reinterpret_cast<const Vector3 *>(_data._mem)->z, hash); } break; case VECTOR3I: { - uint32_t hash = hash_djb2_one_32(reinterpret_cast<const Vector3i *>(_data._mem)->x); hash = hash_djb2_one_32(reinterpret_cast<const Vector3i *>(_data._mem)->y, hash); return hash_djb2_one_32(reinterpret_cast<const Vector3i *>(_data._mem)->z, hash); } break; case PLANE: { - uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Plane *>(_data._mem)->normal.x); hash = hash_djb2_one_float(reinterpret_cast<const Plane *>(_data._mem)->normal.y, hash); hash = hash_djb2_one_float(reinterpret_cast<const Plane *>(_data._mem)->normal.z, hash); @@ -3279,10 +2852,8 @@ uint32_t Variant::hash() const { } break;*/ case AABB: { - uint32_t hash = 5831; for (int i = 0; i < 3; i++) { - hash = hash_djb2_one_float(_data._aabb->position[i], hash); hash = hash_djb2_one_float(_data._aabb->size[i], hash); } @@ -3291,7 +2862,6 @@ uint32_t Variant::hash() const { } break; case QUAT: { - uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Quat *>(_data._mem)->x); hash = hash_djb2_one_float(reinterpret_cast<const Quat *>(_data._mem)->y, hash); hash = hash_djb2_one_float(reinterpret_cast<const Quat *>(_data._mem)->z, hash); @@ -3299,10 +2869,8 @@ uint32_t Variant::hash() const { } break; case BASIS: { - uint32_t hash = 5831; for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { hash = hash_djb2_one_float(_data._basis->elements[i][j], hash); } @@ -3312,10 +2880,8 @@ uint32_t Variant::hash() const { } break; case TRANSFORM: { - uint32_t hash = 5831; for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { hash = hash_djb2_one_float(_data._transform->basis.elements[i][j], hash); } @@ -3328,7 +2894,6 @@ uint32_t Variant::hash() const { // misc types case COLOR: { - uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Color *>(_data._mem)->r); hash = hash_djb2_one_float(reinterpret_cast<const Color *>(_data._mem)->g, hash); hash = hash_djb2_one_float(reinterpret_cast<const Color *>(_data._mem)->b, hash); @@ -3336,45 +2901,36 @@ uint32_t Variant::hash() const { } break; case _RID: { - return hash_djb2_one_64(reinterpret_cast<const RID *>(_data._mem)->get_id()); } break; case OBJECT: { - return hash_djb2_one_64(make_uint64_t(_get_obj().obj)); } break; case STRING_NAME: { - return reinterpret_cast<const StringName *>(_data._mem)->hash(); } break; case NODE_PATH: { - return reinterpret_cast<const NodePath *>(_data._mem)->hash(); } break; case DICTIONARY: { - return reinterpret_cast<const Dictionary *>(_data._mem)->hash(); } break; case CALLABLE: { - return reinterpret_cast<const Callable *>(_data._mem)->hash(); } break; case SIGNAL: { - const Signal &s = *reinterpret_cast<const Signal *>(_data._mem); uint32_t hash = s.get_name().hash(); return hash_djb2_one_64(s.get_object_id(), hash); } break; case ARRAY: { - const Array &arr = *reinterpret_cast<const Array *>(_data._mem); return arr.hash(); } break; case PACKED_BYTE_ARRAY: { - const Vector<uint8_t> &arr = PackedArrayRef<uint8_t>::get_array(_data.packed_array); int len = arr.size(); if (likely(len)) { @@ -3386,7 +2942,6 @@ uint32_t Variant::hash() const { } break; case PACKED_INT32_ARRAY: { - const Vector<int32_t> &arr = PackedArrayRef<int32_t>::get_array(_data.packed_array); int len = arr.size(); if (likely(len)) { @@ -3398,7 +2953,6 @@ uint32_t Variant::hash() const { } break; case PACKED_INT64_ARRAY: { - const Vector<int64_t> &arr = PackedArrayRef<int64_t>::get_array(_data.packed_array); int len = arr.size(); if (likely(len)) { @@ -3410,7 +2964,6 @@ uint32_t Variant::hash() const { } break; case PACKED_FLOAT32_ARRAY: { - const Vector<float> &arr = PackedArrayRef<float>::get_array(_data.packed_array); int len = arr.size(); @@ -3423,7 +2976,6 @@ uint32_t Variant::hash() const { } break; case PACKED_FLOAT64_ARRAY: { - const Vector<double> &arr = PackedArrayRef<double>::get_array(_data.packed_array); int len = arr.size(); @@ -3436,7 +2988,6 @@ uint32_t Variant::hash() const { } break; case PACKED_STRING_ARRAY: { - uint32_t hash = 5831; const Vector<String> &arr = PackedArrayRef<String>::get_array(_data.packed_array); int len = arr.size(); @@ -3452,7 +3003,6 @@ uint32_t Variant::hash() const { return hash; } break; case PACKED_VECTOR2_ARRAY: { - uint32_t hash = 5831; const Vector<Vector2> &arr = PackedArrayRef<Vector2>::get_array(_data.packed_array); int len = arr.size(); @@ -3469,7 +3019,6 @@ uint32_t Variant::hash() const { return hash; } break; case PACKED_VECTOR3_ARRAY: { - uint32_t hash = 5831; const Vector<Vector3> &arr = PackedArrayRef<Vector3>::get_array(_data.packed_array); int len = arr.size(); @@ -3487,7 +3036,6 @@ uint32_t Variant::hash() const { return hash; } break; case PACKED_COLOR_ARRAY: { - uint32_t hash = 5831; const Vector<Color> &arr = PackedArrayRef<Color>::get_array(_data.packed_array); int len = arr.size(); @@ -3715,30 +3263,25 @@ bool Variant::hash_compare(const Variant &p_variant) const { } bool Variant::is_ref() const { - return type == OBJECT && _get_obj().id.is_reference(); } Vector<Variant> varray() { - return Vector<Variant>(); } Vector<Variant> varray(const Variant &p_arg1) { - Vector<Variant> v; v.push_back(p_arg1); return v; } Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2) { - Vector<Variant> v; v.push_back(p_arg1); v.push_back(p_arg2); return v; } Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3) { - Vector<Variant> v; v.push_back(p_arg1); v.push_back(p_arg2); @@ -3746,7 +3289,6 @@ Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Varia return v; } Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4) { - Vector<Variant> v; v.push_back(p_arg1); v.push_back(p_arg2); @@ -3756,7 +3298,6 @@ Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Varia } Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4, const Variant &p_arg5) { - Vector<Variant> v; v.push_back(p_arg1); v.push_back(p_arg2); @@ -3770,9 +3311,7 @@ void Variant::static_assign(const Variant &p_variant) { } bool Variant::is_shared() const { - switch (type) { - case OBJECT: return true; case ARRAY: @@ -3800,20 +3339,16 @@ Variant Variant::call(const StringName &p_method, VARIANT_ARG_DECLARE) { Variant ret = call(p_method, argptr, argc, error); switch (error.error) { - case Callable::CallError::CALL_ERROR_INVALID_ARGUMENT: { - String err = "Invalid type for argument #" + itos(error.argument) + ", expected '" + Variant::get_type_name(Variant::Type(error.expected)) + "'."; ERR_PRINT(err.utf8().get_data()); } break; case Callable::CallError::CALL_ERROR_INVALID_METHOD: { - String err = "Invalid method '" + p_method + "' for type '" + Variant::get_type_name(type) + "'."; ERR_PRINT(err.utf8().get_data()); } break; case Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: { - String err = "Too many arguments for method '" + p_method + "'"; ERR_PRINT(err.utf8().get_data()); } break; @@ -3825,12 +3360,10 @@ Variant Variant::call(const StringName &p_method, VARIANT_ARG_DECLARE) { } void Variant::construct_from_string(const String &p_string, Variant &r_value, ObjectConstruct p_obj_construct, void *p_construct_ud) { - r_value = Variant(); } String Variant::get_construct_string() const { - String vars; VariantWriter::write_to_string(*this, vars); @@ -3838,7 +3371,6 @@ String Variant::get_construct_string() const { } String Variant::get_call_error_text(Object *p_base, const StringName &p_method, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce) { - String err_text; if (ce.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) { @@ -3863,14 +3395,12 @@ String Variant::get_call_error_text(Object *p_base, const StringName &p_method, String class_name = p_base->get_class(); Ref<Script> script = p_base->get_script(); if (script.is_valid() && script->get_path().is_resource_file()) { - class_name += "(" + script->get_path().get_file() + ")"; } return "'" + class_name + "::" + String(p_method) + "': " + err_text; } String Variant::get_callable_error_text(const Callable &p_callable, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce) { - String err_text; if (ce.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) { @@ -3896,26 +3426,20 @@ String Variant::get_callable_error_text(const Callable &p_callable, const Varian } String vformat(const String &p_text, const Variant &p1, const Variant &p2, const Variant &p3, const Variant &p4, const Variant &p5) { - Array args; if (p1.get_type() != Variant::NIL) { - args.push_back(p1); if (p2.get_type() != Variant::NIL) { - args.push_back(p2); if (p3.get_type() != Variant::NIL) { - args.push_back(p3); if (p4.get_type() != Variant::NIL) { - args.push_back(p4); if (p5.get_type() != Variant::NIL) { - args.push_back(p5); } } diff --git a/core/variant.h b/core/variant.h index 0498e93825..70de8479e3 100644 --- a/core/variant.h +++ b/core/variant.h @@ -126,7 +126,6 @@ private: Type type = NIL; struct ObjData { - ObjectID id; Object *obj; }; @@ -403,7 +402,6 @@ public: static String get_operator_name(Operator p_op); static void evaluate(const Operator &p_op, const Variant &p_a, const Variant &p_b, Variant &r_ret, bool &r_valid); static _FORCE_INLINE_ Variant evaluate(const Operator &p_op, const Variant &p_a, const Variant &p_b) { - bool valid = true; Variant res; evaluate(p_op, p_a, p_b, res, valid); @@ -489,22 +487,18 @@ Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Varia Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4, const Variant &p_arg5); struct VariantHasher { - static _FORCE_INLINE_ uint32_t hash(const Variant &p_variant) { return p_variant.hash(); } }; struct VariantComparator { - static _FORCE_INLINE_ bool compare(const Variant &p_lhs, const Variant &p_rhs) { return p_lhs.hash_compare(p_rhs); } }; Variant::ObjData &Variant::_get_obj() { - return *reinterpret_cast<ObjData *>(&_data._mem[0]); } const Variant::ObjData &Variant::_get_obj() const { - return *reinterpret_cast<const ObjData *>(&_data._mem[0]); } diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 416a1a5fb8..61b1e91d6c 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -42,14 +42,11 @@ typedef void (*VariantFunc)(Variant &r_ret, Variant &p_self, const Variant **p_a typedef void (*VariantConstructFunc)(Variant &r_ret, const Variant **p_args); struct _VariantCall { - static void Vector3_dot(Variant &r_ret, Variant &p_self, const Variant **p_args) { - r_ret = reinterpret_cast<Vector3 *>(p_self._data._mem)->dot(*reinterpret_cast<const Vector3 *>(p_args[0]->_data._mem)); } struct FuncData { - int arg_count; Vector<Variant> default_args; Vector<Variant::Type> arg_types; @@ -62,14 +59,12 @@ struct _VariantCall { VariantFunc func; _FORCE_INLINE_ bool verify_arguments(const Variant **p_args, Callable::CallError &r_error) { - if (arg_count == 0) return true; const Variant::Type *tptr = &arg_types[0]; for (int i = 0; i < arg_count; i++) { - if (tptr[i] == Variant::NIL || tptr[i] == p_args[i]->type) continue; // all good if (!Variant::can_convert(p_args[i]->type, tptr[i])) { @@ -124,7 +119,6 @@ struct _VariantCall { }; struct TypeFunc { - Map<StringName, FuncData> functions; }; @@ -143,14 +137,12 @@ struct _VariantCall { //void addfunc(Variant::Type p_type, const StringName& p_name,VariantFunc p_func); static void make_func_return_variant(Variant::Type p_type, const StringName &p_name) { - #ifdef DEBUG_ENABLED type_funcs[p_type].functions[p_name].returns = true; #endif } static void addfunc(bool p_const, Variant::Type p_type, Variant::Type p_return, bool p_has_return, const StringName &p_name, VariantFunc p_func, const Vector<Variant> &p_defaultarg, const Arg &p_argtype1 = Arg(), const Arg &p_argtype2 = Arg(), const Arg &p_argtype3 = Arg(), const Arg &p_argtype4 = Arg(), const Arg &p_argtype5 = Arg()) { - FuncData funcdata; funcdata.func = p_func; funcdata.default_args = p_defaultarg; @@ -315,7 +307,6 @@ struct _VariantCall { VCALL_LOCALMEM1R(String, trim_suffix); static void _call_String_to_ascii(Variant &r_ret, Variant &p_self, const Variant **p_args) { - String *s = reinterpret_cast<String *>(p_self._data._mem); if (s->empty()) { r_ret = PackedByteArray(); @@ -333,7 +324,6 @@ struct _VariantCall { } static void _call_String_to_utf8(Variant &r_ret, Variant &p_self, const Variant **p_args) { - String *s = reinterpret_cast<String *>(p_self._data._mem); if (s->empty()) { r_ret = PackedByteArray(); @@ -592,7 +582,6 @@ struct _VariantCall { VCALL_LOCALMEM0R(Array, min); static void _call_PackedByteArray_get_string_from_ascii(Variant &r_ret, Variant &p_self, const Variant **p_args) { - PackedByteArray *ba = reinterpret_cast<PackedByteArray *>(p_self._data._mem); String s; if (ba->size() > 0) { @@ -608,7 +597,6 @@ struct _VariantCall { } static void _call_PackedByteArray_get_string_from_utf8(Variant &r_ret, Variant &p_self, const Variant **p_args) { - PackedByteArray *ba = reinterpret_cast<PackedByteArray *>(p_self._data._mem); String s; if (ba->size() > 0) { @@ -619,7 +607,6 @@ struct _VariantCall { } static void _call_PackedByteArray_compress(Variant &r_ret, Variant &p_self, const Variant **p_args) { - PackedByteArray *ba = reinterpret_cast<PackedByteArray *>(p_self._data._mem); PackedByteArray compressed; if (ba->size() > 0) { @@ -635,7 +622,6 @@ struct _VariantCall { } static void _call_PackedByteArray_decompress(Variant &r_ret, Variant &p_self, const Variant **p_args) { - PackedByteArray *ba = reinterpret_cast<PackedByteArray *>(p_self._data._mem); PackedByteArray decompressed; Compression::Mode mode = (Compression::Mode)(int)(*p_args[1]); @@ -985,7 +971,6 @@ struct _VariantCall { } struct ConstructData { - int arg_count; Vector<Variant::Type> arg_types; Vector<String> arg_names; @@ -993,50 +978,41 @@ struct _VariantCall { }; struct ConstructFunc { - List<ConstructData> constructors; }; static ConstructFunc *construct_funcs; static void Vector2_init1(Variant &r_ret, const Variant **p_args) { - r_ret = Vector2(*p_args[0], *p_args[1]); } static void Vector2i_init1(Variant &r_ret, const Variant **p_args) { - r_ret = Vector2i(*p_args[0], *p_args[1]); } static void Rect2_init1(Variant &r_ret, const Variant **p_args) { - r_ret = Rect2(*p_args[0], *p_args[1]); } static void Rect2_init2(Variant &r_ret, const Variant **p_args) { - r_ret = Rect2(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); } static void Rect2i_init1(Variant &r_ret, const Variant **p_args) { - r_ret = Rect2i(*p_args[0], *p_args[1]); } static void Rect2i_init2(Variant &r_ret, const Variant **p_args) { - r_ret = Rect2i(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); } static void Transform2D_init2(Variant &r_ret, const Variant **p_args) { - Transform2D m(*p_args[0], *p_args[1]); r_ret = m; } static void Transform2D_init3(Variant &r_ret, const Variant **p_args) { - Transform2D m; m[0] = *p_args[0]; m[1] = *p_args[1]; @@ -1045,81 +1021,65 @@ struct _VariantCall { } static void Vector3_init1(Variant &r_ret, const Variant **p_args) { - r_ret = Vector3(*p_args[0], *p_args[1], *p_args[2]); } static void Vector3i_init1(Variant &r_ret, const Variant **p_args) { - r_ret = Vector3i(*p_args[0], *p_args[1], *p_args[2]); } static void Plane_init1(Variant &r_ret, const Variant **p_args) { - r_ret = Plane(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); } static void Plane_init2(Variant &r_ret, const Variant **p_args) { - r_ret = Plane(*p_args[0], *p_args[1], *p_args[2]); } static void Plane_init3(Variant &r_ret, const Variant **p_args) { - r_ret = Plane(p_args[0]->operator Vector3(), p_args[1]->operator real_t()); } static void Plane_init4(Variant &r_ret, const Variant **p_args) { - r_ret = Plane(p_args[0]->operator Vector3(), p_args[1]->operator Vector3()); } static void Quat_init1(Variant &r_ret, const Variant **p_args) { - r_ret = Quat(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); } static void Quat_init2(Variant &r_ret, const Variant **p_args) { - r_ret = Quat(((Vector3)(*p_args[0])), ((real_t)(*p_args[1]))); } static void Quat_init3(Variant &r_ret, const Variant **p_args) { - r_ret = Quat(((Vector3)(*p_args[0]))); } static void Color_init1(Variant &r_ret, const Variant **p_args) { - r_ret = Color(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); } static void Color_init2(Variant &r_ret, const Variant **p_args) { - r_ret = Color(*p_args[0], *p_args[1], *p_args[2]); } static void Color_init3(Variant &r_ret, const Variant **p_args) { - r_ret = Color::html(*p_args[0]); } static void Color_init4(Variant &r_ret, const Variant **p_args) { - r_ret = Color::hex(*p_args[0]); } static void Color_init5(Variant &r_ret, const Variant **p_args) { - r_ret = Color(((Color)(*p_args[0])), *p_args[1]); } static void AABB_init1(Variant &r_ret, const Variant **p_args) { - r_ret = ::AABB(*p_args[0], *p_args[1]); } static void Basis_init1(Variant &r_ret, const Variant **p_args) { - Basis m; m.set_axis(0, *p_args[0]); m.set_axis(1, *p_args[1]); @@ -1128,12 +1088,10 @@ struct _VariantCall { } static void Basis_init2(Variant &r_ret, const Variant **p_args) { - r_ret = Basis(p_args[0]->operator Vector3(), p_args[1]->operator real_t()); } static void Transform_init1(Variant &r_ret, const Variant **p_args) { - Transform t; t.basis.set_axis(0, *p_args[0]); t.basis.set_axis(1, *p_args[1]); @@ -1143,17 +1101,14 @@ struct _VariantCall { } static void Transform_init2(Variant &r_ret, const Variant **p_args) { - r_ret = Transform(p_args[0]->operator Basis(), p_args[1]->operator Vector3()); } static void Callable_init2(Variant &r_ret, const Variant **p_args) { - r_ret = Callable(p_args[0]->operator ObjectID(), p_args[1]->operator String()); } static void Signal_init2(Variant &r_ret, const Variant **p_args) { - r_ret = Signal(p_args[0]->operator ObjectID(), p_args[1]->operator String()); } @@ -1162,7 +1117,6 @@ struct _VariantCall { const String &p_name2 = "", const Variant::Type p_type2 = Variant::NIL, const String &p_name3 = "", const Variant::Type p_type3 = Variant::NIL, const String &p_name4 = "", const Variant::Type p_type4 = Variant::NIL) { - ConstructData cd; cd.func = p_func; cd.arg_count = 0; @@ -1197,7 +1151,6 @@ struct _VariantCall { } struct ConstantData { - Map<StringName, int> value; #ifdef DEBUG_ENABLED List<StringName> value_ordered; @@ -1208,7 +1161,6 @@ struct _VariantCall { static ConstantData *constant_data; static void add_constant(int p_type, StringName p_constant_name, int p_constant_value) { - constant_data[p_type].value[p_constant_name] = p_constant_value; #ifdef DEBUG_ENABLED constant_data[p_type].value_ordered.push_back(p_constant_name); @@ -1216,7 +1168,6 @@ struct _VariantCall { } static void add_variant_constant(int p_type, StringName p_constant_name, const Variant &p_constant_value) { - constant_data[p_type].variant_value[p_constant_name] = p_constant_value; } }; @@ -1226,7 +1177,6 @@ _VariantCall::ConstructFunc *_VariantCall::construct_funcs = nullptr; _VariantCall::ConstantData *_VariantCall::constant_data = nullptr; Variant Variant::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - Variant ret; call_ptr(p_method, p_args, p_argcount, &ret, r_error); return ret; @@ -1254,13 +1204,11 @@ void Variant::call_ptr(const StringName &p_method, const Variant **p_args, int p //else if (type==Variant::METHOD) { } else { - r_error.error = Callable::CallError::CALL_OK; Map<StringName, _VariantCall::FuncData>::Element *E = _VariantCall::type_funcs[type].functions.find(p_method); if (E) { - _VariantCall::FuncData &funcdata = E->get(); funcdata.call(ret, *this, p_args, p_argcount, r_error); @@ -1269,7 +1217,6 @@ void Variant::call_ptr(const StringName &p_method, const Variant **p_args, int p bool valid = false; if (type == CALLABLE) { if (p_method == CoreStringNames::get_singleton()->call) { - reinterpret_cast<const Callable *>(_data._mem)->call(p_args, p_argcount, ret, r_error); valid = true; } @@ -1301,7 +1248,6 @@ void Variant::call_ptr(const StringName &p_method, const Variant **p_args, int p #define VCALL(m_type, m_method) _VariantCall::_call_##m_type##_##m_method Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, int p_argcount, Callable::CallError &r_error, bool p_strict) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; ERR_FAIL_INDEX_V(p_type, VARIANT_MAX, Variant()); @@ -1390,7 +1336,6 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i switch (p_type) { case NIL: { - return Variant(); } break; case BOOL: { @@ -1475,7 +1420,6 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i return Variant(); } } else if (p_argcount >= 1) { - _VariantCall::ConstructFunc &c = _VariantCall::construct_funcs[p_type]; for (List<_VariantCall::ConstructData>::Element *E = c.constructors.front(); E; E = E->next()) { @@ -1504,7 +1448,6 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i } bool Variant::has_method(const StringName &p_method) const { - if (type == OBJECT) { Object *obj = get_validated_object(); if (!obj) @@ -1518,7 +1461,6 @@ bool Variant::has_method(const StringName &p_method) const { } Vector<Variant::Type> Variant::get_method_argument_types(Variant::Type p_type, const StringName &p_method) { - const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method); @@ -1529,7 +1471,6 @@ Vector<Variant::Type> Variant::get_method_argument_types(Variant::Type p_type, c } bool Variant::is_method_const(Variant::Type p_type, const StringName &p_method) { - const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method); @@ -1540,7 +1481,6 @@ bool Variant::is_method_const(Variant::Type p_type, const StringName &p_method) } Vector<StringName> Variant::get_method_argument_names(Variant::Type p_type, const StringName &p_method) { - const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method); @@ -1551,7 +1491,6 @@ Vector<StringName> Variant::get_method_argument_names(Variant::Type p_type, cons } Variant::Type Variant::get_method_return_type(Variant::Type p_type, const StringName &p_method, bool *r_has_return) { - const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method); @@ -1565,7 +1504,6 @@ Variant::Type Variant::get_method_return_type(Variant::Type p_type, const String } Vector<Variant> Variant::get_method_default_arguments(Variant::Type p_type, const StringName &p_method) { - const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method); @@ -1576,11 +1514,9 @@ Vector<Variant> Variant::get_method_default_arguments(Variant::Type p_type, cons } void Variant::get_method_list(List<MethodInfo> *p_list) const { - const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[type]; for (const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.front(); E; E = E->next()) { - const _VariantCall::FuncData &fd = E->get(); MethodInfo mi; @@ -1591,7 +1527,6 @@ void Variant::get_method_list(List<MethodInfo> *p_list) const { } for (int i = 0; i < fd.arg_types.size(); i++) { - PropertyInfo pi; pi.type = fd.arg_types[i]; #ifdef DEBUG_ENABLED @@ -1616,7 +1551,6 @@ void Variant::get_method_list(List<MethodInfo> *p_list) const { } if (type == CALLABLE) { - MethodInfo mi; mi.name = "call"; mi.return_val.usage = PROPERTY_USAGE_NIL_IS_VARIANT; @@ -1631,7 +1565,6 @@ void Variant::get_method_list(List<MethodInfo> *p_list) const { } if (type == SIGNAL) { - MethodInfo mi; mi.name = "emit"; mi.flags |= METHOD_FLAG_VARARG; @@ -1641,18 +1574,15 @@ void Variant::get_method_list(List<MethodInfo> *p_list) const { } void Variant::get_constructor_list(Variant::Type p_type, List<MethodInfo> *p_list) { - ERR_FAIL_INDEX(p_type, VARIANT_MAX); //custom constructors for (const List<_VariantCall::ConstructData>::Element *E = _VariantCall::construct_funcs[p_type].constructors.front(); E; E = E->next()) { - const _VariantCall::ConstructData &cd = E->get(); MethodInfo mi; mi.name = Variant::get_type_name(p_type); mi.return_val.type = p_type; for (int i = 0; i < cd.arg_count; i++) { - PropertyInfo pi; pi.name = cd.arg_names[i]; pi.type = cd.arg_types[i]; @@ -1679,37 +1609,31 @@ void Variant::get_constructor_list(Variant::Type p_type, List<MethodInfo> *p_lis } void Variant::get_constants_for_type(Variant::Type p_type, List<StringName> *p_constants) { - ERR_FAIL_INDEX(p_type, Variant::VARIANT_MAX); _VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type]; #ifdef DEBUG_ENABLED for (List<StringName>::Element *E = cd.value_ordered.front(); E; E = E->next()) { - p_constants->push_back(E->get()); #else for (Map<StringName, int>::Element *E = cd.value.front(); E; E = E->next()) { - p_constants->push_back(E->key()); #endif } for (Map<StringName, Variant>::Element *E = cd.variant_value.front(); E; E = E->next()) { - p_constants->push_back(E->key()); } } bool Variant::has_constant(Variant::Type p_type, const StringName &p_value) { - ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false); _VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type]; return cd.value.has(p_value) || cd.variant_value.has(p_value); } Variant Variant::get_constant_value(Variant::Type p_type, const StringName &p_value, bool *r_valid) { - if (r_valid) *r_valid = false; @@ -1734,7 +1658,6 @@ Variant Variant::get_constant_value(Variant::Type p_type, const StringName &p_va } void register_variant_methods() { - _VariantCall::type_funcs = memnew_arr(_VariantCall::TypeFunc, Variant::VARIANT_MAX); _VariantCall::construct_funcs = memnew_arr(_VariantCall::ConstructFunc, Variant::VARIANT_MAX); @@ -2395,7 +2318,6 @@ void register_variant_methods() { } void unregister_variant_methods() { - memdelete_arr(_VariantCall::type_funcs); memdelete_arr(_VariantCall::construct_funcs); memdelete_arr(_VariantCall::constant_data); diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 4c9848f26a..b7678d8f43 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -159,7 +159,6 @@ #endif Variant::operator bool() const { - return booleanize(); } @@ -435,7 +434,6 @@ bool Variant::booleanize() const { if (a_len m_opa array_b.size()) { \ _RETURN(m_ret_s); \ } else { \ - \ const m_type *ra = array_a.ptr(); \ const m_type *rb = array_b.ptr(); \ \ @@ -461,7 +459,6 @@ bool Variant::booleanize() const { void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &p_b, Variant &r_ret, bool &r_valid) { - CASES(math); r_valid = true; @@ -1418,7 +1415,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, } void Variant::set_named(const StringName &p_index, const Variant &p_value, bool *r_valid) { - bool valid = false; switch (type) { case VECTOR2: { @@ -1466,7 +1462,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool } break; case RECT2: { - if (p_value.type == Variant::VECTOR2) { Rect2 *v = reinterpret_cast<Rect2 *>(_data._mem); //scalar name @@ -1483,7 +1478,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool } } break; case RECT2I: { - if (p_value.type == Variant::VECTOR2I) { Rect2i *v = reinterpret_cast<Rect2i *>(_data._mem); //scalar name @@ -1500,7 +1494,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool } } break; case TRANSFORM2D: { - if (p_value.type == Variant::VECTOR2) { Transform2D *v = _data._transform2d; if (p_index == CoreStringNames::singleton->x) { @@ -1517,7 +1510,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool } break; case VECTOR3: { - if (p_value.type == Variant::INT) { Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem); if (p_index == CoreStringNames::singleton->x) { @@ -1546,7 +1538,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool } break; case VECTOR3I: { - if (p_value.type == Variant::INT) { Vector3i *v = reinterpret_cast<Vector3i *>(_data._mem); if (p_index == CoreStringNames::singleton->x) { @@ -1575,7 +1566,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool } break; case PLANE: { - if (p_value.type == Variant::INT) { Plane *v = reinterpret_cast<Plane *>(_data._mem); if (p_index == CoreStringNames::singleton->x) { @@ -1617,7 +1607,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool } break; case QUAT: { - if (p_value.type == Variant::INT) { Quat *v = reinterpret_cast<Quat *>(_data._mem); if (p_index == CoreStringNames::singleton->x) { @@ -1652,7 +1641,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool } break; case AABB: { - if (p_value.type == Variant::VECTOR3) { ::AABB *v = _data._aabb; //scalar name @@ -1669,7 +1657,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool } } break; case BASIS: { - if (p_value.type == Variant::VECTOR3) { Basis *v = _data._basis; //scalar name @@ -1686,7 +1673,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool } } break; case TRANSFORM: { - if (p_value.type == Variant::BASIS && p_index == CoreStringNames::singleton->basis) { _data._transform->basis = *p_value._data._basis; valid = true; @@ -1697,7 +1683,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool } break; case COLOR: { - if (p_value.type == Variant::INT) { Color *v = reinterpret_cast<Color *>(_data._mem); if (p_index == CoreStringNames::singleton->r) { @@ -1773,7 +1758,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool } } break; case OBJECT: { - #ifdef DEBUG_ENABLED if (!_get_obj().obj) { break; @@ -1796,7 +1780,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool } Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { - if (r_valid) { *r_valid = true; } @@ -1820,7 +1803,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { } break; case RECT2: { - const Rect2 *v = reinterpret_cast<const Rect2 *>(_data._mem); //scalar name if (p_index == CoreStringNames::singleton->position) { @@ -1832,7 +1814,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { } } break; case RECT2I: { - const Rect2i *v = reinterpret_cast<const Rect2i *>(_data._mem); //scalar name if (p_index == CoreStringNames::singleton->position) { @@ -1844,7 +1825,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { } } break; case TRANSFORM2D: { - const Transform2D *v = _data._transform2d; if (p_index == CoreStringNames::singleton->x) { return v->elements[0]; @@ -1856,7 +1836,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { } break; case VECTOR3: { - const Vector3 *v = reinterpret_cast<const Vector3 *>(_data._mem); if (p_index == CoreStringNames::singleton->x) { return v->x; @@ -1868,7 +1847,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { } break; case VECTOR3I: { - const Vector3i *v = reinterpret_cast<const Vector3i *>(_data._mem); if (p_index == CoreStringNames::singleton->x) { return v->x; @@ -1880,7 +1858,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { } break; case PLANE: { - const Plane *v = reinterpret_cast<const Plane *>(_data._mem); if (p_index == CoreStringNames::singleton->x) { return v->normal.x; @@ -1896,7 +1873,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { } break; case QUAT: { - const Quat *v = reinterpret_cast<const Quat *>(_data._mem); if (p_index == CoreStringNames::singleton->x) { return v->x; @@ -1910,7 +1886,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { } break; case AABB: { - const ::AABB *v = _data._aabb; //scalar name if (p_index == CoreStringNames::singleton->position) { @@ -1922,7 +1897,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { } } break; case BASIS: { - const Basis *v = _data._basis; //scalar name if (p_index == CoreStringNames::singleton->x) { @@ -1935,7 +1909,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { } break; case TRANSFORM: { - if (p_index == CoreStringNames::singleton->basis) { return _data._transform->basis; } else if (p_index == CoreStringNames::singleton->origin) { @@ -1944,7 +1917,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { } break; case COLOR: { - const Color *v = reinterpret_cast<const Color *>(_data._mem); if (p_index == CoreStringNames::singleton->r) { return v->r; @@ -1971,14 +1943,12 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { } } break; case OBJECT: { - #ifdef DEBUG_ENABLED if (!_get_obj().obj) { if (r_valid) *r_valid = false; return "Instance base is null."; } else { - if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { if (r_valid) *r_valid = false; @@ -2039,7 +2009,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { #define DEFAULT_OP_DVECTOR_GET(m_name, m_type) \ case m_name: { \ - \ if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { \ int index = p_index; \ const Vector<m_type> *arr = &PackedArrayRef<m_type>::get_array(_data.packed_array); \ @@ -2054,7 +2023,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { } break; void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) { - static bool _dummy = false; bool &valid = r_valid ? *r_valid : _dummy; @@ -2074,7 +2042,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) return; } break; case STRING: { - if (p_index.type != Variant::INT && p_index.type != Variant::FLOAT) return; @@ -2088,10 +2055,8 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) String chr; if (p_value.type == Variant::INT || p_value.type == Variant::FLOAT) { - chr = String::chr(p_value); } else if (p_value.type == Variant::STRING) { - chr = p_value; } else { return; @@ -2103,7 +2068,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case VECTOR2: { - if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) return; @@ -2114,7 +2078,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) if (idx < 0) idx += 2; if (idx >= 0 && idx < 2) { - Vector2 *v = reinterpret_cast<Vector2 *>(_data._mem); valid = true; (*v)[idx] = p_value; @@ -2138,7 +2101,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case VECTOR2I: { - if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) return; @@ -2149,7 +2111,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) if (idx < 0) idx += 2; if (idx >= 0 && idx < 2) { - Vector2i *v = reinterpret_cast<Vector2i *>(_data._mem); valid = true; (*v)[idx] = p_value; @@ -2173,7 +2134,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case RECT2: { - if (p_value.type != Variant::VECTOR2) return; @@ -2198,7 +2158,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } } break; case RECT2I: { - if (p_value.type != Variant::VECTOR2I) return; @@ -2223,12 +2182,10 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } } break; case TRANSFORM2D: { - if (p_value.type != Variant::VECTOR2) return; if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { - int index = p_index; if (index < 0) @@ -2241,7 +2198,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) return; } } else if (p_index.get_type() == Variant::STRING && p_value.get_type() == Variant::VECTOR2) { - //scalar name const String *str = reinterpret_cast<const String *>(p_index._data._mem); Transform2D *v = _data._transform2d; @@ -2262,7 +2218,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case VECTOR3: { - if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) return; @@ -2272,14 +2227,12 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) if (idx < 0) idx += 3; if (idx >= 0 && idx < 3) { - Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem); valid = true; (*v)[idx] = p_value; return; } } else if (p_index.get_type() == Variant::STRING) { - //scalar name const String *str = reinterpret_cast<const String *>(p_index._data._mem); Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem); @@ -2300,7 +2253,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case VECTOR3I: { - if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) return; @@ -2310,14 +2262,12 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) if (idx < 0) idx += 3; if (idx >= 0 && idx < 3) { - Vector3i *v = reinterpret_cast<Vector3i *>(_data._mem); valid = true; (*v)[idx] = p_value; return; } } else if (p_index.get_type() == Variant::STRING) { - //scalar name const String *str = reinterpret_cast<const String *>(p_index._data._mem); Vector3i *v = reinterpret_cast<Vector3i *>(_data._mem); @@ -2338,7 +2288,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case PLANE: { - if (p_index.get_type() == Variant::STRING) { //scalar name const String *str = reinterpret_cast<const String *>(p_index._data._mem); @@ -2380,12 +2329,10 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case QUAT: { - if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) return; if (p_index.get_type() == Variant::STRING) { - const String *str = reinterpret_cast<const String *>(p_index._data._mem); Quat *v = reinterpret_cast<Quat *>(_data._mem); if (*str == "x") { @@ -2409,7 +2356,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case AABB: { - if (p_value.type != Variant::VECTOR3) return; @@ -2434,12 +2380,10 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } } break; case BASIS: { - if (p_value.type != Variant::VECTOR3) return; if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { - int index = p_index; if (index < 0) @@ -2452,7 +2396,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) return; } } else if (p_index.get_type() == Variant::STRING) { - const String *str = reinterpret_cast<const String *>(p_index._data._mem); Basis *v = _data._basis; @@ -2473,9 +2416,7 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case TRANSFORM: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { - if (p_value.type != Variant::VECTOR3) return; @@ -2493,12 +2434,10 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) return; } } else if (p_index.get_type() == Variant::STRING) { - Transform *v = _data._transform; const String *str = reinterpret_cast<const String *>(p_index._data._mem); if (*str == "basis") { - if (p_value.type != Variant::BASIS) return; valid = true; @@ -2516,12 +2455,10 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case COLOR: { - if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) return; if (p_index.get_type() == Variant::STRING) { - const String *str = reinterpret_cast<const String *>(p_index._data._mem); Color *v = reinterpret_cast<Color *>(_data._mem); if (*str == "r") { @@ -2570,7 +2507,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) return; } } else if (p_index.get_type() == Variant::INT) { - int idx = p_index; if (idx < 0) idx += 4; @@ -2589,14 +2525,12 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) case _RID: { } break; case OBJECT: { - Object *obj = _get_obj().obj; //only if debugging! if (obj) { #ifdef DEBUG_ENABLED if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { - WARN_PRINT("Attempted use of previously freed pointer object."); valid = false; return; @@ -2613,7 +2547,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } } break; case DICTIONARY: { - Dictionary *dic = reinterpret_cast<Dictionary *>(_data._mem); dic->operator[](p_index) = p_value; valid = true; //always valid, i guess? should this really be ok? @@ -2635,7 +2568,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } Variant Variant::get(const Variant &p_index, bool *r_valid) const { - static bool _dummy = false; bool &valid = r_valid ? *r_valid : _dummy; @@ -2656,7 +2588,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { return Variant(); } break; case STRING: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { //string index @@ -2665,7 +2596,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { if (idx < 0) idx += str->length(); if (idx >= 0 && idx < str->length()) { - valid = true; return str->substr(idx, 1); } @@ -2673,14 +2603,12 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } break; case VECTOR2: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { // scalar index int idx = p_index; if (idx < 0) idx += 2; if (idx >= 0 && idx < 2) { - const Vector2 *v = reinterpret_cast<const Vector2 *>(_data._mem); valid = true; return (*v)[idx]; @@ -2701,14 +2629,12 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } break; case VECTOR2I: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { // scalar index int idx = p_index; if (idx < 0) idx += 2; if (idx >= 0 && idx < 2) { - const Vector2i *v = reinterpret_cast<const Vector2i *>(_data._mem); valid = true; return (*v)[idx]; @@ -2729,7 +2655,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } break; case RECT2: { - if (p_index.get_type() == Variant::STRING) { //scalar name @@ -2748,7 +2673,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } } break; case RECT2I: { - if (p_index.get_type() == Variant::STRING) { //scalar name @@ -2767,20 +2691,17 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } } break; case VECTOR3: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { //scalar index int idx = p_index; if (idx < 0) idx += 3; if (idx >= 0 && idx < 3) { - const Vector3 *v = reinterpret_cast<const Vector3 *>(_data._mem); valid = true; return (*v)[idx]; } } else if (p_index.get_type() == Variant::STRING) { - //scalar name const String *str = reinterpret_cast<const String *>(p_index._data._mem); const Vector3 *v = reinterpret_cast<const Vector3 *>(_data._mem); @@ -2798,20 +2719,17 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } break; case VECTOR3I: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { //scalar index int idx = p_index; if (idx < 0) idx += 3; if (idx >= 0 && idx < 3) { - const Vector3i *v = reinterpret_cast<const Vector3i *>(_data._mem); valid = true; return (*v)[idx]; } } else if (p_index.get_type() == Variant::STRING) { - //scalar name const String *str = reinterpret_cast<const String *>(p_index._data._mem); const Vector3i *v = reinterpret_cast<const Vector3i *>(_data._mem); @@ -2829,9 +2747,7 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } break; case TRANSFORM2D: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { - int index = p_index; if (index < 0) @@ -2843,7 +2759,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { return v->elements[index]; } } else if (p_index.get_type() == Variant::STRING) { - //scalar name const String *str = reinterpret_cast<const String *>(p_index._data._mem); const Transform2D *v = _data._transform2d; @@ -2861,7 +2776,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } break; case PLANE: { - if (p_index.get_type() == Variant::STRING) { //scalar name const String *str = reinterpret_cast<const String *>(p_index._data._mem); @@ -2886,9 +2800,7 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } break; case QUAT: { - if (p_index.get_type() == Variant::STRING) { - const String *str = reinterpret_cast<const String *>(p_index._data._mem); const Quat *v = reinterpret_cast<const Quat *>(_data._mem); if (*str == "x") { @@ -2908,7 +2820,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } break; case AABB: { - if (p_index.get_type() == Variant::STRING) { //scalar name @@ -2927,9 +2838,7 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } } break; case BASIS: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { - int index = p_index; if (index < 0) index += 3; @@ -2940,7 +2849,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { return v->get_axis(index); } } else if (p_index.get_type() == Variant::STRING) { - const String *str = reinterpret_cast<const String *>(p_index._data._mem); const Basis *v = _data._basis; @@ -2958,9 +2866,7 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } break; case TRANSFORM: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { - int index = p_index; if (index < 0) index += 4; @@ -2970,7 +2876,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { return index == 3 ? v->origin : v->basis.get_axis(index); } } else if (p_index.get_type() == Variant::STRING) { - const Transform *v = _data._transform; const String *str = reinterpret_cast<const String *>(p_index._data._mem); @@ -2986,9 +2891,7 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } break; case COLOR: { - if (p_index.get_type() == Variant::STRING) { - const String *str = reinterpret_cast<const String *>(p_index._data._mem); const Color *v = reinterpret_cast<const Color *>(_data._mem); if (*str == "r") { @@ -3026,7 +2929,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { return (int)Math::round(v->a * 255.0); } } else if (p_index.get_type() == Variant::INT) { - int idx = p_index; if (idx < 0) idx += 4; @@ -3047,7 +2949,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { case OBJECT: { Object *obj = _get_obj().obj; if (obj) { - #ifdef DEBUG_ENABLED if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { @@ -3065,7 +2966,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } break; case DICTIONARY: { - const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem); const Variant *res = dic->getptr(p_index); if (res) { @@ -3091,14 +2991,11 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } bool Variant::in(const Variant &p_index, bool *r_valid) const { - if (r_valid) *r_valid = true; switch (type) { - case STRING: { - if (p_index.get_type() == Variant::STRING) { //string index String idx = p_index; @@ -3111,7 +3008,6 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { case OBJECT: { Object *obj = _get_obj().obj; if (obj) { - bool valid = false; #ifdef DEBUG_ENABLED @@ -3138,18 +3034,15 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { return false; } break; case DICTIONARY: { - const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem); return dic->has(p_index); } break; case ARRAY: { - const Array *arr = reinterpret_cast<const Array *>(_data._mem); int l = arr->size(); if (l) { for (int i = 0; i < l; i++) { - if (evaluate(OP_EQUAL, (*arr)[i], p_index)) return true; } @@ -3160,7 +3053,6 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { } break; case PACKED_BYTE_ARRAY: { if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { - int index = p_index; const Vector<uint8_t> *arr = &PackedArrayRef<uint8_t>::get_array(_data.packed_array); int l = arr->size(); @@ -3178,7 +3070,6 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { } break; case PACKED_INT32_ARRAY: { if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { - int32_t index = p_index; const Vector<int32_t> *arr = &PackedArrayRef<int32_t>::get_array(_data.packed_array); int32_t l = arr->size(); @@ -3195,7 +3086,6 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { } break; case PACKED_INT64_ARRAY: { if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { - int64_t index = p_index; const Vector<int64_t> *arr = &PackedArrayRef<int64_t>::get_array(_data.packed_array); int64_t l = arr->size(); @@ -3211,9 +3101,7 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { } } break; case PACKED_FLOAT32_ARRAY: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { - real_t index = p_index; const Vector<float> *arr = &PackedArrayRef<float>::get_array(_data.packed_array); int l = arr->size(); @@ -3230,9 +3118,7 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { } break; case PACKED_FLOAT64_ARRAY: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { - real_t index = p_index; const Vector<double> *arr = &PackedArrayRef<double>::get_array(_data.packed_array); int l = arr->size(); @@ -3250,7 +3136,6 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { } break; case PACKED_STRING_ARRAY: { if (p_index.get_type() == Variant::STRING) { - String index = p_index; const Vector<String> *arr = &PackedArrayRef<String>::get_array(_data.packed_array); @@ -3269,7 +3154,6 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { } break; //25 case PACKED_VECTOR2_ARRAY: { if (p_index.get_type() == Variant::VECTOR2) { - Vector2 index = p_index; const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array); @@ -3288,7 +3172,6 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { } break; case PACKED_VECTOR3_ARRAY: { if (p_index.get_type() == Variant::VECTOR3) { - Vector3 index = p_index; const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array); @@ -3306,9 +3189,7 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { } break; case PACKED_COLOR_ARRAY: { - if (p_index.get_type() == Variant::COLOR) { - Color index = p_index; const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array); @@ -3334,57 +3215,48 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { } void Variant::get_property_list(List<PropertyInfo> *p_list) const { - switch (type) { case VECTOR2: { - p_list->push_back(PropertyInfo(Variant::FLOAT, "x")); p_list->push_back(PropertyInfo(Variant::FLOAT, "y")); } break; case VECTOR2I: { - p_list->push_back(PropertyInfo(Variant::INT, "x")); p_list->push_back(PropertyInfo(Variant::INT, "y")); } break; case RECT2: { - p_list->push_back(PropertyInfo(Variant::VECTOR2, "position")); p_list->push_back(PropertyInfo(Variant::VECTOR2, "size")); p_list->push_back(PropertyInfo(Variant::VECTOR2, "end")); } break; case RECT2I: { - p_list->push_back(PropertyInfo(Variant::VECTOR2I, "position")); p_list->push_back(PropertyInfo(Variant::VECTOR2I, "size")); p_list->push_back(PropertyInfo(Variant::VECTOR2I, "end")); } break; case VECTOR3: { - p_list->push_back(PropertyInfo(Variant::FLOAT, "x")); p_list->push_back(PropertyInfo(Variant::FLOAT, "y")); p_list->push_back(PropertyInfo(Variant::FLOAT, "z")); } break; case VECTOR3I: { - p_list->push_back(PropertyInfo(Variant::INT, "x")); p_list->push_back(PropertyInfo(Variant::INT, "y")); p_list->push_back(PropertyInfo(Variant::INT, "z")); } break; case TRANSFORM2D: { - p_list->push_back(PropertyInfo(Variant::VECTOR2, "x")); p_list->push_back(PropertyInfo(Variant::VECTOR2, "y")); p_list->push_back(PropertyInfo(Variant::VECTOR2, "origin")); } break; case PLANE: { - p_list->push_back(PropertyInfo(Variant::VECTOR3, "normal")); p_list->push_back(PropertyInfo(Variant::FLOAT, "x")); p_list->push_back(PropertyInfo(Variant::FLOAT, "y")); @@ -3393,7 +3265,6 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const { } break; case QUAT: { - p_list->push_back(PropertyInfo(Variant::FLOAT, "x")); p_list->push_back(PropertyInfo(Variant::FLOAT, "y")); p_list->push_back(PropertyInfo(Variant::FLOAT, "z")); @@ -3406,14 +3277,12 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::VECTOR3, "end")); } break; case BASIS: { - p_list->push_back(PropertyInfo(Variant::VECTOR3, "x")); p_list->push_back(PropertyInfo(Variant::VECTOR3, "y")); p_list->push_back(PropertyInfo(Variant::VECTOR3, "z")); } break; case TRANSFORM: { - p_list->push_back(PropertyInfo(Variant::BASIS, "basis")); p_list->push_back(PropertyInfo(Variant::VECTOR3, "origin")); @@ -3439,7 +3308,6 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const { case _RID: { } break; case OBJECT: { - Object *obj = _get_obj().obj; if (obj) { #ifdef DEBUG_ENABLED @@ -3456,7 +3324,6 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const { } break; case DICTIONARY: { - const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem); List<Variant> keys; dic->get_key_list(&keys); @@ -3476,7 +3343,6 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const { case PACKED_VECTOR2_ARRAY: case PACKED_VECTOR3_ARRAY: case PACKED_COLOR_ARRAY: { - //nothing } break; default: { @@ -3485,7 +3351,6 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const { } bool Variant::iter_init(Variant &r_iter, bool &valid) const { - valid = true; switch (type) { case INT: { @@ -3541,7 +3406,6 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { return step < 0; } break; case OBJECT: { - if (!_get_obj().obj) { valid = false; return false; @@ -3573,7 +3437,6 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { } break; case STRING: { - const String *str = reinterpret_cast<const String *>(_data._mem); if (str->empty()) return false; @@ -3581,7 +3444,6 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { return true; } break; case DICTIONARY: { - const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem); if (dic->empty()) return false; @@ -3592,7 +3454,6 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { } break; case ARRAY: { - const Array *arr = reinterpret_cast<const Array *>(_data._mem); if (arr->empty()) return false; @@ -3647,7 +3508,6 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { return true; } break; case PACKED_VECTOR2_ARRAY: { - const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array); if (arr->size() == 0) return false; @@ -3655,7 +3515,6 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { return true; } break; case PACKED_VECTOR3_ARRAY: { - const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array); if (arr->size() == 0) return false; @@ -3663,7 +3522,6 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { return true; } break; case PACKED_COLOR_ARRAY: { - const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array); if (arr->size() == 0) return false; @@ -3679,7 +3537,6 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { return false; } bool Variant::iter_next(Variant &r_iter, bool &valid) const { - valid = true; switch (type) { case INT: { @@ -3755,7 +3612,6 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { return true; } break; case OBJECT: { - if (!_get_obj().obj) { valid = false; return false; @@ -3788,7 +3644,6 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { } break; case STRING: { - const String *str = reinterpret_cast<const String *>(_data._mem); int idx = r_iter; idx++; @@ -3798,7 +3653,6 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { return true; } break; case DICTIONARY: { - const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem); const Variant *next = dic->next(&r_iter); if (!next) @@ -3809,7 +3663,6 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { } break; case ARRAY: { - const Array *arr = reinterpret_cast<const Array *>(_data._mem); int idx = r_iter; idx++; @@ -3878,7 +3731,6 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { return true; } break; case PACKED_VECTOR2_ARRAY: { - const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array); int idx = r_iter; idx++; @@ -3888,7 +3740,6 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { return true; } break; case PACKED_VECTOR3_ARRAY: { - const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array); int idx = r_iter; idx++; @@ -3898,7 +3749,6 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { return true; } break; case PACKED_COLOR_ARRAY: { - const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array); int idx = r_iter; idx++; @@ -3916,35 +3766,27 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { } Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { - r_valid = true; switch (type) { case INT: { - return r_iter; } break; case FLOAT: { - return r_iter; } break; case VECTOR2: { - return r_iter; } break; case VECTOR2I: { - return r_iter; } break; case VECTOR3: { - return r_iter; } break; case VECTOR3I: { - return r_iter; } break; case OBJECT: { - if (!_get_obj().obj) { r_valid = false; return Variant(); @@ -3972,17 +3814,14 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { } break; case STRING: { - const String *str = reinterpret_cast<const String *>(_data._mem); return str->substr(r_iter, 1); } break; case DICTIONARY: { - return r_iter; //iterator is the same as the key } break; case ARRAY: { - const Array *arr = reinterpret_cast<const Array *>(_data._mem); int idx = r_iter; #ifdef DEBUG_ENABLED @@ -4060,7 +3899,6 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { return arr->get(idx); } break; case PACKED_VECTOR2_ARRAY: { - const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array); int idx = r_iter; #ifdef DEBUG_ENABLED @@ -4072,7 +3910,6 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { return arr->get(idx); } break; case PACKED_VECTOR3_ARRAY: { - const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array); int idx = r_iter; #ifdef DEBUG_ENABLED @@ -4084,7 +3921,6 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { return arr->get(idx); } break; case PACKED_COLOR_ARRAY: { - const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array); int idx = r_iter; #ifdef DEBUG_ENABLED @@ -4237,7 +4073,6 @@ void Variant::blend(const Variant &a, const Variant &b, float c, Variant &r_dst) } void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &r_dst) { - if (a.type != b.type) { if (a.is_num() && b.is_num()) { //not as efficient but.. @@ -4252,7 +4087,6 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & } switch (a.type) { - case NIL: { r_dst = Variant(); } @@ -4290,18 +4124,15 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & int split = csize / 2; for (int i = 0; i < csize; i++) { - CharType chr = ' '; if (i < split) { - if (i < sa.length()) chr = sa[i]; else if (i < sb.length()) chr = sb[i]; } else { - if (i < sb.length()) chr = sb[i]; else if (i < sa.length()) @@ -4423,10 +4254,8 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & const Vector<int32_t> *arr_b = &PackedArrayRef<int32_t>::get_array(b._data.packed_array); int32_t sz = arr_a->size(); if (sz == 0 || arr_b->size() != sz) { - r_dst = a; } else { - Vector<int32_t> v; v.resize(sz); { @@ -4449,10 +4278,8 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & const Vector<int64_t> *arr_b = &PackedArrayRef<int64_t>::get_array(b._data.packed_array); int64_t sz = arr_a->size(); if (sz == 0 || arr_b->size() != sz) { - r_dst = a; } else { - Vector<int64_t> v; v.resize(sz); { @@ -4475,10 +4302,8 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & const Vector<float> *arr_b = &PackedArrayRef<float>::get_array(b._data.packed_array); int sz = arr_a->size(); if (sz == 0 || arr_b->size() != sz) { - r_dst = a; } else { - Vector<float> v; v.resize(sz); { @@ -4501,10 +4326,8 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & const Vector<double> *arr_b = &PackedArrayRef<double>::get_array(b._data.packed_array); int sz = arr_a->size(); if (sz == 0 || arr_b->size() != sz) { - r_dst = a; } else { - Vector<double> v; v.resize(sz); { @@ -4531,10 +4354,8 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & const Vector<Vector2> *arr_b = &PackedArrayRef<Vector2>::get_array(b._data.packed_array); int sz = arr_a->size(); if (sz == 0 || arr_b->size() != sz) { - r_dst = a; } else { - Vector<Vector2> v; v.resize(sz); { @@ -4551,15 +4372,12 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & } return; case PACKED_VECTOR3_ARRAY: { - const Vector<Vector3> *arr_a = &PackedArrayRef<Vector3>::get_array(a._data.packed_array); const Vector<Vector3> *arr_b = &PackedArrayRef<Vector3>::get_array(b._data.packed_array); int sz = arr_a->size(); if (sz == 0 || arr_b->size() != sz) { - r_dst = a; } else { - Vector<Vector3> v; v.resize(sz); { @@ -4580,10 +4398,8 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & const Vector<Color> *arr_b = &PackedArrayRef<Color>::get_array(b._data.packed_array); int sz = arr_a->size(); if (sz == 0 || arr_b->size() != sz) { - r_dst = a; } else { - Vector<Color> v; v.resize(sz); { @@ -4600,7 +4416,6 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & } return; default: { - r_dst = a; } } @@ -4636,7 +4451,6 @@ static const char *_op_names[Variant::OP_MAX] = { }; String Variant::get_operator_name(Operator p_op) { - ERR_FAIL_INDEX_V(p_op, OP_MAX, ""); return _op_names[p_op]; } diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index c9678c9933..0184de46ee 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -36,21 +36,17 @@ #include "core/string_buffer.h" CharType VariantParser::StreamFile::get_char() { - return f->get_8(); } bool VariantParser::StreamFile::is_utf8() const { - return true; } bool VariantParser::StreamFile::is_eof() const { - return f->eof_reached(); } CharType VariantParser::StreamString::get_char() { - if (pos > s.length()) { return 0; } else if (pos == s.length()) { @@ -93,11 +89,9 @@ const char *VariantParser::tk_name[TK_MAX] = { }; Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, String &r_err_str) { - bool string_name = false; while (true) { - CharType cchar; if (p_stream->saved) { cchar = p_stream->saved; @@ -111,9 +105,7 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri } switch (cchar) { - case '\n': { - line++; break; }; @@ -122,42 +114,34 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri return OK; } break; case '{': { - r_token.type = TK_CURLY_BRACKET_OPEN; return OK; }; case '}': { - r_token.type = TK_CURLY_BRACKET_CLOSE; return OK; }; case '[': { - r_token.type = TK_BRACKET_OPEN; return OK; }; case ']': { - r_token.type = TK_BRACKET_CLOSE; return OK; }; case '(': { - r_token.type = TK_PARENTHESIS_OPEN; return OK; }; case ')': { - r_token.type = TK_PARENTHESIS_CLOSE; return OK; }; case ':': { - r_token.type = TK_COLON; return OK; }; case ';': { - while (true) { CharType ch = p_stream->get_char(); if (p_stream->is_eof()) { @@ -171,22 +155,18 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri break; }; case ',': { - r_token.type = TK_COMMA; return OK; }; case '.': { - r_token.type = TK_PERIOD; return OK; }; case '=': { - r_token.type = TK_EQUAL; return OK; }; case '#': { - StringBuffer<> color_str; color_str += '#'; while (true) { @@ -219,10 +199,8 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri [[fallthrough]]; } case '"': { - String str; while (true) { - CharType ch = p_stream->get_char(); if (ch == 0) { @@ -242,7 +220,6 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri CharType res = 0; switch (next) { - case 'b': res = 8; break; @@ -268,7 +245,6 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri return ERR_PARSE_ERROR; } if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) { - r_err_str = "Malformed hex constant in string"; r_token.type = TK_ERROR; return ERR_PARSE_ERROR; @@ -321,7 +297,6 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri } break; default: { - if (cchar <= 32) { break; } @@ -348,10 +323,8 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri bool is_float = false; while (true) { - switch (reading) { case READING_INT: { - if (c >= '0' && c <= '9') { //pass } else if (c == '.') { @@ -366,9 +339,7 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri } break; case READING_DEC: { - if (c >= '0' && c <= '9') { - } else if (c == 'e') { reading = READING_EXP; } else { @@ -377,7 +348,6 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri } break; case READING_EXP: { - if (c >= '0' && c <= '9') { exp_beg = true; @@ -407,12 +377,10 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri return OK; } else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') { - StringBuffer<> id; bool first = true; while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && cchar >= '0' && cchar <= '9')) { - id += cchar; cchar = p_stream->get_char(); first = false; @@ -437,7 +405,6 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri } Error VariantParser::_parse_enginecfg(Stream *p_stream, Vector<String> &strings, int &line, String &r_err_str) { - Token token; get_token(p_stream, token, line, r_err_str); if (token.type != TK_PARENTHESIS_OPEN) { @@ -448,7 +415,6 @@ Error VariantParser::_parse_enginecfg(Stream *p_stream, Vector<String> &strings, String accum; while (true) { - CharType c = p_stream->get_char(); if (p_stream->is_eof()) { @@ -470,7 +436,6 @@ Error VariantParser::_parse_enginecfg(Stream *p_stream, Vector<String> &strings, template <class T> Error VariantParser::_parse_construct(Stream *p_stream, Vector<T> &r_construct, int &line, String &r_err_str) { - Token token; get_token(p_stream, token, line, r_err_str); if (token.type != TK_PARENTHESIS_OPEN) { @@ -480,7 +445,6 @@ Error VariantParser::_parse_construct(Stream *p_stream, Vector<T> &r_construct, bool first = true; while (true) { - if (!first) { get_token(p_stream, token, line, r_err_str); if (token.type == TK_COMMA) { @@ -509,7 +473,6 @@ Error VariantParser::_parse_construct(Stream *p_stream, Vector<T> &r_construct, } Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, int &line, String &r_err_str, ResourceParser *p_res_parser) { - /* { Error err = get_token(p_stream,token,line,r_err_str); if (err) @@ -517,7 +480,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, }*/ if (token.type == TK_CURLY_BRACKET_OPEN) { - Dictionary d; Error err = _parse_dictionary(d, p_stream, line, r_err_str, p_res_parser); if (err) @@ -525,7 +487,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = d; return OK; } else if (token.type == TK_BRACKET_OPEN) { - Array a; Error err = _parse_array(a, p_stream, line, r_err_str, p_res_parser); if (err) @@ -534,7 +495,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; } else if (token.type == TK_IDENTIFIER) { - String id = token.value; if (id == "true") value = true; @@ -547,7 +507,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, else if (id == "nan") value = Math_NAN; else if (id == "Vector2") { - Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); if (err) @@ -560,7 +519,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = Vector2(args[0], args[1]); return OK; } else if (id == "Vector2i") { - Vector<int32_t> args; Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str); if (err) @@ -573,7 +531,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = Vector2i(args[0], args[1]); return OK; } else if (id == "Rect2") { - Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); if (err) @@ -586,7 +543,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = Rect2(args[0], args[1], args[2], args[3]); return OK; } else if (id == "Rect2i") { - Vector<int32_t> args; Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str); if (err) @@ -599,7 +555,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = Rect2i(args[0], args[1], args[2], args[3]); return OK; } else if (id == "Vector3") { - Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); if (err) @@ -612,7 +567,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = Vector3(args[0], args[1], args[2]); return OK; } else if (id == "Vector3i") { - Vector<int32_t> args; Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str); if (err) @@ -641,7 +595,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = m; return OK; } else if (id == "Plane") { - Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); if (err) @@ -654,7 +607,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = Plane(args[0], args[1], args[2], args[3]); return OK; } else if (id == "Quat") { - Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); if (err) @@ -668,7 +620,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; } else if (id == "AABB" || id == "Rect3") { - Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); if (err) @@ -695,7 +646,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = Basis(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]); return OK; } else if (id == "Transform") { - Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); if (err) @@ -709,7 +659,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; } else if (id == "Color") { - Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); if (err) @@ -723,7 +672,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; } else if (id == "NodePath") { - get_token(p_stream, token, line, r_err_str); if (token.type != TK_PARENTHESIS_OPEN) { r_err_str = "Expected '('"; @@ -745,7 +693,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } } else if (id == "RID") { - get_token(p_stream, token, line, r_err_str); if (token.type != TK_PARENTHESIS_OPEN) { r_err_str = "Expected '('"; @@ -768,7 +715,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; } else if (id == "Object") { - get_token(p_stream, token, line, r_err_str); if (token.type != TK_PARENTHESIS_OPEN) { r_err_str = "Expected '('"; @@ -803,14 +749,12 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, bool need_comma = false; while (true) { - if (p_stream->is_eof()) { r_err_str = "Unexpected End of File while parsing Object()"; return ERR_FILE_CORRUPT; } if (at_key) { - Error err = get_token(p_stream, token2, line, r_err_str); if (err != OK) return err; @@ -826,9 +770,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } if (need_comma) { - if (token2.type != TK_COMMA) { - r_err_str = "Expected '}' or ','"; return ERR_PARSE_ERROR; } else { @@ -849,13 +791,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, if (err != OK) return err; if (token2.type != TK_COLON) { - r_err_str = "Expected ':'"; return ERR_PARSE_ERROR; } at_key = false; } else { - Error err = get_token(p_stream, token2, line, r_err_str); if (err != OK) return err; @@ -871,7 +811,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } } else if (id == "Resource" || id == "SubResource" || id == "ExtResource") { - get_token(p_stream, token, line, r_err_str); if (token.type != TK_PARENTHESIS_OPEN) { r_err_str = "Expected '('"; @@ -879,7 +818,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } if (p_res_parser && id == "Resource" && p_res_parser->func) { - RES res; Error err = p_res_parser->func(p_res_parser->userdata, p_stream, res, line, r_err_str); if (err) @@ -889,7 +827,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; } else if (p_res_parser && id == "ExtResource" && p_res_parser->ext_func) { - RES res; Error err = p_res_parser->ext_func(p_res_parser->userdata, p_stream, res, line, r_err_str); if (err) @@ -899,7 +836,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; } else if (p_res_parser && id == "SubResource" && p_res_parser->sub_func) { - RES res; Error err = p_res_parser->sub_func(p_res_parser->userdata, p_stream, res, line, r_err_str); if (err) @@ -909,7 +845,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; } else { - get_token(p_stream, token, line, r_err_str); if (token.type == TK_STRING) { String path = token.value; @@ -935,7 +870,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } } else if (id == "PackedByteArray" || id == "PoolByteArray" || id == "ByteArray") { - Vector<uint8_t> args; Error err = _parse_construct<uint8_t>(p_stream, args, line, r_err_str); if (err) @@ -956,7 +890,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; } else if (id == "PackedInt32Array" || id == "PackedIntArray" || id == "PoolIntArray" || id == "IntArray") { - Vector<int32_t> args; Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str); if (err) @@ -977,7 +910,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; } else if (id == "PackedInt64Array") { - Vector<int64_t> args; Error err = _parse_construct<int64_t>(p_stream, args, line, r_err_str); if (err) @@ -998,7 +930,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; } else if (id == "PackedFloat32Array" || id == "PackedRealArray" || id == "PoolRealArray" || id == "FloatArray") { - Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); if (err) @@ -1018,7 +949,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; } else if (id == "PackedFloat64Array") { - Vector<double> args; Error err = _parse_construct<double>(p_stream, args, line, r_err_str); if (err) @@ -1038,7 +968,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; } else if (id == "PackedStringArray" || id == "PoolStringArray" || id == "StringArray") { - get_token(p_stream, token, line, r_err_str); if (token.type != TK_PARENTHESIS_OPEN) { r_err_str = "Expected '('"; @@ -1049,7 +978,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, bool first = true; while (true) { - if (!first) { get_token(p_stream, token, line, r_err_str); if (token.type == TK_COMMA) { @@ -1089,7 +1017,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; } else if (id == "PackedVector2Array" || id == "PoolVector2Array" || id == "Vector2Array") { - Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); if (err) @@ -1110,7 +1037,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; } else if (id == "PackedVector3Array" || id == "PoolVector3Array" || id == "Vector3Array") { - Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); if (err) @@ -1131,7 +1057,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; } else if (id == "PackedColorArray" || id == "PoolColorArray" || id == "ColorArray") { - Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); if (err) @@ -1158,19 +1083,15 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; } else if (token.type == TK_NUMBER) { - value = token.value; return OK; } else if (token.type == TK_STRING) { - value = token.value; return OK; } else if (token.type == TK_STRING_NAME) { - value = token.value; return OK; } else if (token.type == TK_COLOR) { - value = token.value; return OK; } else { @@ -1180,12 +1101,10 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } Error VariantParser::_parse_array(Array &array, Stream *p_stream, int &line, String &r_err_str, ResourceParser *p_res_parser) { - Token token; bool need_comma = false; while (true) { - if (p_stream->is_eof()) { r_err_str = "Unexpected End of File while parsing array"; return ERR_FILE_CORRUPT; @@ -1196,14 +1115,11 @@ Error VariantParser::_parse_array(Array &array, Stream *p_stream, int &line, Str return err; if (token.type == TK_BRACKET_CLOSE) { - return OK; } if (need_comma) { - if (token.type != TK_COMMA) { - r_err_str = "Expected ','"; return ERR_PARSE_ERROR; } else { @@ -1223,34 +1139,28 @@ Error VariantParser::_parse_array(Array &array, Stream *p_stream, int &line, Str } Error VariantParser::_parse_dictionary(Dictionary &object, Stream *p_stream, int &line, String &r_err_str, ResourceParser *p_res_parser) { - bool at_key = true; Variant key; Token token; bool need_comma = false; while (true) { - if (p_stream->is_eof()) { r_err_str = "Unexpected End of File while parsing dictionary"; return ERR_FILE_CORRUPT; } if (at_key) { - Error err = get_token(p_stream, token, line, r_err_str); if (err != OK) return err; if (token.type == TK_CURLY_BRACKET_CLOSE) { - return OK; } if (need_comma) { - if (token.type != TK_COMMA) { - r_err_str = "Expected '}' or ','"; return ERR_PARSE_ERROR; } else { @@ -1269,13 +1179,11 @@ Error VariantParser::_parse_dictionary(Dictionary &object, Stream *p_stream, int if (err != OK) return err; if (token.type != TK_COLON) { - r_err_str = "Expected ':'"; return ERR_PARSE_ERROR; } at_key = false; } else { - Error err = get_token(p_stream, token, line, r_err_str); if (err != OK) return err; @@ -1292,7 +1200,6 @@ Error VariantParser::_parse_dictionary(Dictionary &object, Stream *p_stream, int } Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, ResourceParser *p_res_parser, bool p_simple_tag) { - r_tag.fields.clear(); if (token.type != TK_BRACKET_OPEN) { @@ -1301,12 +1208,10 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin } if (p_simple_tag) { - r_tag.name = ""; r_tag.fields.clear(); while (true) { - CharType c = p_stream->get_char(); if (p_stream->is_eof()) { r_err_str = "Unexpected EOF while parsing simple tag"; @@ -1333,7 +1238,6 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin bool parsing_tag = true; while (true) { - if (p_stream->is_eof()) { r_err_str = "Unexpected End of File while parsing tag: " + r_tag.name; return ERR_FILE_CORRUPT; @@ -1383,7 +1287,6 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin } Error VariantParser::parse_tag(Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, ResourceParser *p_res_parser, bool p_simple_tag) { - Token token; get_token(p_stream, token, line, r_err_str); @@ -1400,13 +1303,11 @@ Error VariantParser::parse_tag(Stream *p_stream, int &line, String &r_err_str, T } Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, String &r_assign, Variant &r_value, ResourceParser *p_res_parser, bool p_simple_tag) { - //assign.. r_assign = ""; String what; while (true) { - CharType c; if (p_stream->saved) { c = p_stream->saved; @@ -1470,7 +1371,6 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r } Error VariantParser::parse(Stream *p_stream, Variant &r_ret, String &r_err_str, int &r_err_line, ResourceParser *p_res_parser) { - Token token; Error err = get_token(p_stream, token, r_err_line, r_err_str); if (err) @@ -1488,7 +1388,6 @@ Error VariantParser::parse(Stream *p_stream, Variant &r_ret, String &r_err_str, //////////////////////////////////////////////////////////////////////////////// static String rtosfix(double p_value) { - if (p_value == 0.0) return "0"; //avoid negative zero (-0) being written, which may annoy git, svn, etc. for changes when they don't exist. else @@ -1496,22 +1395,17 @@ static String rtosfix(double p_value) { } Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_string_func, void *p_store_string_ud, EncodeResourceFunc p_encode_res_func, void *p_encode_res_ud) { - switch (p_variant.get_type()) { - case Variant::NIL: { p_store_string_func(p_store_string_ud, "null"); } break; case Variant::BOOL: { - p_store_string_func(p_store_string_ud, p_variant.operator bool() ? "true" : "false"); } break; case Variant::INT: { - p_store_string_func(p_store_string_ud, itos(p_variant.operator int64_t())); } break; case Variant::FLOAT: { - String s = rtosfix(p_variant.operator real_t()); if (s != "inf" && s != "nan") { if (s.find(".") == -1 && s.find("e") == -1) @@ -1520,69 +1414,57 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str p_store_string_func(p_store_string_ud, s); } break; case Variant::STRING: { - String str = p_variant; str = "\"" + str.c_escape_multiline() + "\""; p_store_string_func(p_store_string_ud, str); } break; case Variant::VECTOR2: { - Vector2 v = p_variant; p_store_string_func(p_store_string_ud, "Vector2( " + rtosfix(v.x) + ", " + rtosfix(v.y) + " )"); } break; case Variant::VECTOR2I: { - Vector2i v = p_variant; p_store_string_func(p_store_string_ud, "Vector2i( " + itos(v.x) + ", " + itos(v.y) + " )"); } break; case Variant::RECT2: { - Rect2 aabb = p_variant; p_store_string_func(p_store_string_ud, "Rect2( " + rtosfix(aabb.position.x) + ", " + rtosfix(aabb.position.y) + ", " + rtosfix(aabb.size.x) + ", " + rtosfix(aabb.size.y) + " )"); } break; case Variant::RECT2I: { - Rect2i aabb = p_variant; p_store_string_func(p_store_string_ud, "Rect2i( " + itos(aabb.position.x) + ", " + itos(aabb.position.y) + ", " + itos(aabb.size.x) + ", " + itos(aabb.size.y) + " )"); } break; case Variant::VECTOR3: { - Vector3 v = p_variant; p_store_string_func(p_store_string_ud, "Vector3( " + rtosfix(v.x) + ", " + rtosfix(v.y) + ", " + rtosfix(v.z) + " )"); } break; case Variant::VECTOR3I: { - Vector3i v = p_variant; p_store_string_func(p_store_string_ud, "Vector3i( " + itos(v.x) + ", " + itos(v.y) + ", " + itos(v.z) + " )"); } break; case Variant::PLANE: { - Plane p = p_variant; p_store_string_func(p_store_string_ud, "Plane( " + rtosfix(p.normal.x) + ", " + rtosfix(p.normal.y) + ", " + rtosfix(p.normal.z) + ", " + rtosfix(p.d) + " )"); } break; case Variant::AABB: { - AABB aabb = p_variant; p_store_string_func(p_store_string_ud, "AABB( " + rtosfix(aabb.position.x) + ", " + rtosfix(aabb.position.y) + ", " + rtosfix(aabb.position.z) + ", " + rtosfix(aabb.size.x) + ", " + rtosfix(aabb.size.y) + ", " + rtosfix(aabb.size.z) + " )"); } break; case Variant::QUAT: { - Quat quat = p_variant; p_store_string_func(p_store_string_ud, "Quat( " + rtosfix(quat.x) + ", " + rtosfix(quat.y) + ", " + rtosfix(quat.z) + ", " + rtosfix(quat.w) + " )"); } break; case Variant::TRANSFORM2D: { - String s = "Transform2D( "; Transform2D m3 = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - if (i != 0 || j != 0) s += ", "; s += rtosfix(m3.elements[i][j]); @@ -1593,12 +1475,10 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str } break; case Variant::BASIS: { - String s = "Basis( "; Basis m3 = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - if (i != 0 || j != 0) s += ", "; s += rtosfix(m3.elements[i][j]); @@ -1609,13 +1489,11 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str } break; case Variant::TRANSFORM: { - String s = "Transform( "; Transform t = p_variant; Basis &m3 = t.basis; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - if (i != 0 || j != 0) s += ", "; s += rtosfix(m3.elements[i][j]); @@ -1629,13 +1507,11 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str // misc types case Variant::COLOR: { - Color c = p_variant; p_store_string_func(p_store_string_ud, "Color( " + rtosfix(c.r) + ", " + rtosfix(c.g) + ", " + rtosfix(c.b) + ", " + rtosfix(c.a) + " )"); } break; case Variant::STRING_NAME: { - String str = p_variant; str = "@\"" + str.c_escape() + "\""; @@ -1643,7 +1519,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str } break; case Variant::NODE_PATH: { - String str = p_variant; str = "NodePath(\"" + str.c_escape() + "\")"; @@ -1652,7 +1527,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str } break; case Variant::OBJECT: { - Object *obj = p_variant; if (!obj) { @@ -1667,13 +1541,11 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str //try external function if (p_encode_res_func) { - res_text = p_encode_res_func(p_encode_res_ud, res); } //try path because it's a file if (res_text == String() && res->get_path().is_resource_file()) { - //external resource String path = res->get_path(); res_text = "Resource( \"" + path + "\")"; @@ -1694,7 +1566,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str obj->get_property_list(&props); bool first = true; for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - if (E->get().usage & PROPERTY_USAGE_STORAGE || E->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE) { //must be serialized @@ -1714,7 +1585,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str } break; case Variant::DICTIONARY: { - Dictionary dict = p_variant; List<Variant> keys; @@ -1723,7 +1593,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str p_store_string_func(p_store_string_ud, "{\n"); for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { - /* if (!_check_type(dict[E->get()])) continue; @@ -1739,12 +1608,10 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str } break; case Variant::ARRAY: { - p_store_string_func(p_store_string_ud, "[ "); Array array = p_variant; int len = array.size(); for (int i = 0; i < len; i++) { - if (i > 0) p_store_string_func(p_store_string_ud, ", "); write(array[i], p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud); @@ -1754,7 +1621,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str } break; case Variant::PACKED_BYTE_ARRAY: { - p_store_string_func(p_store_string_ud, "PackedByteArray( "); String s; Vector<uint8_t> data = p_variant; @@ -1762,7 +1628,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str const uint8_t *ptr = data.ptr(); for (int i = 0; i < len; i++) { - if (i > 0) p_store_string_func(p_store_string_ud, ", "); @@ -1773,14 +1638,12 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str } break; case Variant::PACKED_INT32_ARRAY: { - p_store_string_func(p_store_string_ud, "PackedInt32Array( "); Vector<int32_t> data = p_variant; int32_t len = data.size(); const int32_t *ptr = data.ptr(); for (int32_t i = 0; i < len; i++) { - if (i > 0) p_store_string_func(p_store_string_ud, ", "); @@ -1791,14 +1654,12 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str } break; case Variant::PACKED_INT64_ARRAY: { - p_store_string_func(p_store_string_ud, "PackedInt64Array( "); Vector<int64_t> data = p_variant; int64_t len = data.size(); const int64_t *ptr = data.ptr(); for (int64_t i = 0; i < len; i++) { - if (i > 0) p_store_string_func(p_store_string_ud, ", "); @@ -1809,14 +1670,12 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str } break; case Variant::PACKED_FLOAT32_ARRAY: { - p_store_string_func(p_store_string_ud, "PackedFloat32Array( "); Vector<float> data = p_variant; int len = data.size(); const float *ptr = data.ptr(); for (int i = 0; i < len; i++) { - if (i > 0) p_store_string_func(p_store_string_ud, ", "); p_store_string_func(p_store_string_ud, rtosfix(ptr[i])); @@ -1826,14 +1685,12 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str } break; case Variant::PACKED_FLOAT64_ARRAY: { - p_store_string_func(p_store_string_ud, "PackedFloat64Array( "); Vector<double> data = p_variant; int len = data.size(); const double *ptr = data.ptr(); for (int i = 0; i < len; i++) { - if (i > 0) p_store_string_func(p_store_string_ud, ", "); p_store_string_func(p_store_string_ud, rtosfix(ptr[i])); @@ -1843,7 +1700,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str } break; case Variant::PACKED_STRING_ARRAY: { - p_store_string_func(p_store_string_ud, "PackedStringArray( "); Vector<String> data = p_variant; int len = data.size(); @@ -1853,7 +1709,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str //write_string("\n"); for (int i = 0; i < len; i++) { - if (i > 0) p_store_string_func(p_store_string_ud, ", "); String str = ptr[i]; @@ -1864,14 +1719,12 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str } break; case Variant::PACKED_VECTOR2_ARRAY: { - p_store_string_func(p_store_string_ud, "PackedVector2Array( "); Vector<Vector2> data = p_variant; int len = data.size(); const Vector2 *ptr = data.ptr(); for (int i = 0; i < len; i++) { - if (i > 0) p_store_string_func(p_store_string_ud, ", "); p_store_string_func(p_store_string_ud, rtosfix(ptr[i].x) + ", " + rtosfix(ptr[i].y)); @@ -1881,14 +1734,12 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str } break; case Variant::PACKED_VECTOR3_ARRAY: { - p_store_string_func(p_store_string_ud, "PackedVector3Array( "); Vector<Vector3> data = p_variant; int len = data.size(); const Vector3 *ptr = data.ptr(); for (int i = 0; i < len; i++) { - if (i > 0) p_store_string_func(p_store_string_ud, ", "); p_store_string_func(p_store_string_ud, rtosfix(ptr[i].x) + ", " + rtosfix(ptr[i].y) + ", " + rtosfix(ptr[i].z)); @@ -1898,7 +1749,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str } break; case Variant::PACKED_COLOR_ARRAY: { - p_store_string_func(p_store_string_ud, "PackedColorArray( "); Vector<Color> data = p_variant; @@ -1906,7 +1756,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str const Color *ptr = data.ptr(); for (int i = 0; i < len; i++) { - if (i > 0) p_store_string_func(p_store_string_ud, ", "); @@ -1923,14 +1772,12 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str } static Error _write_to_str(void *ud, const String &p_string) { - String *str = (String *)ud; (*str) += p_string; return OK; } Error VariantWriter::write_to_string(const Variant &p_variant, String &r_string, EncodeResourceFunc p_encode_res_func, void *p_encode_res_ud) { - r_string = String(); return write(p_variant, _write_to_str, &r_string, p_encode_res_func, p_encode_res_ud); diff --git a/core/variant_parser.h b/core/variant_parser.h index af7d55d1b8..b55d7b2df0 100644 --- a/core/variant_parser.h +++ b/core/variant_parser.h @@ -38,7 +38,6 @@ class VariantParser { public: struct Stream { - virtual CharType get_char() = 0; virtual bool is_utf8() const = 0; virtual bool is_eof() const = 0; @@ -50,7 +49,6 @@ public: }; struct StreamFile : public Stream { - FileAccess *f = nullptr; virtual CharType get_char(); @@ -61,7 +59,6 @@ public: }; struct StreamString : public Stream { - String s; int pos = 0; @@ -75,7 +72,6 @@ public: typedef Error (*ParseResourceFunc)(void *p_self, Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str); struct ResourceParser { - void *userdata = nullptr; ParseResourceFunc func; ParseResourceFunc ext_func; @@ -112,13 +108,11 @@ public: }; struct Token { - TokenType type; Variant value; }; struct Tag { - String name; Map<String, Variant> fields; }; diff --git a/core/vector.h b/core/vector.h index 7ab464fe11..4521b29339 100644 --- a/core/vector.h +++ b/core/vector.h @@ -93,7 +93,6 @@ public: template <class C> void sort_custom() { - int len = _cowdata.size(); if (len == 0) return; @@ -104,14 +103,12 @@ public: } void sort() { - sort_custom<_DefaultComparator<T>>(); } void ordered_insert(const T &p_val) { int i; for (i = 0; i < _cowdata.size(); i++) { - if (p_val < operator[](i)) { break; }; @@ -132,7 +129,6 @@ public: } Vector<T> subarray(int p_from, int p_to) const { - if (p_from < 0) { p_from = size() + p_from; } @@ -163,7 +159,6 @@ public: template <class T> void Vector<T>::invert() { - for (int i = 0; i < size() / 2; i++) { T *p = ptrw(); SWAP(p[i], p[size() - i - 1]); @@ -183,7 +178,6 @@ void Vector<T>::append_array(Vector<T> p_other) { template <class T> bool Vector<T>::push_back(T p_elem) { - Error err = resize(size() + 1); ERR_FAIL_COND_V(err, true); set(size() - 1, p_elem); diff --git a/core/vmap.h b/core/vmap.h index 848b5055fa..358b6260a4 100644 --- a/core/vmap.h +++ b/core/vmap.h @@ -38,14 +38,12 @@ template <class T, class V> class VMap { public: struct Pair { - T key; V value; _FORCE_INLINE_ Pair() {} _FORCE_INLINE_ Pair(const T &p_key, const V &p_value) { - key = p_key; value = p_value; } @@ -55,7 +53,6 @@ private: CowData<Pair> _cowdata; _FORCE_INLINE_ int _find(const T &p_val, bool &r_exact) const { - r_exact = false; if (_cowdata.empty()) return 0; @@ -89,7 +86,6 @@ private: } _FORCE_INLINE_ int _find_exact(const T &p_val) const { - if (_cowdata.empty()) return -1; @@ -115,7 +111,6 @@ private: public: int insert(const T &p_key, const V &p_val) { - bool exact; int pos = _find(p_key, exact); if (exact) { @@ -127,12 +122,10 @@ public: } bool has(const T &p_val) const { - return _find_exact(p_val) != -1; } void erase(const T &p_val) { - int pos = _find_exact(p_val); if (pos < 0) return; @@ -140,12 +133,10 @@ public: } int find(const T &p_val) const { - return _find_exact(p_val); } int find_nearest(const T &p_val) const { - bool exact; return _find(p_val, exact); } @@ -154,37 +145,30 @@ public: _FORCE_INLINE_ bool empty() const { return _cowdata.empty(); } const Pair *get_array() const { - return _cowdata.ptr(); } Pair *get_array() { - return _cowdata.ptrw(); } const V &getv(int p_index) const { - return _cowdata.get(p_index).value; } V &getv(int p_index) { - return _cowdata.get_m(p_index).value; } const T &getk(int p_index) const { - return _cowdata.get(p_index).key; } T &getk(int p_index) { - return _cowdata.get_m(p_index).key; } inline const V &operator[](const T &p_key) const { - int pos = _find_exact(p_key); CRASH_COND(pos < 0); @@ -193,7 +177,6 @@ public: } inline V &operator[](const T &p_key) { - int pos = _find_exact(p_key); if (pos < 0) { pos = insert(p_key, V()); diff --git a/core/vset.h b/core/vset.h index b96a115d21..45516bdb05 100644 --- a/core/vset.h +++ b/core/vset.h @@ -36,11 +36,9 @@ template <class T> class VSet { - Vector<T> _data; _FORCE_INLINE_ int _find(const T &p_val, bool &r_exact) const { - r_exact = false; if (_data.empty()) return 0; @@ -75,7 +73,6 @@ class VSet { } _FORCE_INLINE_ int _find_exact(const T &p_val) const { - if (_data.empty()) return -1; @@ -101,7 +98,6 @@ class VSet { public: void insert(const T &p_val) { - bool exact; int pos = _find(p_val, exact); if (exact) @@ -110,12 +106,10 @@ public: } bool has(const T &p_val) const { - return _find_exact(p_val) != -1; } void erase(const T &p_val) { - int pos = _find_exact(p_val); if (pos < 0) return; @@ -123,7 +117,6 @@ public: } int find(const T &p_val) const { - return _find_exact(p_val); } @@ -132,12 +125,10 @@ public: _FORCE_INLINE_ int size() const { return _data.size(); } inline T &operator[](int p_index) { - return _data.write[p_index]; } inline const T &operator[](int p_index) const { - return _data[p_index]; } }; |