summaryrefslogtreecommitdiff
path: root/core/object/object.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/object/object.h')
-rw-r--r--core/object/object.h160
1 files changed, 79 insertions, 81 deletions
diff --git a/core/object/object.h b/core/object/object.h
index 9416eb7762..5ec69a371b 100644
--- a/core/object/object.h
+++ b/core/object/object.h
@@ -1,37 +1,37 @@
-/*************************************************************************/
-/* object.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* 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. */
-/*************************************************************************/
+/**************************************************************************/
+/* object.h */
+/**************************************************************************/
+/* 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. */
+/**************************************************************************/
#ifndef OBJECT_H
#define OBJECT_H
-#include "core/extension/gdnative_interface.h"
+#include "core/extension/gdextension_interface.h"
#include "core/object/message_queue.h"
#include "core/object/object_id.h"
#include "core/os/rw_lock.h"
@@ -74,14 +74,6 @@ enum PropertyHint {
PROPERTY_HINT_OBJECT_ID,
PROPERTY_HINT_TYPE_STRING, ///< a type string, the hint is the base type to choose
PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE, ///< so something else can provide this (used in scripts)
- PROPERTY_HINT_METHOD_OF_VARIANT_TYPE, ///< a method of a type
- PROPERTY_HINT_METHOD_OF_BASE_TYPE, ///< a method of a base type
- PROPERTY_HINT_METHOD_OF_INSTANCE, ///< a method of an instance
- PROPERTY_HINT_METHOD_OF_SCRIPT, ///< a method of a script & base
- PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE, ///< a property of a type
- PROPERTY_HINT_PROPERTY_OF_BASE_TYPE, ///< a property of a base type
- PROPERTY_HINT_PROPERTY_OF_INSTANCE, ///< a property of an instance
- PROPERTY_HINT_PROPERTY_OF_SCRIPT, ///< a property of a script & base
PROPERTY_HINT_OBJECT_TOO_BIG, ///< object is too big to send
PROPERTY_HINT_NODE_PATH_VALID_TYPES,
PROPERTY_HINT_SAVE_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,". This opens a save dialog
@@ -95,16 +87,15 @@ enum PropertyHint {
PROPERTY_HINT_HIDE_QUATERNION_EDIT, /// Only Node3D::transform should hide the quaternion editor.
PROPERTY_HINT_PASSWORD,
PROPERTY_HINT_MAX,
- // When updating PropertyHint, also sync the hardcoded list in VisualScriptEditorVariableEdit
};
enum PropertyUsageFlags {
PROPERTY_USAGE_NONE = 0,
PROPERTY_USAGE_STORAGE = 1 << 1,
PROPERTY_USAGE_EDITOR = 1 << 2,
- PROPERTY_USAGE_CHECKABLE = 1 << 3, // Used for editing global variables.
- PROPERTY_USAGE_CHECKED = 1 << 4, // Used for editing global variables.
- PROPERTY_USAGE_INTERNATIONALIZED = 1 << 5, // Hint for internationalized strings.
+ PROPERTY_USAGE_INTERNAL = 1 << 3,
+ PROPERTY_USAGE_CHECKABLE = 1 << 4, // Used for editing global variables.
+ PROPERTY_USAGE_CHECKED = 1 << 5, // Used for editing global variables.
PROPERTY_USAGE_GROUP = 1 << 6, // Used for grouping props in the editor.
PROPERTY_USAGE_CATEGORY = 1 << 7,
PROPERTY_USAGE_SUBGROUP = 1 << 8,
@@ -113,13 +104,13 @@ enum PropertyUsageFlags {
PROPERTY_USAGE_RESTART_IF_CHANGED = 1 << 11,
PROPERTY_USAGE_SCRIPT_VARIABLE = 1 << 12,
PROPERTY_USAGE_STORE_IF_NULL = 1 << 13,
- PROPERTY_USAGE_ANIMATE_AS_TRIGGER = 1 << 14,
- PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED = 1 << 15,
- PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE = 1 << 16,
- PROPERTY_USAGE_CLASS_IS_ENUM = 1 << 17,
- PROPERTY_USAGE_NIL_IS_VARIANT = 1 << 18,
- PROPERTY_USAGE_INTERNAL = 1 << 19,
- PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE = 1 << 20, // If the object is duplicated also this property will be duplicated.
+ PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED = 1 << 14,
+ PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE = 1 << 15,
+ PROPERTY_USAGE_CLASS_IS_ENUM = 1 << 16,
+ PROPERTY_USAGE_NIL_IS_VARIANT = 1 << 17,
+ PROPERTY_USAGE_ARRAY = 1 << 18, // Used in the inspector to group properties as elements of an array.
+ PROPERTY_USAGE_ALWAYS_DUPLICATE = 1 << 19, // When duplicating a resource, always duplicate, even with subresource duplication disabled.
+ PROPERTY_USAGE_NEVER_DUPLICATE = 1 << 20, // When duplicating a resource, never duplicate, even with subresource duplication enabled.
PROPERTY_USAGE_HIGH_END_GFX = 1 << 21,
PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT = 1 << 22,
PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT = 1 << 23,
@@ -128,10 +119,8 @@ enum PropertyUsageFlags {
PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT = 1 << 26, // For Object properties, instantiate them when creating in editor.
PROPERTY_USAGE_EDITOR_BASIC_SETTING = 1 << 27, //for project or editor settings, show when basic settings are selected.
PROPERTY_USAGE_READ_ONLY = 1 << 28, // Mark a property as read-only in the inspector.
- PROPERTY_USAGE_ARRAY = 1 << 29, // Used in the inspector to group properties as elements of an array.
PROPERTY_USAGE_DEFAULT = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR,
- PROPERTY_USAGE_DEFAULT_INTL = PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNATIONALIZED,
PROPERTY_USAGE_NO_EDITOR = PROPERTY_USAGE_STORAGE,
};
@@ -192,7 +181,7 @@ struct PropertyInfo {
type(Variant::OBJECT),
class_name(p_class_name) {}
- explicit PropertyInfo(const GDNativePropertyInfo &pinfo) :
+ explicit PropertyInfo(const GDExtensionPropertyInfo &pinfo) :
type((Variant::Type)pinfo.type),
name(*reinterpret_cast<StringName *>(pinfo.name)),
class_name(*reinterpret_cast<StringName *>(pinfo.class_name)),
@@ -234,6 +223,16 @@ struct MethodInfo {
int id = 0;
List<PropertyInfo> arguments;
Vector<Variant> default_arguments;
+ int return_val_metadata = 0;
+ Vector<int> arguments_metadata;
+
+ int get_argument_meta(int p_arg) const {
+ ERR_FAIL_COND_V(p_arg < -1 || p_arg > arguments.size(), 0);
+ if (p_arg == -1) {
+ return return_val_metadata;
+ }
+ return arguments_metadata.size() > p_arg ? arguments_metadata[p_arg] : 0;
+ }
inline bool operator==(const MethodInfo &p_method) const { return id == p_method.id; }
inline bool operator<(const MethodInfo &p_method) const { return id == p_method.id ? (name < p_method.name) : (id < p_method.id); }
@@ -244,7 +243,7 @@ struct MethodInfo {
MethodInfo() {}
- explicit MethodInfo(const GDNativeMethodInfo &pinfo) :
+ explicit MethodInfo(const GDExtensionMethodInfo &pinfo) :
name(*reinterpret_cast<StringName *>(pinfo.name)),
return_val(PropertyInfo(pinfo.return_value)),
flags(pinfo.flags),
@@ -302,31 +301,31 @@ struct MethodInfo {
}
};
-// API used to extend in GDNative and other C compatible compiled languages.
+// API used to extend in GDExtension and other C compatible compiled languages.
class MethodBind;
-struct ObjectNativeExtension {
- ObjectNativeExtension *parent = nullptr;
- List<ObjectNativeExtension *> children;
+struct ObjectGDExtension {
+ ObjectGDExtension *parent = nullptr;
+ List<ObjectGDExtension *> children;
StringName parent_class_name;
StringName class_name;
bool editor_class = false;
bool is_virtual = false;
bool is_abstract = false;
- GDNativeExtensionClassSet set;
- GDNativeExtensionClassGet get;
- GDNativeExtensionClassGetPropertyList get_property_list;
- GDNativeExtensionClassFreePropertyList free_property_list;
- GDNativeExtensionClassPropertyCanRevert property_can_revert;
- GDNativeExtensionClassPropertyGetRevert property_get_revert;
- GDNativeExtensionClassNotification notification;
- GDNativeExtensionClassToString to_string;
- GDNativeExtensionClassReference reference;
- GDNativeExtensionClassReference unreference;
- GDNativeExtensionClassGetRID get_rid;
+ GDExtensionClassSet set;
+ GDExtensionClassGet get;
+ GDExtensionClassGetPropertyList get_property_list;
+ GDExtensionClassFreePropertyList free_property_list;
+ GDExtensionClassPropertyCanRevert property_can_revert;
+ GDExtensionClassPropertyGetRevert property_get_revert;
+ GDExtensionClassNotification notification;
+ GDExtensionClassToString to_string;
+ GDExtensionClassReference reference;
+ GDExtensionClassReference unreference;
+ GDExtensionClassGetRID get_rid;
_FORCE_INLINE_ bool is_class(const String &p_class) const {
- const ObjectNativeExtension *e = this;
+ const ObjectGDExtension *e = this;
while (e) {
if (p_class == e->class_name.operator String()) {
return true;
@@ -337,9 +336,9 @@ struct ObjectNativeExtension {
}
void *class_userdata = nullptr;
- GDNativeExtensionClassCreateInstance create_instance;
- GDNativeExtensionClassFreeInstance free_instance;
- GDNativeExtensionClassGetVirtual get_virtual;
+ GDExtensionClassCreateInstance create_instance;
+ GDExtensionClassFreeInstance free_instance;
+ GDExtensionClassGetVirtual get_virtual;
};
#define GDVIRTUAL_CALL(m_name, ...) _gdvirtual_##m_name##_call<false>(__VA_ARGS__)
@@ -557,6 +556,7 @@ public:
CONNECT_PERSIST = 2, // hint for scene to save this connection
CONNECT_ONE_SHOT = 4,
CONNECT_REFERENCE_COUNTED = 8,
+ CONNECT_INHERITED = 16, // Used in editor builds.
};
struct Connection {
@@ -579,7 +579,7 @@ private:
friend bool predelete_handler(Object *);
friend void postinitialize_handler(Object *);
- ObjectNativeExtension *_extension = nullptr;
+ ObjectGDExtension *_extension = nullptr;
GDExtensionClassInstancePtr _extension_instance = nullptr;
struct SignalData {
@@ -637,8 +637,8 @@ private:
struct InstanceBinding {
void *binding = nullptr;
void *token = nullptr;
- GDNativeInstanceBindingFreeCallback free_callback = nullptr;
- GDNativeInstanceBindingReferenceCallback reference_callback = nullptr;
+ GDExtensionInstanceBindingFreeCallback free_callback = nullptr;
+ GDExtensionInstanceBindingReferenceCallback reference_callback = nullptr;
};
InstanceBinding *_instance_bindings = nullptr;
uint32_t _instance_binding_count = 0;
@@ -662,8 +662,8 @@ protected:
return can_die;
}
- friend class NativeExtensionMethodBind;
- _ALWAYS_INLINE_ const ObjectNativeExtension *_get_extension() const { return _extension; }
+ friend class GDExtensionMethodBind;
+ _ALWAYS_INLINE_ const ObjectGDExtension *_get_extension() const { return _extension; }
_ALWAYS_INLINE_ GDExtensionClassInstancePtr _get_extension_instance() const { return _extension_instance; }
virtual void _initialize_classv() { initialize_class(); }
virtual bool _setv(const StringName &p_name, const Variant &p_property) { return false; };
@@ -894,8 +894,6 @@ public:
Variant::Type get_static_property_type(const StringName &p_property, bool *r_valid = nullptr) const;
Variant::Type get_static_property_type_indexed(const Vector<StringName> &p_path, bool *r_valid = nullptr) const;
- virtual void get_translatable_strings(List<String> *p_strings) const;
-
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const;
// Translate message (internationalization).
@@ -917,9 +915,9 @@ public:
#endif
// Used by script languages to store binding data.
- void *get_instance_binding(void *p_token, const GDNativeInstanceBindingCallbacks *p_callbacks);
+ void *get_instance_binding(void *p_token, const GDExtensionInstanceBindingCallbacks *p_callbacks);
// Used on creation by binding only.
- void set_instance_binding(void *p_token, void *p_binding, const GDNativeInstanceBindingCallbacks *p_callbacks);
+ void set_instance_binding(void *p_token, void *p_binding, const GDExtensionInstanceBindingCallbacks *p_callbacks);
bool has_instance_binding(void *p_token);
void clear_internal_resource_paths();