diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/extension/gdnative_interface.cpp | 10 | ||||
-rw-r--r-- | core/extension/gdnative_interface.h | 4 | ||||
-rw-r--r-- | core/input/input_map.cpp | 54 | ||||
-rw-r--r-- | core/input/input_map.h | 2 | ||||
-rw-r--r-- | core/math/aabb.cpp | 4 | ||||
-rw-r--r-- | core/math/aabb.h | 4 | ||||
-rw-r--r-- | core/math/delaunay_2d.h | 2 | ||||
-rw-r--r-- | core/math/face3.cpp | 4 | ||||
-rw-r--r-- | core/math/rect2.h | 6 | ||||
-rw-r--r-- | core/math/transform_2d.cpp | 2 | ||||
-rw-r--r-- | core/math/triangle_mesh.cpp | 4 | ||||
-rw-r--r-- | core/math/vector2.cpp | 2 | ||||
-rw-r--r-- | core/object/class_db.cpp | 9 | ||||
-rw-r--r-- | core/object/class_db.h | 1 | ||||
-rw-r--r-- | core/templates/pooled_list.h | 14 | ||||
-rw-r--r-- | core/variant/callable.cpp | 4 | ||||
-rw-r--r-- | core/variant/callable.h | 2 | ||||
-rw-r--r-- | core/variant/variant_call.cpp | 5 | ||||
-rw-r--r-- | core/variant/variant_utility.cpp | 43 |
19 files changed, 119 insertions, 57 deletions
diff --git a/core/extension/gdnative_interface.cpp b/core/extension/gdnative_interface.cpp index b41f74a4bc..ff09b0b86c 100644 --- a/core/extension/gdnative_interface.cpp +++ b/core/extension/gdnative_interface.cpp @@ -854,14 +854,21 @@ static GDNativeMethodBindPtr gdnative_classdb_get_method_bind(const char *p_clas return (GDNativeMethodBindPtr)mb; } -static GDNativeClassConstructor gdnative_classdb_get_constructor(const char *p_classname) { +static GDNativeClassConstructor gdnative_classdb_get_constructor(const char *p_classname, GDNativeExtensionPtr *r_extension) { ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(StringName(p_classname)); if (class_info) { + if (r_extension) { + *r_extension = class_info->native_extension; + } return (GDNativeClassConstructor)class_info->creation_func; } return nullptr; } +static GDNativeObjectPtr gdnative_classdb_construct_object(GDNativeClassConstructor p_constructor, GDNativeExtensionPtr p_extension) { + return (GDNativeObjectPtr)ClassDB::construct_object((Object * (*)()) p_constructor, (ObjectNativeExtension *)p_extension); +} + static void *gdnative_classdb_get_class_tag(const char *p_classname) { ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(p_classname); return class_info ? class_info->class_ptr : nullptr; @@ -1010,6 +1017,7 @@ void gdnative_setup_interface(GDNativeInterface *p_interface) { /* CLASSDB */ gdni.classdb_get_constructor = gdnative_classdb_get_constructor; + gdni.classdb_construct_object = gdnative_classdb_construct_object; gdni.classdb_get_method_bind = gdnative_classdb_get_method_bind; gdni.classdb_get_class_tag = gdnative_classdb_get_class_tag; diff --git a/core/extension/gdnative_interface.h b/core/extension/gdnative_interface.h index df735db9b6..73f78bde54 100644 --- a/core/extension/gdnative_interface.h +++ b/core/extension/gdnative_interface.h @@ -137,6 +137,7 @@ typedef void *GDNativeStringNamePtr; typedef void *GDNativeStringPtr; typedef void *GDNativeObjectPtr; typedef void *GDNativeTypePtr; +typedef void *GDNativeExtensionPtr; typedef void *GDNativeMethodBindPtr; typedef int64_t GDNativeInt; typedef uint8_t GDNativeBool; @@ -431,7 +432,8 @@ typedef struct { /* CLASSDB */ - GDNativeClassConstructor (*classdb_get_constructor)(const char *p_classname); + GDNativeClassConstructor (*classdb_get_constructor)(const char *p_classname, GDNativeExtensionPtr *r_extension); + GDNativeObjectPtr (*classdb_construct_object)(GDNativeClassConstructor p_constructor, GDNativeExtensionPtr p_extension); GDNativeMethodBindPtr (*classdb_get_method_bind)(const char *p_classname, const char *p_methodname, GDNativeInt p_hash); void *(*classdb_get_class_tag)(const char *p_classname); diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp index c6db7be53a..8bec80a99e 100644 --- a/core/input/input_map.cpp +++ b/core/input/input_map.cpp @@ -33,6 +33,7 @@ #include "core/config/project_settings.h" #include "core/input/input.h" #include "core/os/keyboard.h" +#include "core/os/os.h" InputMap *InputMap::singleton = nullptr; @@ -699,34 +700,57 @@ const OrderedHashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { return default_builtin_cache; } -void InputMap::load_default() { +const OrderedHashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins_with_feature_overrides_applied() { + if (default_builtin_with_overrides_cache.size() > 0) { + return default_builtin_with_overrides_cache; + } + OrderedHashMap<String, List<Ref<InputEvent>>> builtins = get_builtins(); - // List of Builtins which have an override for macOS. - Vector<String> macos_builtins; + // Get a list of all built in inputs which are valid overrides for the OS + // Key = builtin name (e.g. ui_accept) + // Value = override/feature names (e.g. macos, if it was defined as "ui_accept.macos" and the platform supports that feature) + Map<String, Vector<String>> builtins_with_overrides; for (OrderedHashMap<String, List<Ref<InputEvent>>>::Element E = builtins.front(); E; E = E.next()) { - if (String(E.key()).ends_with(".macos")) { - // Strip .macos from name: some_input_name.macos -> some_input_name - macos_builtins.push_back(String(E.key()).split(".")[0]); + String fullname = E.key(); + + Vector<String> split = fullname.split("."); + String name = split[0]; + String override_for = split.size() > 1 ? split[1] : String(); + + if (override_for != String() && OS::get_singleton()->has_feature(override_for)) { + builtins_with_overrides[name].push_back(override_for); } } for (OrderedHashMap<String, List<Ref<InputEvent>>>::Element E = builtins.front(); E; E = E.next()) { String fullname = E.key(); - String name = fullname.split(".")[0]; - String override_for = fullname.split(".").size() > 1 ? fullname.split(".")[1] : ""; -#ifdef APPLE_STYLE_KEYS - if (macos_builtins.has(name) && override_for != "macos") { - // Name has `macos` builtin but this particular one is for non-macOS systems - so skip. + Vector<String> split = fullname.split("."); + String name = split[0]; + String override_for = split.size() > 1 ? split[1] : String(); + + if (builtins_with_overrides.has(name) && override_for == String()) { + // Builtin has an override but this particular one is not an override, so skip. continue; } -#else - if (override_for == "macos") { - // Override for macOS - not needed on non-macOS platforms. + + if (override_for != String() && !OS::get_singleton()->has_feature(override_for)) { + // OS does not support this override - skip. continue; } -#endif + + default_builtin_with_overrides_cache.insert(name, E.value()); + } + + return default_builtin_with_overrides_cache; +} + +void InputMap::load_default() { + OrderedHashMap<String, List<Ref<InputEvent>>> builtins = get_builtins_with_feature_overrides_applied(); + + for (OrderedHashMap<String, List<Ref<InputEvent>>>::Element E = builtins.front(); E; E = E.next()) { + String name = E.key(); add_action(name); diff --git a/core/input/input_map.h b/core/input/input_map.h index c724fdb142..8bef722089 100644 --- a/core/input/input_map.h +++ b/core/input/input_map.h @@ -56,6 +56,7 @@ private: mutable OrderedHashMap<StringName, Action> input_map; OrderedHashMap<String, List<Ref<InputEvent>>> default_builtin_cache; + OrderedHashMap<String, List<Ref<InputEvent>>> default_builtin_with_overrides_cache; List<Ref<InputEvent>>::Element *_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool p_exact_match = false, bool *p_pressed = nullptr, float *p_strength = nullptr, float *p_raw_strength = nullptr) const; @@ -93,6 +94,7 @@ public: String get_builtin_display_name(const String &p_name) const; // Use an Ordered Map so insertion order is preserved. We want the elements to be 'grouped' somewhat. const OrderedHashMap<String, List<Ref<InputEvent>>> &get_builtins(); + const OrderedHashMap<String, List<Ref<InputEvent>>> &get_builtins_with_feature_overrides_applied(); InputMap(); ~InputMap(); diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp index 33aa65f15d..51a1309f0e 100644 --- a/core/math/aabb.cpp +++ b/core/math/aabb.cpp @@ -52,8 +52,8 @@ void AABB::merge_with(const AABB &p_aabb) { beg_1 = position; beg_2 = p_aabb.position; - end_1 = Vector3(size.x, size.y, size.z) + beg_1; - end_2 = Vector3(p_aabb.size.x, p_aabb.size.y, p_aabb.size.z) + beg_2; + end_1 = size + beg_1; + end_2 = p_aabb.size + beg_2; min.x = (beg_1.x < beg_2.x) ? beg_1.x : beg_2.x; min.y = (beg_1.y < beg_2.y) ? beg_1.y : beg_2.y; diff --git a/core/math/aabb.h b/core/math/aabb.h index e16246902a..97d92fbe37 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -118,6 +118,10 @@ public: return position + size; } + _FORCE_INLINE_ Vector3 get_center() const { + return position + (size * 0.5); + } + operator String() const; _FORCE_INLINE_ AABB() {} diff --git a/core/math/delaunay_2d.h b/core/math/delaunay_2d.h index 95064e5700..2f80cb5634 100644 --- a/core/math/delaunay_2d.h +++ b/core/math/delaunay_2d.h @@ -101,7 +101,7 @@ public: } float delta_max = MAX(rect.size.width, rect.size.height); - Vector2 center = rect.position + rect.size * 0.5; + Vector2 center = rect.get_center(); points.push_back(Vector2(center.x - 20 * delta_max, center.y - delta_max)); points.push_back(Vector2(center.x, center.y + 20 * delta_max)); diff --git a/core/math/face3.cpp b/core/math/face3.cpp index 9af3f868d2..045ab67ce8 100644 --- a/core/math/face3.cpp +++ b/core/math/face3.cpp @@ -151,8 +151,8 @@ 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); + real_t a = Math::random(0.0, 1.0); + real_t b = Math::random(0.0, 1.0); if (a > b) { SWAP(a, b); } diff --git a/core/math/rect2.h b/core/math/rect2.h index ab0b489b4a..2557959fa2 100644 --- a/core/math/rect2.h +++ b/core/math/rect2.h @@ -46,6 +46,8 @@ struct Rect2 { real_t get_area() const { return size.width * size.height; } + _FORCE_INLINE_ Vector2 get_center() const { return position + (size * 0.5); } + inline bool intersects(const Rect2 &p_rect, const bool p_include_borders = false) const { if (p_include_borders) { if (position.x > (p_rect.position.x + p_rect.size.width)) { @@ -259,7 +261,7 @@ struct Rect2 { } _FORCE_INLINE_ bool intersects_filled_polygon(const Vector2 *p_points, int p_point_count) const { - Vector2 center = position + size * 0.5; + Vector2 center = get_center(); int side_plus = 0; int side_minus = 0; Vector2 end = position + size; @@ -344,6 +346,8 @@ struct Rect2i { int get_area() const { return size.width * size.height; } + _FORCE_INLINE_ Vector2i get_center() const { return position + (size / 2); } + inline bool intersects(const Rect2i &p_rect) const { if (position.x > (p_rect.position.x + p_rect.size.width)) { return false; diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp index 060b619892..496a557844 100644 --- a/core/math/transform_2d.cpp +++ b/core/math/transform_2d.cpp @@ -279,7 +279,7 @@ Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, const } //construct matrix - Transform2D res(Math::atan2(v.y, v.x), p1.lerp(p2, p_c)); + Transform2D res(v.angle(), p1.lerp(p2, p_c)); res.scale_basis(s1.lerp(s2, p_c)); return res; } diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp index bf06c848c5..16d9652ef2 100644 --- a/core/math/triangle_mesh.cpp +++ b/core/math/triangle_mesh.cpp @@ -76,7 +76,7 @@ int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, in int index = r_max_alloc++; BVH *_new = &p_bvh[index]; _new->aabb = aabb; - _new->center = aabb.position + aabb.size * 0.5; + _new->center = aabb.get_center(); _new->face_index = -1; _new->left = left; _new->right = right; @@ -152,7 +152,7 @@ void TriangleMesh::create(const Vector<Vector3> &p_faces) { bw[i].left = -1; bw[i].right = -1; bw[i].face_index = i; - bw[i].center = bw[i].aabb.position + bw[i].aabb.size * 0.5; + bw[i].center = bw[i].aabb.get_center(); } vertices.resize(db.size()); diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp index b53dc05a00..16e43d7d06 100644 --- a/core/math/vector2.cpp +++ b/core/math/vector2.cpp @@ -79,7 +79,7 @@ real_t Vector2::angle_to(const Vector2 &p_vector2) const { } real_t Vector2::angle_to_point(const Vector2 &p_vector2) const { - return Math::atan2(y - p_vector2.y, x - p_vector2.x); + return (*this - p_vector2).angle(); } real_t Vector2::dot(const Vector2 &p_other) const { diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index 8e92340c1e..8ba46e49eb 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -545,6 +545,15 @@ Object *ClassDB::instantiate(const StringName &p_class) { return ti->creation_func(); } +Object *ClassDB::construct_object(Object *(*p_create_func)(), ObjectNativeExtension *p_extension) { + if (p_extension) { + initializing_with_extension = true; + initializing_extension = p_extension; + initializing_extension_instance = p_extension->create_instance(p_extension->class_userdata); + } + return p_create_func(); +} + bool ClassDB::can_instantiate(const StringName &p_class) { OBJTYPE_RLOCK; diff --git a/core/object/class_db.h b/core/object/class_db.h index e89c7fffd7..3a1cbf8559 100644 --- a/core/object/class_db.h +++ b/core/object/class_db.h @@ -234,6 +234,7 @@ public: static bool is_parent_class(const StringName &p_class, const StringName &p_inherits); static bool can_instantiate(const StringName &p_class); static Object *instantiate(const StringName &p_class); + static Object *construct_object(Object *(*p_create_func)(), ObjectNativeExtension *p_extension); static void instance_get_native_extension_data(ObjectNativeExtension **r_extension, GDExtensionClassInstancePtr *r_extension_instance, Object *p_base); static APIType get_api_type(const StringName &p_class); diff --git a/core/templates/pooled_list.h b/core/templates/pooled_list.h index b4a6d2d1dd..b139dadb75 100644 --- a/core/templates/pooled_list.h +++ b/core/templates/pooled_list.h @@ -28,13 +28,16 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#pragma once +#ifndef POOLED_LIST_H +#define POOLED_LIST_H + +#include "core/templates/local_vector.h" // Simple template to provide a pool with O(1) allocate and free. // The freelist could alternatively be a linked list placed within the unused elements // to use less memory, however a separate freelist is probably more cache friendly. - -// NOTE : Take great care when using this with non POD types. The construction and destruction +// +// NOTE: Take great care when using this with non POD types. The construction and destruction // is done in the LocalVector, NOT as part of the pool. So requesting a new item does not guarantee // a constructor is run, and free does not guarantee a destructor. // You should generally handle clearing @@ -42,9 +45,6 @@ // This is by design for fastest use in the BVH. If you want a more general pool // that does call constructors / destructors on request / free, this should probably be // a separate template. - -#include "core/templates/local_vector.h" - template <class T, bool force_trivial = false> class PooledList { LocalVector<T, uint32_t, force_trivial> list; @@ -93,3 +93,5 @@ public: _used_size--; } }; + +#endif // POOLED_LIST_H diff --git a/core/variant/callable.cpp b/core/variant/callable.cpp index f487e718f4..dcded6e61f 100644 --- a/core/variant/callable.cpp +++ b/core/variant/callable.cpp @@ -377,11 +377,11 @@ 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) { +Error Signal::connect(const Callable &p_callable, uint32_t p_flags) { Object *object = get_object(); ERR_FAIL_COND_V(!object, ERR_UNCONFIGURED); - return object->connect(name, p_callable, p_binds, p_flags); + return object->connect(name, p_callable, varray(), p_flags); } void Signal::disconnect(const Callable &p_callable) { diff --git a/core/variant/callable.h b/core/variant/callable.h index 52094af3aa..de886492ea 100644 --- a/core/variant/callable.h +++ b/core/variant/callable.h @@ -159,7 +159,7 @@ public: operator String() const; Error emit(const Variant **p_arguments, int p_argcount) const; - Error connect(const Callable &p_callable, const Vector<Variant> &p_binds = Vector<Variant>(), uint32_t p_flags = 0); + Error connect(const Callable &p_callable, uint32_t p_flags = 0); void disconnect(const Callable &p_callable); bool is_connected(const Callable &p_callable) const; diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 4a7d6761d8..32d6778a2b 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1513,6 +1513,7 @@ static void _register_variant_builtin_methods() { /* Rect2 */ + bind_method(Rect2, get_center, sarray(), varray()); bind_method(Rect2, get_area, sarray(), varray()); bind_method(Rect2, has_no_area, sarray(), varray()); bind_method(Rect2, has_point, sarray("point"), varray()); @@ -1529,6 +1530,7 @@ static void _register_variant_builtin_methods() { /* Rect2i */ + bind_method(Rect2i, get_center, sarray(), varray()); bind_method(Rect2i, get_area, sarray(), varray()); bind_method(Rect2i, has_no_area, sarray(), varray()); bind_method(Rect2i, has_point, sarray("point"), varray()); @@ -1688,7 +1690,7 @@ static void _register_variant_builtin_methods() { bind_method(Signal, get_object_id, sarray(), varray()); bind_method(Signal, get_name, sarray(), varray()); - bind_method(Signal, connect, sarray("callable", "binds", "flags"), varray(Array(), 0)); + bind_method(Signal, connect, sarray("callable", "flags"), varray(0)); bind_method(Signal, disconnect, sarray("callable"), varray()); bind_method(Signal, is_connected, sarray("callable"), varray()); bind_method(Signal, get_connections, sarray(), varray()); @@ -1739,6 +1741,7 @@ static void _register_variant_builtin_methods() { /* AABB */ bind_method(AABB, abs, sarray(), varray()); + bind_method(AABB, get_center, sarray(), varray()); bind_method(AABB, get_area, sarray(), varray()); bind_method(AABB, has_no_area, sarray(), varray()); bind_method(AABB, has_no_surface, sarray(), varray()); diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp index 232054d0ca..55c1376031 100644 --- a/core/variant/variant_utility.cpp +++ b/core/variant/variant_utility.cpp @@ -487,10 +487,6 @@ struct VariantUtilityFunctions { } static inline void print(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { - if (p_arg_count < 1) { - r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = 1; - } String str; for (int i = 0; i < p_arg_count; i++) { String os = p_args[i]->operator String(); @@ -506,11 +502,29 @@ struct VariantUtilityFunctions { r_error.error = Callable::CallError::CALL_OK; } - static inline void printerr(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { - if (p_arg_count < 1) { - r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = 1; + static inline void print_verbose(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { + if (OS::get_singleton()->is_stdout_verbose()) { + String str; + for (int i = 0; i < p_arg_count; i++) { + String os = p_args[i]->operator String(); + + if (i == 0) { + str = os; + } else { + str += os; + } + } + + // No need to use `print_verbose()` as this call already only happens + // when verbose mode is enabled. This avoids performing string argument concatenation + // when not needed. + print_line(str); } + + r_error.error = Callable::CallError::CALL_OK; + } + + static inline void printerr(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { String str; for (int i = 0; i < p_arg_count; i++) { String os = p_args[i]->operator String(); @@ -527,10 +541,6 @@ struct VariantUtilityFunctions { } static inline void printt(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { - if (p_arg_count < 1) { - r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = 1; - } String str; for (int i = 0; i < p_arg_count; i++) { if (i) { @@ -544,10 +554,6 @@ struct VariantUtilityFunctions { } static inline void prints(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { - if (p_arg_count < 1) { - r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = 1; - } String str; for (int i = 0; i < p_arg_count; i++) { if (i) { @@ -561,10 +567,6 @@ struct VariantUtilityFunctions { } static inline void printraw(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { - if (p_arg_count < 1) { - r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = 1; - } String str; for (int i = 0; i < p_arg_count; i++) { String os = p_args[i]->operator String(); @@ -1246,6 +1248,7 @@ void Variant::_register_variant_utility_functions() { FUNCBINDVARARGV(printt, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL); FUNCBINDVARARGV(prints, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL); FUNCBINDVARARGV(printraw, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL); + FUNCBINDVARARGV(print_verbose, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL); FUNCBINDVARARGV(push_error, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL); FUNCBINDVARARGV(push_warning, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL); |