From abca497b7223eed94ae4cbd65119ddfce7941027 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Mon, 28 Nov 2022 14:47:55 +0200 Subject: [PATCH] Expose some low level functions and String operators. --- binding_generator.py | 111 ++- gdextension/extension_api.json | 1167 ++++------------------- gdextension/gdextension_interface.h | 20 + include/godot_cpp/core/math.hpp | 216 ++++- include/godot_cpp/templates/cowdata.hpp | 4 +- include/godot_cpp/variant/variant.hpp | 12 + src/classes/low_level.cpp | 58 ++ src/variant/char_string.cpp | 49 +- test/demo/main.gd | 9 + test/src/example.cpp | 24 + test/src/example.h | 2 + 11 files changed, 623 insertions(+), 1049 deletions(-) create mode 100644 src/classes/low_level.cpp diff --git a/binding_generator.py b/binding_generator.py index e5bb84e5..f0bee593 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -367,6 +367,15 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl result.append("#include ") result.append("#include ") + if class_name == "PackedStringArray": + result.append("#include ") + if class_name == "PackedColorArray": + result.append("#include ") + if class_name == "PackedVector2Array": + result.append("#include ") + if class_name == "PackedVector3Array": + result.append("#include ") + if class_name == "Array": result.append("#include ") @@ -584,10 +593,17 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl result.append("\tbool operator!=(const wchar_t *p_str) const;") result.append("\tbool operator!=(const char16_t *p_str) const;") result.append("\tbool operator!=(const char32_t *p_str) const;") - result.append("\tString operator+(const char *p_chr);") - result.append("\tString operator+(const wchar_t *p_chr);") - result.append("\tString operator+(const char16_t *p_chr);") - result.append("\tString operator+(const char32_t *p_chr);") + result.append("\tString operator+(const char *p_str);") + result.append("\tString operator+(const wchar_t *p_str);") + result.append("\tString operator+(const char16_t *p_str);") + result.append("\tString operator+(const char32_t *p_str);") + result.append("\tString operator+(char32_t p_char);") + result.append("\tString &operator+=(const String &p_str);") + result.append("\tString &operator+=(char32_t p_char);") + result.append("\tString &operator+=(const char *p_str);") + result.append("\tString &operator+=(const wchar_t *p_str);") + result.append("\tString &operator+=(const char32_t *p_str);") + result.append("\tconst char32_t &operator[](int p_index) const;") result.append("\tchar32_t &operator[](int p_index);") result.append("\tconst char32_t *ptr() const;") @@ -611,6 +627,72 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl result.append(f"\t" + return_type + f" &operator[](int p_index);") result.append(f"\tconst " + return_type + f" *ptr() const;") result.append(f"\t" + return_type + f" *ptrw();") + iterators = """ + struct Iterator { + _FORCE_INLINE_ $TYPE &operator*() const { + return *elem_ptr; + } + _FORCE_INLINE_ $TYPE *operator->() const { return elem_ptr; } + _FORCE_INLINE_ Iterator &operator++() { + elem_ptr++; + return *this; + } + _FORCE_INLINE_ Iterator &operator--() { + elem_ptr--; + return *this; + } + + _FORCE_INLINE_ bool operator==(const Iterator &b) const { return elem_ptr == b.elem_ptr; } + _FORCE_INLINE_ bool operator!=(const Iterator &b) const { return elem_ptr != b.elem_ptr; } + + Iterator($TYPE *p_ptr) { elem_ptr = p_ptr; } + Iterator() {} + Iterator(const Iterator &p_it) { elem_ptr = p_it.elem_ptr; } + + private: + $TYPE *elem_ptr = nullptr; + }; + + struct ConstIterator { + _FORCE_INLINE_ const $TYPE &operator*() const { + return *elem_ptr; + } + _FORCE_INLINE_ const $TYPE *operator->() const { return elem_ptr; } + _FORCE_INLINE_ ConstIterator &operator++() { + elem_ptr++; + return *this; + } + _FORCE_INLINE_ ConstIterator &operator--() { + elem_ptr--; + return *this; + } + + _FORCE_INLINE_ bool operator==(const ConstIterator &b) const { return elem_ptr == b.elem_ptr; } + _FORCE_INLINE_ bool operator!=(const ConstIterator &b) const { return elem_ptr != b.elem_ptr; } + + ConstIterator(const $TYPE *p_ptr) { elem_ptr = p_ptr; } + ConstIterator() {} + ConstIterator(const ConstIterator &p_it) { elem_ptr = p_it.elem_ptr; } + + private: + const $TYPE *elem_ptr = nullptr; + }; + + _FORCE_INLINE_ Iterator begin() { + return Iterator(ptrw()); + } + _FORCE_INLINE_ Iterator end() { + return Iterator(ptrw() + size()); + } + + _FORCE_INLINE_ ConstIterator begin() const { + return ConstIterator(ptr()); + } + _FORCE_INLINE_ ConstIterator end() const { + return ConstIterator(ptr() + size()); + } +""" + result.append(iterators.replace("$TYPE", return_type)) if class_name == "Array": result.append(f"\tconst Variant &operator[](int p_index) const;") @@ -636,6 +718,7 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl result.append("String operator+(const wchar_t *p_chr, const String &p_str);") result.append("String operator+(const char16_t *p_chr, const String &p_str);") result.append("String operator+(const char32_t *p_chr, const String &p_str);") + result.append("String operator+(char32_t p_char, const String &p_str);") result.append("String itos(int64_t p_val);") result.append("String uitos(uint64_t p_val);") @@ -1252,6 +1335,26 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us result.append("public:") # Special cases. + if class_name == "XMLParser": + result.append("\tError _open_buffer(const uint8_t *p_buffer, size_t p_size);") + + if class_name == "FileAccess": + result.append("\tuint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const;") + result.append("\tvoid store_buffer(const uint8_t *p_src, uint64_t p_length);") + + if class_name == "WorkerThreadPool": + result.append("\tenum {") + result.append("\tINVALID_TASK_ID = -1") + result.append("\t};") + result.append("\ttypedef int64_t TaskID;") + result.append("\ttypedef int64_t GroupID;") + result.append( + "\tTaskID add_native_task(void (*p_func)(void *), void *p_userdata, bool p_high_priority = false, const String &p_description = String());" + ) + result.append( + "\tGroupID add_native_group_task(void (*p_func)(void *, uint32_t), void *p_userdata, int p_elements, int p_tasks = -1, bool p_high_priority = false, const String &p_description = String());" + ) + if class_name == "Object": result.append("") diff --git a/gdextension/extension_api.json b/gdextension/extension_api.json index 7c014539..a54aefb5 100644 --- a/gdextension/extension_api.json +++ b/gdextension/extension_api.json @@ -3,9 +3,9 @@ "version_major": 4, "version_minor": 0, "version_patch": 0, - "version_status": "beta13", - "version_build": "official", - "version_full_name": "Godot Engine v4.0.beta13.official" + "version_status": "beta", + "version_build": "custom_build", + "version_full_name": "Godot Engine v4.0.beta.custom_build" }, "builtin_class_sizes": [ { @@ -1921,6 +1921,7 @@ "global_enums": [ { "name": "Side", + "is_bitfield": false, "values": [ { "name": "SIDE_LEFT", @@ -1942,6 +1943,7 @@ }, { "name": "Corner", + "is_bitfield": false, "values": [ { "name": "CORNER_TOP_LEFT", @@ -1963,6 +1965,7 @@ }, { "name": "Orientation", + "is_bitfield": false, "values": [ { "name": "VERTICAL", @@ -1976,6 +1979,7 @@ }, { "name": "ClockDirection", + "is_bitfield": false, "values": [ { "name": "CLOCKWISE", @@ -1989,6 +1993,7 @@ }, { "name": "HorizontalAlignment", + "is_bitfield": false, "values": [ { "name": "HORIZONTAL_ALIGNMENT_LEFT", @@ -2010,6 +2015,7 @@ }, { "name": "VerticalAlignment", + "is_bitfield": false, "values": [ { "name": "VERTICAL_ALIGNMENT_TOP", @@ -2031,6 +2037,7 @@ }, { "name": "InlineAlignment", + "is_bitfield": false, "values": [ { "name": "INLINE_ALIGNMENT_TOP_TO", @@ -2088,6 +2095,7 @@ }, { "name": "EulerOrder", + "is_bitfield": false, "values": [ { "name": "EULER_ORDER_XYZ", @@ -2117,6 +2125,7 @@ }, { "name": "Key", + "is_bitfield": false, "values": [ { "name": "KEY_NONE", @@ -3174,6 +3183,7 @@ }, { "name": "KeyModifierMask", + "is_bitfield": true, "values": [ { "name": "KEY_CODE_MASK", @@ -3215,6 +3225,7 @@ }, { "name": "MouseButton", + "is_bitfield": false, "values": [ { "name": "MOUSE_BUTTON_NONE", @@ -3260,6 +3271,7 @@ }, { "name": "MouseButtonMask", + "is_bitfield": true, "values": [ { "name": "MOUSE_BUTTON_MASK_LEFT", @@ -3285,6 +3297,7 @@ }, { "name": "JoyButton", + "is_bitfield": false, "values": [ { "name": "JOY_BUTTON_INVALID", @@ -3386,6 +3399,7 @@ }, { "name": "JoyAxis", + "is_bitfield": false, "values": [ { "name": "JOY_AXIS_INVALID", @@ -3427,6 +3441,7 @@ }, { "name": "MIDIMessage", + "is_bitfield": false, "values": [ { "name": "MIDI_MESSAGE_NONE", @@ -3508,6 +3523,7 @@ }, { "name": "Error", + "is_bitfield": false, "values": [ { "name": "OK", @@ -3709,6 +3725,7 @@ }, { "name": "PropertyHint", + "is_bitfield": false, "values": [ { "name": "PROPERTY_HINT_NONE", @@ -3866,6 +3883,7 @@ }, { "name": "PropertyUsageFlags", + "is_bitfield": true, "values": [ { "name": "PROPERTY_USAGE_NONE", @@ -3991,6 +4009,7 @@ }, { "name": "MethodFlags", + "is_bitfield": true, "values": [ { "name": "METHOD_FLAG_NORMAL", @@ -4028,6 +4047,7 @@ }, { "name": "Variant.Type", + "is_bitfield": false, "values": [ { "name": "TYPE_NIL", @@ -4189,6 +4209,7 @@ }, { "name": "Variant.Operator", + "is_bitfield": false, "values": [ { "name": "OP_EQUAL", @@ -31065,7 +31086,14 @@ "is_vararg": false, "is_static": false, "is_virtual": false, - "hash": 3218959716 + "hash": 107499316, + "arguments": [ + { + "name": "keep_state", + "type": "bool", + "default_value": "false" + } + ] }, { "name": "is_playing", @@ -59804,14 +59832,6 @@ "is_virtual": false, "hash": 3218959716 }, - { - "name": "do_unindent", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3218959716 - }, { "name": "indent_lines", "is_const": false, @@ -75132,6 +75152,13 @@ } ] }, + { + "name": "DisplayServerMacOS", + "is_refcounted": false, + "is_instantiable": false, + "inherits": "DisplayServer", + "api_type": "core" + }, { "name": "ENetConnection", "is_refcounted": true, @@ -77488,14 +77515,6 @@ } ] }, - { - "name": "update_script_classes", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3218959716 - }, { "name": "reimport_files", "is_const": false, @@ -93206,6 +93225,13 @@ } ] }, + { + "name": "FramebufferCacheRD", + "is_refcounted": false, + "is_instantiable": false, + "inherits": "Object", + "api_type": "core" + }, { "name": "GDExtension", "is_refcounted": true, @@ -139231,6 +139257,23 @@ "meta": "int32" } }, + { + "name": "has_environment", + "is_const": true, + "is_vararg": false, + "is_static": false, + "is_virtual": false, + "hash": 3927539163, + "return_value": { + "type": "bool" + }, + "arguments": [ + { + "name": "variable", + "type": "String" + } + ] + }, { "name": "get_environment", "is_const": true, @@ -139254,10 +139297,7 @@ "is_vararg": false, "is_static": false, "is_virtual": false, - "hash": 820780508, - "return_value": { - "type": "bool" - }, + "hash": 3605043004, "arguments": [ { "name": "variable", @@ -139270,15 +139310,12 @@ ] }, { - "name": "has_environment", + "name": "unset_environment", "is_const": true, "is_vararg": false, "is_static": false, "is_virtual": false, - "hash": 3927539163, - "return_value": { - "type": "bool" - }, + "hash": 3089850668, "arguments": [ { "name": "variable", @@ -141030,958 +141067,6 @@ } ] }, - { - "name": "OpenXRAction", - "is_refcounted": true, - "is_instantiable": true, - "inherits": "Resource", - "api_type": "core", - "enums": [ - { - "name": "ActionType", - "is_bitfield": false, - "values": [ - { - "name": "OPENXR_ACTION_BOOL", - "value": 0 - }, - { - "name": "OPENXR_ACTION_FLOAT", - "value": 1 - }, - { - "name": "OPENXR_ACTION_VECTOR2", - "value": 2 - }, - { - "name": "OPENXR_ACTION_POSE", - "value": 3 - } - ] - } - ], - "methods": [ - { - "name": "set_localized_name", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 83702148, - "arguments": [ - { - "name": "localized_name", - "type": "String" - } - ] - }, - { - "name": "get_localized_name", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 201670096, - "return_value": { - "type": "String" - } - }, - { - "name": "set_action_type", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 1675238366, - "arguments": [ - { - "name": "action_type", - "type": "enum::OpenXRAction.ActionType" - } - ] - }, - { - "name": "get_action_type", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3536542431, - "return_value": { - "type": "enum::OpenXRAction.ActionType" - } - }, - { - "name": "set_toplevel_paths", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 4015028928, - "arguments": [ - { - "name": "toplevel_paths", - "type": "PackedStringArray" - } - ] - }, - { - "name": "get_toplevel_paths", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 1139954409, - "return_value": { - "type": "PackedStringArray" - } - } - ], - "properties": [ - { - "type": "String", - "name": "localized_name", - "setter": "set_localized_name", - "getter": "get_localized_name" - }, - { - "type": "int", - "name": "action_type", - "setter": "set_action_type", - "getter": "get_action_type" - }, - { - "type": "PackedStringArray", - "name": "toplevel_paths", - "setter": "set_toplevel_paths", - "getter": "get_toplevel_paths" - } - ] - }, - { - "name": "OpenXRActionMap", - "is_refcounted": true, - "is_instantiable": true, - "inherits": "Resource", - "api_type": "core", - "methods": [ - { - "name": "set_action_sets", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 381264803, - "arguments": [ - { - "name": "action_sets", - "type": "Array" - } - ] - }, - { - "name": "get_action_sets", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3995934104, - "return_value": { - "type": "Array" - } - }, - { - "name": "get_action_set_count", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3905245786, - "return_value": { - "type": "int", - "meta": "int32" - } - }, - { - "name": "find_action_set", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 1888809267, - "return_value": { - "type": "OpenXRActionSet" - }, - "arguments": [ - { - "name": "name", - "type": "String" - } - ] - }, - { - "name": "get_action_set", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 1789580336, - "return_value": { - "type": "OpenXRActionSet" - }, - "arguments": [ - { - "name": "idx", - "type": "int", - "meta": "int32" - } - ] - }, - { - "name": "add_action_set", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 2093310581, - "arguments": [ - { - "name": "action_set", - "type": "OpenXRActionSet" - } - ] - }, - { - "name": "remove_action_set", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 2093310581, - "arguments": [ - { - "name": "action_set", - "type": "OpenXRActionSet" - } - ] - }, - { - "name": "set_interaction_profiles", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 381264803, - "arguments": [ - { - "name": "interaction_profiles", - "type": "Array" - } - ] - }, - { - "name": "get_interaction_profiles", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3995934104, - "return_value": { - "type": "Array" - } - }, - { - "name": "get_interaction_profile_count", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3905245786, - "return_value": { - "type": "int", - "meta": "int32" - } - }, - { - "name": "find_interaction_profile", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3095875538, - "return_value": { - "type": "OpenXRInteractionProfile" - }, - "arguments": [ - { - "name": "name", - "type": "String" - } - ] - }, - { - "name": "get_interaction_profile", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 2546151210, - "return_value": { - "type": "OpenXRInteractionProfile" - }, - "arguments": [ - { - "name": "idx", - "type": "int", - "meta": "int32" - } - ] - }, - { - "name": "add_interaction_profile", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 2697953512, - "arguments": [ - { - "name": "interaction_profile", - "type": "OpenXRInteractionProfile" - } - ] - }, - { - "name": "remove_interaction_profile", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 2697953512, - "arguments": [ - { - "name": "interaction_profile", - "type": "OpenXRInteractionProfile" - } - ] - }, - { - "name": "create_default_action_sets", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3218959716 - } - ], - "properties": [ - { - "type": "OpenXRActionSet", - "name": "action_sets", - "setter": "set_action_sets", - "getter": "get_action_sets" - }, - { - "type": "OpenXRInteractionProfile", - "name": "interaction_profiles", - "setter": "set_interaction_profiles", - "getter": "get_interaction_profiles" - } - ] - }, - { - "name": "OpenXRActionSet", - "is_refcounted": true, - "is_instantiable": true, - "inherits": "Resource", - "api_type": "core", - "methods": [ - { - "name": "set_localized_name", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 83702148, - "arguments": [ - { - "name": "localized_name", - "type": "String" - } - ] - }, - { - "name": "get_localized_name", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 201670096, - "return_value": { - "type": "String" - } - }, - { - "name": "set_priority", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 1286410249, - "arguments": [ - { - "name": "priority", - "type": "int", - "meta": "int32" - } - ] - }, - { - "name": "get_priority", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3905245786, - "return_value": { - "type": "int", - "meta": "int32" - } - }, - { - "name": "get_action_count", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3905245786, - "return_value": { - "type": "int", - "meta": "int32" - } - }, - { - "name": "set_actions", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 381264803, - "arguments": [ - { - "name": "actions", - "type": "Array" - } - ] - }, - { - "name": "get_actions", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3995934104, - "return_value": { - "type": "Array" - } - }, - { - "name": "add_action", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 349361333, - "arguments": [ - { - "name": "action", - "type": "OpenXRAction" - } - ] - }, - { - "name": "remove_action", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 349361333, - "arguments": [ - { - "name": "action", - "type": "OpenXRAction" - } - ] - } - ], - "properties": [ - { - "type": "String", - "name": "localized_name", - "setter": "set_localized_name", - "getter": "get_localized_name" - }, - { - "type": "int", - "name": "priority", - "setter": "set_priority", - "getter": "get_priority" - }, - { - "type": "OpenXRAction", - "name": "actions", - "setter": "set_actions", - "getter": "get_actions" - } - ] - }, - { - "name": "OpenXRHand", - "is_refcounted": false, - "is_instantiable": true, - "inherits": "Node3D", - "api_type": "core", - "enums": [ - { - "name": "Hands", - "is_bitfield": false, - "values": [ - { - "name": "HAND_LEFT", - "value": 0 - }, - { - "name": "HAND_RIGHT", - "value": 1 - }, - { - "name": "HAND_MAX", - "value": 2 - } - ] - }, - { - "name": "MotionRange", - "is_bitfield": false, - "values": [ - { - "name": "MOTION_RANGE_UNOBSTRUCTED", - "value": 0 - }, - { - "name": "MOTION_RANGE_CONFORM_TO_CONTROLLER", - "value": 1 - }, - { - "name": "MOTION_RANGE_MAX", - "value": 2 - } - ] - } - ], - "methods": [ - { - "name": "set_hand", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 1849328560, - "arguments": [ - { - "name": "hand", - "type": "enum::OpenXRHand.Hands" - } - ] - }, - { - "name": "get_hand", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 2850644561, - "return_value": { - "type": "enum::OpenXRHand.Hands" - } - }, - { - "name": "set_hand_skeleton", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 1348162250, - "arguments": [ - { - "name": "hand_skeleton", - "type": "NodePath" - } - ] - }, - { - "name": "get_hand_skeleton", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 4075236667, - "return_value": { - "type": "NodePath" - } - }, - { - "name": "set_motion_range", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3326516003, - "arguments": [ - { - "name": "motion_range", - "type": "enum::OpenXRHand.MotionRange" - } - ] - }, - { - "name": "get_motion_range", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 2191822314, - "return_value": { - "type": "enum::OpenXRHand.MotionRange" - } - } - ], - "properties": [ - { - "type": "int", - "name": "hand", - "setter": "set_hand", - "getter": "get_hand" - }, - { - "type": "int", - "name": "motion_range", - "setter": "set_motion_range", - "getter": "get_motion_range" - }, - { - "type": "NodePath", - "name": "hand_skeleton", - "setter": "set_hand_skeleton", - "getter": "get_hand_skeleton" - } - ] - }, - { - "name": "OpenXRIPBinding", - "is_refcounted": true, - "is_instantiable": true, - "inherits": "Resource", - "api_type": "core", - "methods": [ - { - "name": "set_action", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 349361333, - "arguments": [ - { - "name": "action", - "type": "OpenXRAction" - } - ] - }, - { - "name": "get_action", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 4072409085, - "return_value": { - "type": "OpenXRAction" - } - }, - { - "name": "get_path_count", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3905245786, - "return_value": { - "type": "int", - "meta": "int32" - } - }, - { - "name": "set_paths", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 4015028928, - "arguments": [ - { - "name": "paths", - "type": "PackedStringArray" - } - ] - }, - { - "name": "get_paths", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 1139954409, - "return_value": { - "type": "PackedStringArray" - } - }, - { - "name": "has_path", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3927539163, - "return_value": { - "type": "bool" - }, - "arguments": [ - { - "name": "path", - "type": "String" - } - ] - }, - { - "name": "add_path", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 83702148, - "arguments": [ - { - "name": "path", - "type": "String" - } - ] - }, - { - "name": "remove_path", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 83702148, - "arguments": [ - { - "name": "path", - "type": "String" - } - ] - } - ], - "properties": [ - { - "type": "OpenXRAction", - "name": "action", - "setter": "set_action", - "getter": "get_action" - }, - { - "type": "PackedStringArray", - "name": "paths", - "setter": "set_paths", - "getter": "get_paths" - } - ] - }, - { - "name": "OpenXRInteractionProfile", - "is_refcounted": true, - "is_instantiable": true, - "inherits": "Resource", - "api_type": "core", - "methods": [ - { - "name": "set_interaction_profile_path", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 83702148, - "arguments": [ - { - "name": "interaction_profile_path", - "type": "String" - } - ] - }, - { - "name": "get_interaction_profile_path", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 201670096, - "return_value": { - "type": "String" - } - }, - { - "name": "get_binding_count", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3905245786, - "return_value": { - "type": "int", - "meta": "int32" - } - }, - { - "name": "get_binding", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3934429652, - "return_value": { - "type": "OpenXRIPBinding" - }, - "arguments": [ - { - "name": "index", - "type": "int", - "meta": "int32" - } - ] - }, - { - "name": "set_bindings", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 381264803, - "arguments": [ - { - "name": "bindings", - "type": "Array" - } - ] - }, - { - "name": "get_bindings", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3995934104, - "return_value": { - "type": "Array" - } - } - ], - "properties": [ - { - "type": "String", - "name": "interaction_profile_path", - "setter": "set_interaction_profile_path", - "getter": "get_interaction_profile_path" - }, - { - "type": "OpenXRIPBinding", - "name": "bindings", - "setter": "set_bindings", - "getter": "get_bindings" - } - ] - }, - { - "name": "OpenXRInterface", - "is_refcounted": true, - "is_instantiable": true, - "inherits": "XRInterface", - "api_type": "core", - "methods": [ - { - "name": "get_display_refresh_rate", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 1740695150, - "return_value": { - "type": "float", - "meta": "float" - } - }, - { - "name": "set_display_refresh_rate", - "is_const": false, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 373806689, - "arguments": [ - { - "name": "refresh_rate", - "type": "float", - "meta": "float" - } - ] - }, - { - "name": "get_available_display_refresh_rates", - "is_const": true, - "is_vararg": false, - "is_static": false, - "is_virtual": false, - "hash": 3995934104, - "return_value": { - "type": "Array" - } - } - ], - "signals": [ - { - "name": "session_begun" - }, - { - "name": "session_stopping" - }, - { - "name": "session_focussed" - }, - { - "name": "session_visible" - }, - { - "name": "pose_recentered" - } - ], - "properties": [ - { - "type": "float", - "name": "display_refresh_rate", - "setter": "set_display_refresh_rate", - "getter": "get_display_refresh_rate" - } - ] - }, { "name": "OptimizedTranslation", "is_refcounted": true, @@ -230912,6 +229997,13 @@ } ] }, + { + "name": "TextServerFallback", + "is_refcounted": true, + "is_instantiable": true, + "inherits": "TextServerExtension", + "api_type": "core" + }, { "name": "TextServerManager", "is_refcounted": false, @@ -236086,6 +235178,41 @@ } ] }, + { + "name": "get_used_cells_by_id", + "is_const": true, + "is_vararg": false, + "is_static": false, + "is_virtual": false, + "hash": 4152068407, + "return_value": { + "type": "typedarray::Vector2i" + }, + "arguments": [ + { + "name": "layer", + "type": "int", + "meta": "int32" + }, + { + "name": "source_id", + "type": "int", + "meta": "int32", + "default_value": "-1" + }, + { + "name": "atlas_coords", + "type": "Vector2i", + "default_value": "Vector2i(-1, -1)" + }, + { + "name": "alternative_tile", + "type": "int", + "meta": "int32", + "default_value": "-1" + } + ] + }, { "name": "get_used_rect", "is_const": false, @@ -245810,6 +244937,13 @@ } ] }, + { + "name": "UniformSetCacheRD", + "is_refcounted": false, + "is_instantiable": false, + "inherits": "Object", + "api_type": "core" + }, { "name": "VBoxContainer", "is_refcounted": false, @@ -254367,8 +253501,16 @@ "value": 5 }, { - "name": "SOURCE_MAX", + "name": "SOURCE_3D_NORMAL", "value": 6 + }, + { + "name": "SOURCE_ROUGHNESS", + "value": 7 + }, + { + "name": "SOURCE_MAX", + "value": 8 } ] }, @@ -254712,6 +253854,32 @@ "value": 3 } ] + }, + { + "name": "TextureSource", + "is_bitfield": false, + "values": [ + { + "name": "SOURCE_NONE", + "value": 0 + }, + { + "name": "SOURCE_SCREEN", + "value": 1 + }, + { + "name": "SOURCE_DEPTH", + "value": 2 + }, + { + "name": "SOURCE_NORMAL_ROUGHNESS", + "value": 3 + }, + { + "name": "SOURCE_MAX", + "value": 4 + } + ] } ], "methods": [ @@ -254749,7 +253917,7 @@ "hash": 4217624432, "arguments": [ { - "name": "type", + "name": "color", "type": "enum::VisualShaderNodeTextureParameter.ColorDefault" } ] @@ -254799,7 +253967,7 @@ "hash": 2036143070, "arguments": [ { - "name": "type", + "name": "repeat", "type": "enum::VisualShaderNodeTextureParameter.TextureRepeat" } ] @@ -254814,6 +253982,31 @@ "return_value": { "type": "enum::VisualShaderNodeTextureParameter.TextureRepeat" } + }, + { + "name": "set_texture_source", + "is_const": false, + "is_vararg": false, + "is_static": false, + "is_virtual": false, + "hash": 1212687372, + "arguments": [ + { + "name": "source", + "type": "enum::VisualShaderNodeTextureParameter.TextureSource" + } + ] + }, + { + "name": "get_texture_source", + "is_const": true, + "is_vararg": false, + "is_static": false, + "is_virtual": false, + "hash": 2039092262, + "return_value": { + "type": "enum::VisualShaderNodeTextureParameter.TextureSource" + } } ], "properties": [ @@ -254840,6 +254033,12 @@ "name": "texture_repeat", "setter": "set_texture_repeat", "getter": "get_texture_repeat" + }, + { + "type": "int", + "name": "texture_source", + "setter": "set_texture_source", + "getter": "get_texture_source" } ] }, diff --git a/gdextension/gdextension_interface.h b/gdextension/gdextension_interface.h index 190298ee..a16eef2f 100644 --- a/gdextension/gdextension_interface.h +++ b/gdextension/gdextension_interface.h @@ -503,6 +503,26 @@ typedef struct { char32_t *(*string_operator_index)(GDExtensionStringPtr p_self, GDExtensionInt p_index); const char32_t *(*string_operator_index_const)(GDExtensionConstStringPtr p_self, GDExtensionInt p_index); + void (*string_operator_plus_eq_string)(GDExtensionStringPtr p_self, GDExtensionConstStringPtr p_b); + void (*string_operator_plus_eq_char)(GDExtensionStringPtr p_self, char32_t p_b); + void (*string_operator_plus_eq_cstr)(GDExtensionStringPtr p_self, const char *p_b); + void (*string_operator_plus_eq_wcstr)(GDExtensionStringPtr p_self, const wchar_t *p_b); + void (*string_operator_plus_eq_c32str)(GDExtensionStringPtr p_self, const char32_t *p_b); + + /* XMLParser extra utilities */ + + GDExtensionInt (*xml_parser_open_buffer)(GDExtensionObjectPtr p_instance, const uint8_t *p_buffer, size_t p_size); + + /* FileAccess extra utilities */ + + void (*file_access_store_buffer)(GDExtensionObjectPtr p_instance, const uint8_t *p_src, uint64_t p_length); + uint64_t (*file_access_get_buffer)(GDExtensionConstObjectPtr p_instance, uint8_t *p_dst, uint64_t p_length); + + /* WorkerThreadPool extra utilities */ + + int64_t (*worker_thread_pool_add_native_group_task)(GDExtensionObjectPtr p_instance, void (*p_func)(void *, uint32_t), void *p_userdata, int p_elements, int p_tasks, bool p_high_priority, GDExtensionConstStringPtr p_description); + int64_t (*worker_thread_pool_add_native_task)(GDExtensionObjectPtr p_instance, void (*p_func)(void *), void *p_userdata, bool p_high_priority, GDExtensionConstStringPtr p_description); + /* Packed array functions */ uint8_t *(*packed_byte_array_operator_index)(GDExtensionTypePtr p_self, GDExtensionInt p_index); // p_self should be a PackedByteArray diff --git a/include/godot_cpp/core/math.hpp b/include/godot_cpp/core/math.hpp index 361395d1..48d1283e 100644 --- a/include/godot_cpp/core/math.hpp +++ b/include/godot_cpp/core/math.hpp @@ -38,6 +38,171 @@ #include namespace godot { + +#define Math_SQRT12 0.7071067811865475244008443621048490 +#define Math_SQRT2 1.4142135623730950488016887242 +#define Math_LN2 0.6931471805599453094172321215 +#define Math_PI 3.1415926535897932384626433833 +#define Math_TAU 6.2831853071795864769252867666 +#define Math_E 2.7182818284590452353602874714 +#define Math_INF INFINITY +#define Math_NAN NAN + +// Make room for our constexpr's below by overriding potential system-specific macros. +#undef ABS +#undef SIGN +#undef MIN +#undef MAX +#undef CLAMP + +// Generic ABS function, for math uses please use Math::abs. +template +constexpr T ABS(T m_v) { + return m_v < 0 ? -m_v : m_v; +} + +template +constexpr const T SIGN(const T m_v) { + return m_v == 0 ? 0.0f : (m_v < 0 ? -1.0f : +1.0f); +} + +template +constexpr auto MIN(const T m_a, const T2 m_b) { + return m_a < m_b ? m_a : m_b; +} + +template +constexpr auto MAX(const T m_a, const T2 m_b) { + return m_a > m_b ? m_a : m_b; +} + +template +constexpr auto CLAMP(const T m_a, const T2 m_min, const T3 m_max) { + return m_a < m_min ? m_min : (m_a > m_max ? m_max : m_a); +} + +// Generic swap template. +#ifndef SWAP +#define SWAP(m_x, m_y) __swap_tmpl((m_x), (m_y)) +template +inline void __swap_tmpl(T &x, T &y) { + T aux = x; + x = y; + y = aux; +} +#endif // SWAP + +/* Functions to handle powers of 2 and shifting. */ + +// Function to find the next power of 2 to an integer. +static _FORCE_INLINE_ unsigned int next_power_of_2(unsigned int x) { + if (x == 0) { + return 0; + } + + --x; + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; + + return ++x; +} + +// Function to find the previous power of 2 to an integer. +static _FORCE_INLINE_ unsigned int previous_power_of_2(unsigned int x) { + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; + return x - (x >> 1); +} + +// Function to find the closest power of 2 to an integer. +static _FORCE_INLINE_ unsigned int closest_power_of_2(unsigned int x) { + unsigned int nx = next_power_of_2(x); + unsigned int px = previous_power_of_2(x); + return (nx - x) > (x - px) ? px : nx; +} + +// Get a shift value from a power of 2. +static inline int get_shift_from_power_of_2(unsigned int p_bits) { + for (unsigned int i = 0; i < 32; i++) { + if (p_bits == (unsigned int)(1 << i)) { + return i; + } + } + + return -1; +} + +template +static _FORCE_INLINE_ T nearest_power_of_2_templated(T x) { + --x; + + // The number of operations on x is the base two logarithm + // of the number of bits in the type. Add three to account + // for sizeof(T) being in bytes. + size_t num = get_shift_from_power_of_2(sizeof(T)) + 3; + + // If the compiler is smart, it unrolls this loop. + // If it's dumb, this is a bit slow. + for (size_t i = 0; i < num; i++) { + x |= x >> (1 << i); + } + + return ++x; +} + +// Function to find the nearest (bigger) power of 2 to an integer. +static inline unsigned int nearest_shift(unsigned int p_number) { + for (int i = 30; i >= 0; i--) { + if (p_number & (1 << i)) { + return i + 1; + } + } + + return 0; +} + +// constexpr function to find the floored log2 of a number +template +constexpr T floor_log2(T x) { + return x < 2 ? x : 1 + floor_log2(x >> 1); +} + +// Get the number of bits needed to represent the number. +// IE, if you pass in 8, you will get 4. +// If you want to know how many bits are needed to store 8 values however, pass in (8 - 1). +template +constexpr T get_num_bits(T x) { + return floor_log2(x); +} + +// Swap 16, 32 and 64 bits value for endianness. +#if defined(__GNUC__) +#define BSWAP16(x) __builtin_bswap16(x) +#define BSWAP32(x) __builtin_bswap32(x) +#define BSWAP64(x) __builtin_bswap64(x) +#else +static inline uint16_t BSWAP16(uint16_t x) { + return (x >> 8) | (x << 8); +} + +static inline uint32_t BSWAP32(uint32_t x) { + return ((x << 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x >> 24)); +} + +static inline uint64_t BSWAP64(uint64_t x) { + x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000) >> 32; + x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16; + x = (x & 0x00FF00FF00FF00FF) << 8 | (x & 0xFF00FF00FF00FF00) >> 8; + return x; +} +#endif + namespace Math { // This epsilon should match the one used by Godot for consistency. @@ -53,43 +218,6 @@ namespace Math { #define UNIT_EPSILON 0.001 #endif -#define Math_SQRT12 0.7071067811865475244008443621048490 -#define Math_SQRT2 1.4142135623730950488016887242 -#define Math_LN2 0.6931471805599453094172321215 -#define Math_PI 3.1415926535897932384626433833 -#define Math_TAU 6.2831853071795864769252867666 -#define Math_E 2.7182818284590452353602874714 -#define Math_INF INFINITY -#define Math_NAN NAN - -// Windows badly defines a lot of stuff we'll never use. Undefine it. -#ifdef _WIN32 -#undef MIN // override standard definition -#undef MAX // override standard definition -#undef CLAMP // override standard definition -#endif - -// Generic ABS function, for math uses please use Math::abs. -#ifndef ABS -#define ABS(m_v) (((m_v) < 0) ? (-(m_v)) : (m_v)) -#endif - -#ifndef SIGN -#define SIGN(m_v) (((m_v) == 0) ? (0.0) : (((m_v) < 0) ? (-1.0) : (+1.0))) -#endif - -#ifndef MIN -#define MIN(m_a, m_b) (((m_a) < (m_b)) ? (m_a) : (m_b)) -#endif - -#ifndef MAX -#define MAX(m_a, m_b) (((m_a) > (m_b)) ? (m_a) : (m_b)) -#endif - -#ifndef CLAMP -#define CLAMP(m_a, m_min, m_max) (((m_a) < (m_min)) ? (m_min) : (((m_a) > (m_max)) ? m_max : m_a)) -#endif - // Functions reproduced as in Godot's source code `math_funcs.h`. // Some are overloads to automatically support changing real_t into either double or float in the way Godot does. @@ -628,20 +756,6 @@ inline double pingpong(double value, double length) { return (length != 0.0) ? abs(fract((value - length) / (length * 2.0)) * length * 2.0 - length) : 0.0; } -inline unsigned int next_power_of_2(unsigned int x) { - if (x == 0) - return 0; - - --x; - x |= x >> 1; - x |= x >> 2; - x |= x >> 4; - x |= x >> 8; - x |= x >> 16; - - return ++x; -} - // This function should be as fast as possible and rounding mode should not matter. inline int fast_ftoi(float a) { static int b; diff --git a/include/godot_cpp/templates/cowdata.hpp b/include/godot_cpp/templates/cowdata.hpp index 8d4defd6..38f92777 100644 --- a/include/godot_cpp/templates/cowdata.hpp +++ b/include/godot_cpp/templates/cowdata.hpp @@ -91,7 +91,7 @@ private: } _FORCE_INLINE_ size_t _get_alloc_size(size_t p_elements) const { - return Math::next_power_of_2(p_elements * sizeof(T)); + return next_power_of_2(p_elements * sizeof(T)); } _FORCE_INLINE_ bool _get_alloc_size_checked(size_t p_elements, size_t *out) const { @@ -102,7 +102,7 @@ private: *out = 0; return false; } - *out = Math::next_power_of_2(o); + *out = next_power_of_2(o); if (__builtin_add_overflow(o, static_cast(32), &p)) { return false; // No longer allocated here. } diff --git a/include/godot_cpp/variant/variant.hpp b/include/godot_cpp/variant/variant.hpp index b131d749..06ba75f6 100644 --- a/include/godot_cpp/variant/variant.hpp +++ b/include/godot_cpp/variant/variant.hpp @@ -322,6 +322,18 @@ struct VariantComparator { static _FORCE_INLINE_ bool compare(const Variant &p_lhs, const Variant &p_rhs) { return p_lhs.hash_compare(p_rhs); } }; +template +String vformat(const String &p_text, const VarArgs... p_args) { + Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported. + Array args_array; + args_array.resize(sizeof...(p_args)); + for (uint32_t i = 0; i < sizeof...(p_args); i++) { + args_array[i] = args[i]; + } + + return p_text % args_array; +} + } // namespace godot #endif // GODOT_VARIANT_HPP diff --git a/src/classes/low_level.cpp b/src/classes/low_level.cpp new file mode 100644 index 00000000..b9841871 --- /dev/null +++ b/src/classes/low_level.cpp @@ -0,0 +1,58 @@ +/**************************************************************************/ +/* low_level.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include +#include +#include + +#include + +namespace godot { +Error XMLParser::_open_buffer(const uint8_t *p_buffer, size_t p_size) { + return (Error)internal::gde_interface->xml_parser_open_buffer(_owner, p_buffer, p_size); +} + +uint64_t FileAccess::get_buffer(uint8_t *p_dst, uint64_t p_length) const { + return internal::gde_interface->file_access_get_buffer(_owner, p_dst, p_length); +} + +void FileAccess::store_buffer(const uint8_t *p_src, uint64_t p_length) { + internal::gde_interface->file_access_store_buffer(_owner, p_src, p_length); +} + +WorkerThreadPool::TaskID WorkerThreadPool::add_native_task(void (*p_func)(void *), void *p_userdata, bool p_high_priority, const String &p_description) { + return (TaskID)internal::gde_interface->worker_thread_pool_add_native_task(_owner, p_func, p_userdata, p_high_priority, (const GDExtensionStringPtr)&p_description); +} + +WorkerThreadPool::GroupID WorkerThreadPool::add_native_group_task(void (*p_func)(void *, uint32_t), void *p_userdata, int p_elements, int p_tasks, bool p_high_priority, const String &p_description) { + return (GroupID)internal::gde_interface->worker_thread_pool_add_native_group_task(_owner, p_func, p_userdata, p_elements, p_tasks, p_high_priority, (const GDExtensionStringPtr)&p_description); +} + +} // namespace godot diff --git a/src/variant/char_string.cpp b/src/variant/char_string.cpp index e6b596fd..a9c170ea 100644 --- a/src/variant/char_string.cpp +++ b/src/variant/char_string.cpp @@ -332,20 +332,49 @@ bool String::operator!=(const char32_t *p_str) const { return *this != String(p_str); } -String String::operator+(const char *p_chr) { - return *this + String(p_chr); +String String::operator+(const char *p_str) { + return *this + String(p_str); } -String String::operator+(const wchar_t *p_chr) { - return *this + String(p_chr); +String String::operator+(const wchar_t *p_str) { + return *this + String(p_str); } -String String::operator+(const char16_t *p_chr) { - return *this + String(p_chr); +String String::operator+(const char16_t *p_str) { + return *this + String(p_str); } -String String::operator+(const char32_t *p_chr) { - return *this + String(p_chr); +String String::operator+(const char32_t *p_str) { + return *this + String(p_str); +} + +String String::operator+(const char32_t p_char) { + return *this + String::chr(p_char); +} + +String &String::operator+=(const String &p_str) { + internal::gde_interface->string_operator_plus_eq_string((GDExtensionStringPtr)this, (const GDExtensionStringPtr)&p_str); + return *this; +} + +String &String::operator+=(char32_t p_char) { + internal::gde_interface->string_operator_plus_eq_char((GDExtensionStringPtr)this, p_char); + return *this; +} + +String &String::operator+=(const char *p_str) { + internal::gde_interface->string_operator_plus_eq_cstr((GDExtensionStringPtr)this, p_str); + return *this; +} + +String &String::operator+=(const wchar_t *p_str) { + internal::gde_interface->string_operator_plus_eq_wcstr((GDExtensionStringPtr)this, p_str); + return *this; +} + +String &String::operator+=(const char32_t *p_str) { + internal::gde_interface->string_operator_plus_eq_c32str((GDExtensionStringPtr)this, p_str); + return *this; } const char32_t &String::operator[](int p_index) const { @@ -412,6 +441,10 @@ String operator+(const char32_t *p_chr, const String &p_str) { return String(p_chr) + p_str; } +String operator+(char32_t p_char, const String &p_str) { + return String::chr(p_char) + p_str; +} + StringName::StringName(const char *from) : StringName(String(from)) {} diff --git a/test/demo/main.gd b/test/demo/main.gd index 671a879c..7ef3ace0 100644 --- a/test/demo/main.gd +++ b/test/demo/main.gd @@ -54,6 +54,15 @@ func _ready(): var array: Array[int] = [1, 2, 3] $Example.test_tarray_arg(array) + prints("String += operator") + prints(" test string +=", $Example.test_string_ops()) + + prints("WorkerThreadPool") + prints(" test worker_thread_pool", $Example.test_workpool_ops()) + + prints("PackedArray iterators") + prints(" test packed array iterators", $Example.test_vector_ops()) + prints("Properties") prints(" custom position is", $Example.group_subgroup_custom_position) $Example.group_subgroup_custom_position = Vector2(50, 50) diff --git a/test/src/example.cpp b/test/src/example.cpp index 6da1f528..dec8f57d 100644 --- a/test/src/example.cpp +++ b/test/src/example.cpp @@ -123,6 +123,8 @@ void Example::_bind_methods() { ClassDB::bind_method(D_METHOD("test_tarray"), &Example::test_tarray); ClassDB::bind_method(D_METHOD("test_dictionary"), &Example::test_dictionary); ClassDB::bind_method(D_METHOD("test_node_argument"), &Example::test_node_argument); + ClassDB::bind_method(D_METHOD("test_string_ops"), &Example::test_string_ops); + ClassDB::bind_method(D_METHOD("test_vector_ops"), &Example::test_vector_ops); ClassDB::bind_method(D_METHOD("def_args", "a", "b"), &Example::def_args, DEFVAL(100), DEFVAL(200)); @@ -255,6 +257,28 @@ Array Example::test_array() const { return arr; } +String Example::test_string_ops() const { + String s = String("A"); + s += "B"; + s += "C"; + s += char32_t(0x010E); + s = s + "E"; + return s; +} + +int Example::test_vector_ops() const { + PackedInt32Array arr; + arr.push_back(10); + arr.push_back(20); + arr.push_back(30); + arr.push_back(45); + int ret = 0; + for (const int32_t &E : arr) { + ret += E; + } + return ret; +} + void Example::test_tarray_arg(const TypedArray &p_array) { for (int i = 0; i < p_array.size(); i++) { UtilityFunctions::print(p_array[i]); diff --git a/test/src/example.h b/test/src/example.h index 6857be2e..2d4a6b03 100644 --- a/test/src/example.h +++ b/test/src/example.h @@ -101,6 +101,8 @@ public: TypedArray test_tarray() const; Dictionary test_dictionary() const; Example *test_node_argument(Example *p_node) const; + String test_string_ops() const; + int test_vector_ops() const; // Property. void set_custom_position(const Vector2 &pos);