object.h 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357
  1. /**************************************************************************/
  2. /* object.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. #include "core/extension/gdextension_interface.gen.h"
  32. #include "core/object/gdtype.h"
  33. #include "core/object/message_queue.h"
  34. #include "core/object/object_id.h"
  35. #include "core/os/spin_lock.h"
  36. #include "core/templates/hash_map.h"
  37. #include "core/templates/hash_set.h"
  38. #include "core/templates/list.h"
  39. #include "core/templates/safe_refcount.h"
  40. #include "core/variant/variant.h"
  41. template <typename T>
  42. class TypedArray;
  43. template <typename T>
  44. class Ref;
  45. enum PropertyHint {
  46. PROPERTY_HINT_NONE, ///< no hint provided.
  47. PROPERTY_HINT_RANGE, ///< hint_text = "min,max[,step][,or_greater][,or_less][,prefer_slider][,hide_control][,radians_as_degrees][,degrees][,exp][,suffix:<keyword>] range.
  48. PROPERTY_HINT_ENUM, ///< hint_text= "val1,val2,val3,etc"
  49. PROPERTY_HINT_ENUM_SUGGESTION, ///< hint_text= "val1,val2,val3,etc"
  50. PROPERTY_HINT_EXP_EASING, /// exponential easing function (Math::ease) use "attenuation" hint string to revert (flip h), "positive_only" to exclude in-out and out-in. (ie: "attenuation,positive_only")
  51. PROPERTY_HINT_LINK,
  52. PROPERTY_HINT_FLAGS, ///< hint_text= "flag1,flag2,etc" (as bit flags)
  53. PROPERTY_HINT_LAYERS_2D_RENDER,
  54. PROPERTY_HINT_LAYERS_2D_PHYSICS,
  55. PROPERTY_HINT_LAYERS_2D_NAVIGATION,
  56. PROPERTY_HINT_LAYERS_3D_RENDER,
  57. PROPERTY_HINT_LAYERS_3D_PHYSICS,
  58. PROPERTY_HINT_LAYERS_3D_NAVIGATION,
  59. PROPERTY_HINT_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,"
  60. PROPERTY_HINT_DIR, ///< a directory path must be passed
  61. PROPERTY_HINT_GLOBAL_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,"
  62. PROPERTY_HINT_GLOBAL_DIR, ///< a directory path must be passed
  63. PROPERTY_HINT_RESOURCE_TYPE, ///< a comma-separated resource object type, e.g. "NoiseTexture,GradientTexture2D". Subclasses can be excluded with a "-" prefix if placed *after* the base class, e.g. "Texture2D,-MeshTexture".
  64. PROPERTY_HINT_MULTILINE_TEXT, ///< used for string properties that can contain multiple lines
  65. PROPERTY_HINT_EXPRESSION, ///< used for string properties that can contain multiple lines
  66. PROPERTY_HINT_PLACEHOLDER_TEXT, ///< used to set a placeholder text for string properties
  67. PROPERTY_HINT_COLOR_NO_ALPHA, ///< used for ignoring alpha component when editing a color
  68. PROPERTY_HINT_OBJECT_ID,
  69. PROPERTY_HINT_TYPE_STRING, ///< a type string, the hint is the base type to choose
  70. PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE, // Deprecated.
  71. PROPERTY_HINT_OBJECT_TOO_BIG, ///< object is too big to send
  72. PROPERTY_HINT_NODE_PATH_VALID_TYPES,
  73. PROPERTY_HINT_SAVE_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,". This opens a save dialog
  74. PROPERTY_HINT_GLOBAL_SAVE_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,". This opens a save dialog
  75. PROPERTY_HINT_INT_IS_OBJECTID, // Deprecated.
  76. PROPERTY_HINT_INT_IS_POINTER,
  77. PROPERTY_HINT_ARRAY_TYPE,
  78. PROPERTY_HINT_LOCALE_ID,
  79. PROPERTY_HINT_LOCALIZABLE_STRING,
  80. PROPERTY_HINT_NODE_TYPE, ///< a node object type
  81. PROPERTY_HINT_HIDE_QUATERNION_EDIT, /// Only Node3D::transform should hide the quaternion editor.
  82. PROPERTY_HINT_PASSWORD,
  83. PROPERTY_HINT_LAYERS_AVOIDANCE,
  84. PROPERTY_HINT_DICTIONARY_TYPE,
  85. PROPERTY_HINT_TOOL_BUTTON,
  86. PROPERTY_HINT_ONESHOT, ///< the property will be changed by self after setting, such as AudioStreamPlayer.playing, Particles.emitting.
  87. PROPERTY_HINT_NO_NODEPATH, /// < this property will not contain a NodePath, regardless of type (Array, Dictionary, List, etc.). Needed for SceneTreeDock.
  88. PROPERTY_HINT_GROUP_ENABLE, ///< used to make the property's group checkable. Only use for boolean types.
  89. PROPERTY_HINT_INPUT_NAME,
  90. PROPERTY_HINT_FILE_PATH,
  91. PROPERTY_HINT_MAX,
  92. };
  93. enum PropertyUsageFlags {
  94. PROPERTY_USAGE_NONE = 0,
  95. PROPERTY_USAGE_STORAGE = 1 << 1,
  96. PROPERTY_USAGE_EDITOR = 1 << 2,
  97. PROPERTY_USAGE_INTERNAL = 1 << 3,
  98. PROPERTY_USAGE_CHECKABLE = 1 << 4, // Used for editing global variables.
  99. PROPERTY_USAGE_CHECKED = 1 << 5, // Used for editing global variables.
  100. PROPERTY_USAGE_GROUP = 1 << 6, // Used for grouping props in the editor.
  101. PROPERTY_USAGE_CATEGORY = 1 << 7,
  102. PROPERTY_USAGE_SUBGROUP = 1 << 8,
  103. PROPERTY_USAGE_CLASS_IS_BITFIELD = 1 << 9,
  104. PROPERTY_USAGE_NO_INSTANCE_STATE = 1 << 10,
  105. PROPERTY_USAGE_RESTART_IF_CHANGED = 1 << 11,
  106. PROPERTY_USAGE_SCRIPT_VARIABLE = 1 << 12,
  107. PROPERTY_USAGE_STORE_IF_NULL = 1 << 13,
  108. PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED = 1 << 14,
  109. PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE = 1 << 15, // Deprecated.
  110. PROPERTY_USAGE_CLASS_IS_ENUM = 1 << 16,
  111. PROPERTY_USAGE_NIL_IS_VARIANT = 1 << 17,
  112. PROPERTY_USAGE_ARRAY = 1 << 18, // Used in the inspector to group properties as elements of an array.
  113. PROPERTY_USAGE_ALWAYS_DUPLICATE = 1 << 19, // When duplicating a resource, always duplicate, even with subresource duplication disabled.
  114. PROPERTY_USAGE_NEVER_DUPLICATE = 1 << 20, // When duplicating a resource, never duplicate, even with subresource duplication enabled.
  115. PROPERTY_USAGE_HIGH_END_GFX = 1 << 21,
  116. PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT = 1 << 22,
  117. PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT = 1 << 23,
  118. PROPERTY_USAGE_KEYING_INCREMENTS = 1 << 24, // Used in inspector to increment property when keyed in animation player.
  119. PROPERTY_USAGE_DEFERRED_SET_RESOURCE = 1 << 25, // Deprecated.
  120. PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT = 1 << 26, // For Object properties, instantiate them when creating in editor.
  121. PROPERTY_USAGE_EDITOR_BASIC_SETTING = 1 << 27, //for project or editor settings, show when basic settings are selected.
  122. PROPERTY_USAGE_READ_ONLY = 1 << 28, // Mark a property as read-only in the inspector.
  123. PROPERTY_USAGE_SECRET = 1 << 29, // Export preset credentials that should be stored separately from the rest of the export config.
  124. PROPERTY_USAGE_DEFAULT = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR,
  125. PROPERTY_USAGE_NO_EDITOR = PROPERTY_USAGE_STORAGE,
  126. };
  127. #define ADD_SIGNAL(m_signal) ::ClassDB::add_signal(get_class_static(), m_signal)
  128. #define ADD_PROPERTY(m_property, m_setter, m_getter) ::ClassDB::add_property(get_class_static(), m_property, StringName(m_setter), StringName(m_getter))
  129. #define ADD_PROPERTYI(m_property, m_setter, m_getter, m_index) ::ClassDB::add_property(get_class_static(), m_property, StringName(m_setter), StringName(m_getter), m_index)
  130. #define ADD_PROPERTY_DEFAULT(m_property, m_default) ::ClassDB::set_property_default_value(get_class_static(), m_property, m_default)
  131. #define ADD_GROUP(m_name, m_prefix) ::ClassDB::add_property_group(get_class_static(), m_name, m_prefix)
  132. #define ADD_GROUP_INDENT(m_name, m_prefix, m_depth) ::ClassDB::add_property_group(get_class_static(), m_name, m_prefix, m_depth)
  133. #define ADD_SUBGROUP(m_name, m_prefix) ::ClassDB::add_property_subgroup(get_class_static(), m_name, m_prefix)
  134. #define ADD_SUBGROUP_INDENT(m_name, m_prefix, m_depth) ::ClassDB::add_property_subgroup(get_class_static(), m_name, m_prefix, m_depth)
  135. #define ADD_LINKED_PROPERTY(m_property, m_linked_property) ::ClassDB::add_linked_property(get_class_static(), m_property, m_linked_property)
  136. #ifdef TOOLS_ENABLED
  137. #define ADD_CLASS_DEPENDENCY(m_class) ::ClassDB::add_class_dependency(get_class_static(), m_class)
  138. #else
  139. #define ADD_CLASS_DEPENDENCY(m_class)
  140. #endif
  141. #define ADD_ARRAY_COUNT(m_label, m_count_property, m_count_property_setter, m_count_property_getter, m_prefix) ClassDB::add_property_array_count(get_class_static(), m_label, m_count_property, StringName(m_count_property_setter), StringName(m_count_property_getter), m_prefix)
  142. #define ADD_ARRAY_COUNT_WITH_USAGE_FLAGS(m_label, m_count_property, m_count_property_setter, m_count_property_getter, m_prefix, m_property_usage_flags) ClassDB::add_property_array_count(get_class_static(), m_label, m_count_property, StringName(m_count_property_setter), StringName(m_count_property_getter), m_prefix, m_property_usage_flags)
  143. #define ADD_ARRAY(m_array_path, m_prefix) ClassDB::add_property_array(get_class_static(), m_array_path, m_prefix)
  144. // Helper macro to use with PROPERTY_HINT_ARRAY_TYPE for arrays of specific resources:
  145. // PropertyInfo(Variant::ARRAY, "fallbacks", PROPERTY_HINT_ARRAY_TYPE, MAKE_RESOURCE_TYPE_HINT("Font")
  146. #define MAKE_RESOURCE_TYPE_HINT(m_type) vformat("%s/%s:%s", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, m_type)
  147. struct PropertyInfo {
  148. Variant::Type type = Variant::NIL;
  149. String name;
  150. StringName class_name; // For classes
  151. PropertyHint hint = PROPERTY_HINT_NONE;
  152. String hint_string;
  153. uint32_t usage = PROPERTY_USAGE_DEFAULT;
  154. // If you are thinking about adding another member to this class, ask the maintainer (Juan) first.
  155. _FORCE_INLINE_ PropertyInfo added_usage(uint32_t p_fl) const {
  156. PropertyInfo pi = *this;
  157. pi.usage |= p_fl;
  158. return pi;
  159. }
  160. operator Dictionary() const;
  161. static PropertyInfo from_dict(const Dictionary &p_dict);
  162. PropertyInfo() {}
  163. PropertyInfo(const Variant::Type p_type, const String &p_name, const PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", const uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const StringName &p_class_name = StringName()) :
  164. type(p_type),
  165. name(p_name),
  166. hint(p_hint),
  167. hint_string(p_hint_string),
  168. usage(p_usage) {
  169. if (hint == PROPERTY_HINT_RESOURCE_TYPE) {
  170. class_name = hint_string;
  171. } else {
  172. class_name = p_class_name;
  173. }
  174. }
  175. PropertyInfo(const StringName &p_class_name) :
  176. type(Variant::OBJECT),
  177. class_name(p_class_name) {}
  178. explicit PropertyInfo(const GDExtensionPropertyInfo &pinfo) :
  179. type((Variant::Type)pinfo.type),
  180. name(*reinterpret_cast<StringName *>(pinfo.name)),
  181. class_name(*reinterpret_cast<StringName *>(pinfo.class_name)),
  182. hint((PropertyHint)pinfo.hint),
  183. hint_string(*reinterpret_cast<String *>(pinfo.hint_string)),
  184. usage(pinfo.usage) {}
  185. bool operator==(const PropertyInfo &p_info) const {
  186. return ((type == p_info.type) &&
  187. (name == p_info.name) &&
  188. (class_name == p_info.class_name) &&
  189. (hint == p_info.hint) &&
  190. (hint_string == p_info.hint_string) &&
  191. (usage == p_info.usage));
  192. }
  193. bool operator<(const PropertyInfo &p_info) const {
  194. return name < p_info.name;
  195. }
  196. };
  197. TypedArray<Dictionary> convert_property_list(const List<PropertyInfo> *p_list);
  198. TypedArray<Dictionary> convert_property_list(const Vector<PropertyInfo> &p_vector);
  199. enum MethodFlags {
  200. METHOD_FLAG_NORMAL = 1,
  201. METHOD_FLAG_EDITOR = 2,
  202. METHOD_FLAG_CONST = 4,
  203. METHOD_FLAG_VIRTUAL = 8,
  204. METHOD_FLAG_VARARG = 16,
  205. METHOD_FLAG_STATIC = 32,
  206. METHOD_FLAG_OBJECT_CORE = 64,
  207. METHOD_FLAG_VIRTUAL_REQUIRED = 128,
  208. METHOD_FLAGS_DEFAULT = METHOD_FLAG_NORMAL,
  209. };
  210. struct MethodInfo {
  211. String name;
  212. PropertyInfo return_val;
  213. uint32_t flags = METHOD_FLAGS_DEFAULT;
  214. int id = 0;
  215. Vector<PropertyInfo> arguments;
  216. Vector<Variant> default_arguments;
  217. int return_val_metadata = 0;
  218. Vector<int> arguments_metadata;
  219. int get_argument_meta(int p_arg) const {
  220. ERR_FAIL_COND_V(p_arg < -1 || p_arg > arguments.size(), 0);
  221. if (p_arg == -1) {
  222. return return_val_metadata;
  223. }
  224. return arguments_metadata.size() > p_arg ? arguments_metadata[p_arg] : 0;
  225. }
  226. inline bool operator==(const MethodInfo &p_method) const { return id == p_method.id && name == p_method.name; }
  227. inline bool operator<(const MethodInfo &p_method) const { return id == p_method.id ? (name < p_method.name) : (id < p_method.id); }
  228. operator Dictionary() const;
  229. static MethodInfo from_dict(const Dictionary &p_dict);
  230. uint32_t get_compatibility_hash() const;
  231. MethodInfo() {}
  232. explicit MethodInfo(const GDExtensionMethodInfo &pinfo) :
  233. name(*reinterpret_cast<StringName *>(pinfo.name)),
  234. return_val(PropertyInfo(pinfo.return_value)),
  235. flags(pinfo.flags),
  236. id(pinfo.id) {
  237. for (uint32_t i = 0; i < pinfo.argument_count; i++) {
  238. arguments.push_back(PropertyInfo(pinfo.arguments[i]));
  239. }
  240. const Variant *def_values = (const Variant *)pinfo.default_arguments;
  241. for (uint32_t j = 0; j < pinfo.default_argument_count; j++) {
  242. default_arguments.push_back(def_values[j]);
  243. }
  244. }
  245. MethodInfo(const String &p_name) { name = p_name; }
  246. template <typename... VarArgs>
  247. MethodInfo(const String &p_name, VarArgs... p_params) {
  248. name = p_name;
  249. arguments = Vector<PropertyInfo>{ p_params... };
  250. }
  251. MethodInfo(Variant::Type ret) { return_val.type = ret; }
  252. MethodInfo(Variant::Type ret, const String &p_name) {
  253. return_val.type = ret;
  254. name = p_name;
  255. }
  256. template <typename... VarArgs>
  257. MethodInfo(Variant::Type ret, const String &p_name, VarArgs... p_params) {
  258. name = p_name;
  259. return_val.type = ret;
  260. arguments = Vector<PropertyInfo>{ p_params... };
  261. }
  262. MethodInfo(const PropertyInfo &p_ret, const String &p_name) {
  263. return_val = p_ret;
  264. name = p_name;
  265. }
  266. template <typename... VarArgs>
  267. MethodInfo(const PropertyInfo &p_ret, const String &p_name, VarArgs... p_params) {
  268. return_val = p_ret;
  269. name = p_name;
  270. arguments = Vector<PropertyInfo>{ p_params... };
  271. }
  272. };
  273. // API used to extend in GDExtension and other C compatible compiled languages.
  274. class MethodBind;
  275. class GDExtension;
  276. struct ObjectGDExtension {
  277. GDExtension *library = nullptr;
  278. ObjectGDExtension *parent = nullptr;
  279. List<ObjectGDExtension *> children;
  280. StringName parent_class_name;
  281. StringName class_name;
  282. bool editor_class = false;
  283. bool reloadable = false;
  284. bool is_virtual = false;
  285. bool is_abstract = false;
  286. bool is_exposed = true;
  287. #ifdef TOOLS_ENABLED
  288. bool is_runtime = false;
  289. bool is_placeholder = false;
  290. #endif
  291. #ifndef DISABLE_DEPRECATED
  292. bool legacy_unexposed_class = false;
  293. #endif // DISABLE_DEPRECATED
  294. GDExtensionClassSet set;
  295. GDExtensionClassGet get;
  296. GDExtensionClassGetPropertyList get_property_list;
  297. GDExtensionClassFreePropertyList2 free_property_list2;
  298. GDExtensionClassPropertyCanRevert property_can_revert;
  299. GDExtensionClassPropertyGetRevert property_get_revert;
  300. GDExtensionClassValidateProperty validate_property;
  301. #ifndef DISABLE_DEPRECATED
  302. GDExtensionClassNotification notification;
  303. GDExtensionClassFreePropertyList free_property_list;
  304. #endif // DISABLE_DEPRECATED
  305. GDExtensionClassNotification2 notification2;
  306. GDExtensionClassToString to_string;
  307. GDExtensionClassReference reference;
  308. GDExtensionClassReference unreference;
  309. GDExtensionClassGetRID get_rid;
  310. void *class_userdata = nullptr;
  311. #ifndef DISABLE_DEPRECATED
  312. GDExtensionClassCreateInstance create_instance;
  313. #endif // DISABLE_DEPRECATED
  314. GDExtensionClassCreateInstance2 create_instance2;
  315. GDExtensionClassFreeInstance free_instance;
  316. #ifndef DISABLE_DEPRECATED
  317. GDExtensionClassGetVirtual get_virtual;
  318. GDExtensionClassGetVirtualCallData get_virtual_call_data;
  319. #endif // DISABLE_DEPRECATED
  320. GDExtensionClassGetVirtual2 get_virtual2;
  321. GDExtensionClassGetVirtualCallData2 get_virtual_call_data2;
  322. GDExtensionClassCallVirtualWithData call_virtual_with_data;
  323. GDExtensionClassRecreateInstance recreate_instance;
  324. #ifdef TOOLS_ENABLED
  325. void *tracking_userdata = nullptr;
  326. void (*track_instance)(void *p_userdata, void *p_instance) = nullptr;
  327. void (*untrack_instance)(void *p_userdata, void *p_instance) = nullptr;
  328. #endif
  329. /// A type for this Object extension.
  330. /// This is not exposed through the GDExtension API (yet) so it is inferred from above parameters.
  331. const GDType *gdtype;
  332. void create_gdtype();
  333. void destroy_gdtype();
  334. ~ObjectGDExtension();
  335. };
  336. #define GDVIRTUAL_CALL(m_name, ...) _gdvirtual_##m_name##_call(__VA_ARGS__)
  337. #define GDVIRTUAL_CALL_PTR(m_obj, m_name, ...) m_obj->_gdvirtual_##m_name##_call(__VA_ARGS__)
  338. #ifdef DEBUG_ENABLED
  339. #define GDVIRTUAL_BIND(m_name, ...) ::ClassDB::add_virtual_method(get_class_static(), _gdvirtual_##m_name##_get_method_info(), true, sarray(__VA_ARGS__));
  340. #else
  341. #define GDVIRTUAL_BIND(m_name, ...)
  342. #endif // DEBUG_ENABLED
  343. #define GDVIRTUAL_BIND_COMPAT(m_alias, ...) ::ClassDB::add_virtual_compatibility_method(get_class_static(), _gdvirtual_##m_alias##_get_method_info(), true, sarray(__VA_ARGS__));
  344. #define GDVIRTUAL_IS_OVERRIDDEN(m_name) _gdvirtual_##m_name##_overridden()
  345. #define GDVIRTUAL_IS_OVERRIDDEN_PTR(m_obj, m_name) m_obj->_gdvirtual_##m_name##_overridden()
  346. /*
  347. * The following is an incomprehensible blob of hacks and workarounds to
  348. * compensate for many of the fallacies in C++. As a plus, this macro pretty
  349. * much alone defines the object model.
  350. */
  351. /// `GDSOFTCLASS` provides `Object` functionality, such as being able to use `Object::cast_to()`.
  352. /// Use this for `Object` subclasses that are not registered in `ClassDB` (use `GDCLASS` otherwise).
  353. #define GDSOFTCLASS(m_class, m_inherits) \
  354. public: \
  355. using self_type = m_class; \
  356. using super_type = m_inherits; \
  357. static _FORCE_INLINE_ void *get_class_ptr_static() { \
  358. static int ptr; \
  359. return &ptr; \
  360. } \
  361. virtual bool is_class_ptr(void *p_ptr) const override { \
  362. return (p_ptr == get_class_ptr_static()) || m_inherits::is_class_ptr(p_ptr); \
  363. } \
  364. \
  365. protected: \
  366. _FORCE_INLINE_ bool (Object::*_get_get() const)(const StringName &p_name, Variant &) const { \
  367. return (bool (Object::*)(const StringName &, Variant &) const) & m_class::_get; \
  368. } \
  369. virtual bool _getv(const StringName &p_name, Variant &r_ret) const override { \
  370. if (m_class::_get_get() != m_inherits::_get_get()) { \
  371. if (_get(p_name, r_ret)) { \
  372. return true; \
  373. } \
  374. } \
  375. return m_inherits::_getv(p_name, r_ret); \
  376. } \
  377. _FORCE_INLINE_ bool (Object::*_get_set() const)(const StringName &p_name, const Variant &p_property) { \
  378. return (bool (Object::*)(const StringName &, const Variant &)) & m_class::_set; \
  379. } \
  380. virtual bool _setv(const StringName &p_name, const Variant &p_property) override { \
  381. if (m_inherits::_setv(p_name, p_property)) { \
  382. return true; \
  383. } \
  384. if (m_class::_get_set() != m_inherits::_get_set()) { \
  385. return _set(p_name, p_property); \
  386. } \
  387. return false; \
  388. } \
  389. _FORCE_INLINE_ void (Object::*_get_validate_property() const)(PropertyInfo & p_property) const { \
  390. return (void (Object::*)(PropertyInfo &) const) & m_class::_validate_property; \
  391. } \
  392. virtual void _validate_propertyv(PropertyInfo &p_property) const override { \
  393. m_inherits::_validate_propertyv(p_property); \
  394. if (m_class::_get_validate_property() != m_inherits::_get_validate_property()) { \
  395. _validate_property(p_property); \
  396. } \
  397. } \
  398. _FORCE_INLINE_ bool (Object::*_get_property_can_revert() const)(const StringName &p_name) const { \
  399. return (bool (Object::*)(const StringName &) const) & m_class::_property_can_revert; \
  400. } \
  401. virtual bool _property_can_revertv(const StringName &p_name) const override { \
  402. if (m_class::_get_property_can_revert() != m_inherits::_get_property_can_revert()) { \
  403. if (_property_can_revert(p_name)) { \
  404. return true; \
  405. } \
  406. } \
  407. return m_inherits::_property_can_revertv(p_name); \
  408. } \
  409. _FORCE_INLINE_ bool (Object::*_get_property_get_revert() const)(const StringName &p_name, Variant &) const { \
  410. return (bool (Object::*)(const StringName &, Variant &) const) & m_class::_property_get_revert; \
  411. } \
  412. virtual bool _property_get_revertv(const StringName &p_name, Variant &r_ret) const override { \
  413. if (m_class::_get_property_get_revert() != m_inherits::_get_property_get_revert()) { \
  414. if (_property_get_revert(p_name, r_ret)) { \
  415. return true; \
  416. } \
  417. } \
  418. return m_inherits::_property_get_revertv(p_name, r_ret); \
  419. } \
  420. _FORCE_INLINE_ void (Object::*_get_notification() const)(int) { \
  421. return (void (Object::*)(int)) & m_class::_notification; \
  422. } \
  423. virtual void _notification_forwardv(int p_notification) override { \
  424. m_inherits::_notification_forwardv(p_notification); \
  425. if (m_class::_get_notification() != m_inherits::_get_notification()) { \
  426. _notification(p_notification); \
  427. } \
  428. } \
  429. virtual void _notification_backwardv(int p_notification) override { \
  430. if (m_class::_get_notification() != m_inherits::_get_notification()) { \
  431. _notification(p_notification); \
  432. } \
  433. m_inherits::_notification_backwardv(p_notification); \
  434. } \
  435. \
  436. private:
  437. /// `GDSOFTCLASS` provides `Object` functionality, such as being able to use `Object::cast_to()`.
  438. /// Use this for `Object` subclasses that are registered in `ObjectDB` (use `GDSOFTCLASS` otherwise).
  439. #define GDCLASS(m_class, m_inherits) \
  440. GDSOFTCLASS(m_class, m_inherits) \
  441. private: \
  442. void operator=(const m_class &p_rval) {} \
  443. friend class ::ClassDB; \
  444. \
  445. public: \
  446. virtual const GDType &_get_typev() const override { \
  447. return get_gdtype_static(); \
  448. } \
  449. static const GDType &get_gdtype_static() { \
  450. static GDType *_class_static; \
  451. if (unlikely(!_class_static)) { \
  452. assign_type_static(&_class_static, #m_class, &super_type::get_gdtype_static()); \
  453. } \
  454. return *_class_static; \
  455. } \
  456. static const StringName &get_class_static() { \
  457. return get_gdtype_static().get_name(); \
  458. } \
  459. \
  460. protected: \
  461. _FORCE_INLINE_ static void (*_get_bind_methods())() { \
  462. return &m_class::_bind_methods; \
  463. } \
  464. _FORCE_INLINE_ static void (*_get_bind_compatibility_methods())() { \
  465. return &m_class::_bind_compatibility_methods; \
  466. } \
  467. \
  468. public: \
  469. static void initialize_class() { \
  470. static bool initialized = false; \
  471. if (initialized) { \
  472. return; \
  473. } \
  474. m_inherits::initialize_class(); \
  475. _add_class_to_classdb(get_gdtype_static(), &super_type::get_gdtype_static()); \
  476. if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods()) { \
  477. _bind_methods(); \
  478. } \
  479. if (m_class::_get_bind_compatibility_methods() != m_inherits::_get_bind_compatibility_methods()) { \
  480. _bind_compatibility_methods(); \
  481. } \
  482. initialized = true; \
  483. } \
  484. \
  485. protected: \
  486. virtual void _initialize_classv() override { \
  487. initialize_class(); \
  488. } \
  489. _FORCE_INLINE_ void (Object::*_get_get_property_list() const)(List<PropertyInfo> * p_list) const { \
  490. return (void (Object::*)(List<PropertyInfo> *) const) & m_class::_get_property_list; \
  491. } \
  492. virtual void _get_property_listv(List<PropertyInfo> *p_list, bool p_reversed) const override { \
  493. if (!p_reversed) { \
  494. m_inherits::_get_property_listv(p_list, p_reversed); \
  495. } \
  496. p_list->push_back(PropertyInfo(Variant::NIL, get_class_static(), PROPERTY_HINT_NONE, get_class_static(), PROPERTY_USAGE_CATEGORY)); \
  497. _get_property_list_from_classdb(#m_class, p_list, true, this); \
  498. if (m_class::_get_get_property_list() != m_inherits::_get_get_property_list()) { \
  499. _get_property_list(p_list); \
  500. } \
  501. if (p_reversed) { \
  502. m_inherits::_get_property_listv(p_list, p_reversed); \
  503. } \
  504. } \
  505. \
  506. private:
  507. #define OBJ_SAVE_TYPE(m_class) \
  508. public: \
  509. virtual String get_save_class() const override { \
  510. return #m_class; \
  511. } \
  512. \
  513. private:
  514. class ClassDB;
  515. class ScriptInstance;
  516. class Object {
  517. public:
  518. typedef Object self_type;
  519. enum ConnectFlags {
  520. CONNECT_DEFERRED = 1,
  521. CONNECT_PERSIST = 2, // Hint for scene to save this connection.
  522. CONNECT_ONE_SHOT = 4,
  523. CONNECT_REFERENCE_COUNTED = 8,
  524. CONNECT_APPEND_SOURCE_OBJECT = 16,
  525. CONNECT_INHERITED = 32, // Used in editor builds.
  526. };
  527. // Store on each object a bitfield to quickly test whether it is derived from some "key" classes
  528. // that are commonly tested in performance sensitive code.
  529. // Ensure unsigned to bitpack.
  530. enum class AncestralClass : unsigned int {
  531. REF_COUNTED = 1 << 0,
  532. NODE = 1 << 1,
  533. RESOURCE = 1 << 2,
  534. SCRIPT = 1 << 3,
  535. CANVAS_ITEM = 1 << 4,
  536. CONTROL = 1 << 5,
  537. NODE_2D = 1 << 6,
  538. COLLISION_OBJECT_2D = 1 << 7,
  539. AREA_2D = 1 << 8,
  540. NODE_3D = 1 << 9,
  541. VISUAL_INSTANCE_3D = 1 << 10,
  542. GEOMETRY_INSTANCE_3D = 1 << 11,
  543. COLLISION_OBJECT_3D = 1 << 12,
  544. PHYSICS_BODY_3D = 1 << 13,
  545. MESH_INSTANCE_3D = 1 << 14,
  546. };
  547. static constexpr AncestralClass static_ancestral_class = (AncestralClass)0;
  548. struct Connection {
  549. ::Signal signal;
  550. Callable callable;
  551. uint32_t flags = 0;
  552. bool operator<(const Connection &p_conn) const;
  553. operator Variant() const;
  554. Connection() {}
  555. Connection(const Variant &p_variant);
  556. };
  557. private:
  558. #ifdef DEBUG_ENABLED
  559. friend struct _ObjectDebugLock;
  560. #endif // DEBUG_ENABLED
  561. friend bool predelete_handler(Object *);
  562. friend void postinitialize_handler(Object *);
  563. ObjectGDExtension *_extension = nullptr;
  564. GDExtensionClassInstancePtr _extension_instance = nullptr;
  565. struct SignalData {
  566. struct Slot {
  567. int reference_count = 0;
  568. Connection conn;
  569. List<Connection>::Element *cE = nullptr;
  570. };
  571. MethodInfo user;
  572. HashMap<Callable, Slot> slot_map;
  573. bool removable = false;
  574. };
  575. friend struct _ObjectSignalLock;
  576. mutable Mutex *signal_mutex = nullptr;
  577. HashMap<StringName, SignalData> signal_map;
  578. List<Connection> connections;
  579. #ifdef DEBUG_ENABLED
  580. SafeRefCount _lock_index;
  581. #endif // DEBUG_ENABLED
  582. ObjectID _instance_id;
  583. bool _predelete();
  584. void _initialize();
  585. void _postinitialize();
  586. uint32_t _ancestry : 15;
  587. bool _block_signals : 1;
  588. bool _can_translate : 1;
  589. bool _emitting : 1;
  590. bool _predelete_ok : 1;
  591. public:
  592. bool _is_queued_for_deletion : 1; // Set to true by SceneTree::queue_delete().
  593. private:
  594. #ifdef TOOLS_ENABLED
  595. bool _edited : 1;
  596. uint32_t _edited_version = 0;
  597. HashSet<String> editor_section_folding;
  598. #endif
  599. ScriptInstance *script_instance = nullptr;
  600. HashMap<StringName, Variant> metadata;
  601. HashMap<StringName, Variant *> metadata_properties;
  602. mutable const GDType *_gdtype_ptr = nullptr;
  603. void _reset_gdtype() const;
  604. void _add_user_signal(const String &p_name, const Array &p_args = Array());
  605. bool _has_user_signal(const StringName &p_name) const;
  606. void _remove_user_signal(const StringName &p_name);
  607. Error _emit_signal(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
  608. TypedArray<Dictionary> _get_signal_list() const;
  609. TypedArray<Dictionary> _get_signal_connection_list(const StringName &p_signal) const;
  610. TypedArray<Dictionary> _get_incoming_connections() const;
  611. void _set_bind(const StringName &p_set, const Variant &p_value);
  612. Variant _get_bind(const StringName &p_name) const;
  613. void _set_indexed_bind(const NodePath &p_name, const Variant &p_value);
  614. Variant _get_indexed_bind(const NodePath &p_name) const;
  615. int _get_method_argument_count_bind(const StringName &p_name) const;
  616. _FORCE_INLINE_ void _construct_object(bool p_reference);
  617. friend class RefCounted;
  618. BinaryMutex _instance_binding_mutex;
  619. struct InstanceBinding {
  620. void *binding = nullptr;
  621. void *token = nullptr;
  622. GDExtensionInstanceBindingFreeCallback free_callback = nullptr;
  623. GDExtensionInstanceBindingReferenceCallback reference_callback = nullptr;
  624. };
  625. InstanceBinding *_instance_bindings = nullptr;
  626. uint32_t _instance_binding_count = 0;
  627. Object(bool p_reference);
  628. protected:
  629. StringName _translation_domain;
  630. _FORCE_INLINE_ bool _instance_binding_reference(bool p_reference) {
  631. bool can_die = true;
  632. if (_instance_bindings) {
  633. MutexLock instance_binding_lock(_instance_binding_mutex);
  634. for (uint32_t i = 0; i < _instance_binding_count; i++) {
  635. if (_instance_bindings[i].reference_callback) {
  636. if (!_instance_bindings[i].reference_callback(_instance_bindings[i].token, _instance_bindings[i].binding, p_reference)) {
  637. can_die = false;
  638. }
  639. }
  640. }
  641. }
  642. return can_die;
  643. }
  644. // Used in gdvirtual.gen.inc
  645. void _gdvirtual_init_method_ptr(uint32_t p_compat_hash, void *&r_fn_ptr, const StringName &p_fn_name, bool p_compat) const;
  646. friend class GDExtensionMethodBind;
  647. _ALWAYS_INLINE_ const ObjectGDExtension *_get_extension() const { return _extension; }
  648. _ALWAYS_INLINE_ GDExtensionClassInstancePtr _get_extension_instance() const { return _extension_instance; }
  649. virtual void _initialize_classv() { initialize_class(); }
  650. virtual bool _setv(const StringName &p_name, const Variant &p_property) { return false; }
  651. virtual bool _getv(const StringName &p_name, Variant &r_property) const { return false; }
  652. virtual void _get_property_listv(List<PropertyInfo> *p_list, bool p_reversed) const {}
  653. virtual void _validate_propertyv(PropertyInfo &p_property) const {}
  654. virtual bool _property_can_revertv(const StringName &p_name) const { return false; }
  655. virtual bool _property_get_revertv(const StringName &p_name, Variant &r_property) const { return false; }
  656. void _notification_forward(int p_notification);
  657. void _notification_backward(int p_notification);
  658. virtual void _notification_forwardv(int p_notification) {}
  659. virtual void _notification_backwardv(int p_notification) {}
  660. virtual String _to_string();
  661. static void _bind_methods();
  662. static void _bind_compatibility_methods() {}
  663. bool _set(const StringName &p_name, const Variant &p_property) { return false; }
  664. bool _get(const StringName &p_name, Variant &r_property) const { return false; }
  665. void _get_property_list(List<PropertyInfo> *p_list) const {}
  666. void _validate_property(PropertyInfo &p_property) const {}
  667. bool _property_can_revert(const StringName &p_name) const { return false; }
  668. bool _property_get_revert(const StringName &p_name, Variant &r_property) const { return false; }
  669. void _notification(int p_notification) {}
  670. _FORCE_INLINE_ static void (*_get_bind_methods())() {
  671. return &Object::_bind_methods;
  672. }
  673. _FORCE_INLINE_ static void (*_get_bind_compatibility_methods())() {
  674. return &Object::_bind_compatibility_methods;
  675. }
  676. _FORCE_INLINE_ bool (Object::*_get_get() const)(const StringName &p_name, Variant &r_ret) const {
  677. return &Object::_get;
  678. }
  679. _FORCE_INLINE_ bool (Object::*_get_set() const)(const StringName &p_name, const Variant &p_property) {
  680. return &Object::_set;
  681. }
  682. _FORCE_INLINE_ void (Object::*_get_get_property_list() const)(List<PropertyInfo> *p_list) const {
  683. return &Object::_get_property_list;
  684. }
  685. _FORCE_INLINE_ void (Object::*_get_validate_property() const)(PropertyInfo &p_property) const {
  686. return &Object::_validate_property;
  687. }
  688. _FORCE_INLINE_ bool (Object::*_get_property_can_revert() const)(const StringName &p_name) const {
  689. return &Object::_property_can_revert;
  690. }
  691. _FORCE_INLINE_ bool (Object::*_get_property_get_revert() const)(const StringName &p_name, Variant &) const {
  692. return &Object::_property_get_revert;
  693. }
  694. _FORCE_INLINE_ void (Object::*_get_notification() const)(int) {
  695. return &Object::_notification;
  696. }
  697. Variant _call_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
  698. Variant _call_deferred_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
  699. virtual const GDType &_get_typev() const { return get_gdtype_static(); }
  700. TypedArray<StringName> _get_meta_list_bind() const;
  701. TypedArray<Dictionary> _get_property_list_bind() const;
  702. TypedArray<Dictionary> _get_method_list_bind() const;
  703. void _clear_internal_resource_paths(const Variant &p_var);
  704. friend class ::ClassDB;
  705. friend class PlaceholderExtensionInstance;
  706. static void _add_class_to_classdb(const GDType &p_class, const GDType *p_inherits);
  707. static void _get_property_list_from_classdb(const StringName &p_class, List<PropertyInfo> *p_list, bool p_no_inheritance, const Object *p_validator);
  708. bool _disconnect(const StringName &p_signal, const Callable &p_callable, bool p_force = false);
  709. void _define_ancestry(AncestralClass p_class) { _ancestry |= (uint32_t)p_class; }
  710. // Prefer using derives_from.
  711. bool _has_ancestry(AncestralClass p_class) const { return _ancestry & (uint32_t)p_class; }
  712. virtual bool _uses_signal_mutex() const;
  713. // Internal helper to get the current locale, taking into account the translation domain.
  714. String _get_locale() const;
  715. #ifdef TOOLS_ENABLED
  716. struct VirtualMethodTracker {
  717. void **method;
  718. VirtualMethodTracker *next;
  719. };
  720. mutable VirtualMethodTracker *virtual_method_list = nullptr;
  721. #endif
  722. public: // Should be protected, but bug in clang++.
  723. static void initialize_class();
  724. _FORCE_INLINE_ static void register_custom_data_to_otdb() {}
  725. public:
  726. void notify_property_list_changed();
  727. static void *get_class_ptr_static() {
  728. static int ptr;
  729. return &ptr;
  730. }
  731. void detach_from_objectdb();
  732. _FORCE_INLINE_ ObjectID get_instance_id() const { return _instance_id; }
  733. template <typename T, typename O>
  734. static T *cast_to(O *p_object) {
  735. // This is like dynamic_cast, but faster.
  736. // The reason is that we can assume no virtual and multiple inheritance.
  737. return p_object && p_object->template derives_from<T, O>() ? static_cast<T *>(p_object) : nullptr;
  738. }
  739. template <typename T, typename O>
  740. static const T *cast_to(const O *p_object) {
  741. return p_object && p_object->template derives_from<T, O>() ? static_cast<const T *>(p_object) : nullptr;
  742. }
  743. // cast_to versions for types that implicitly convert to Object.
  744. template <typename T>
  745. static T *cast_to(Object *p_object) {
  746. return p_object && p_object->template derives_from<T, Object>() ? static_cast<T *>(p_object) : nullptr;
  747. }
  748. template <typename T>
  749. static const T *cast_to(const Object *p_object) {
  750. return p_object && p_object->template derives_from<T, Object>() ? static_cast<const T *>(p_object) : nullptr;
  751. }
  752. enum {
  753. NOTIFICATION_POSTINITIALIZE = 0,
  754. NOTIFICATION_PREDELETE = 1,
  755. NOTIFICATION_EXTENSION_RELOADED = 2,
  756. // Internal notification to send after NOTIFICATION_PREDELETE, not bound to scripting.
  757. NOTIFICATION_PREDELETE_CLEANUP = 3,
  758. };
  759. /* TYPE API */
  760. static void assign_type_static(GDType **type_ptr, const char *p_name, const GDType *super_type);
  761. static const GDType &get_gdtype_static() {
  762. static GDType *_class_static;
  763. if (unlikely(!_class_static)) {
  764. assign_type_static(&_class_static, "Object", nullptr);
  765. }
  766. return *_class_static;
  767. }
  768. const GDType &get_gdtype() const;
  769. static const StringName &get_class_static() { return get_gdtype_static().get_name(); }
  770. _FORCE_INLINE_ String get_class() const { return get_class_name(); }
  771. virtual String get_save_class() const { return get_class(); } //class stored when saving
  772. bool is_class(const String &p_class) const;
  773. virtual bool is_class_ptr(void *p_ptr) const { return get_class_ptr_static() == p_ptr; }
  774. template <typename T, typename O>
  775. bool derives_from() const;
  776. const StringName &get_class_name() const;
  777. StringName get_class_name_for_extension(const GDExtension *p_library) const;
  778. /* IAPI */
  779. void set(const StringName &p_name, const Variant &p_value, bool *r_valid = nullptr);
  780. Variant get(const StringName &p_name, bool *r_valid = nullptr) const;
  781. void set_indexed(const Vector<StringName> &p_names, const Variant &p_value, bool *r_valid = nullptr);
  782. Variant get_indexed(const Vector<StringName> &p_names, bool *r_valid = nullptr) const;
  783. void get_property_list(List<PropertyInfo> *p_list, bool p_reversed = false) const;
  784. void validate_property(PropertyInfo &p_property) const;
  785. bool property_can_revert(const StringName &p_name) const;
  786. Variant property_get_revert(const StringName &p_name) const;
  787. bool has_method(const StringName &p_method) const;
  788. int get_method_argument_count(const StringName &p_method, bool *r_is_valid = nullptr) const;
  789. void get_method_list(List<MethodInfo> *p_list) const;
  790. Variant callv(const StringName &p_method, const Array &p_args);
  791. virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
  792. virtual Variant call_const(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
  793. template <typename... VarArgs>
  794. Variant call(const StringName &p_method, VarArgs... p_args) {
  795. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  796. const Variant *argptrs[sizeof...(p_args) + 1];
  797. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  798. argptrs[i] = &args[i];
  799. }
  800. Callable::CallError cerr;
  801. const Variant ret = callp(p_method, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args), cerr);
  802. return (cerr.error == Callable::CallError::CALL_OK) ? ret : Variant();
  803. }
  804. // Depending on the boolean, we call either the virtual function _notification_backward or _notification_forward.
  805. // - Forward calls subclasses in descending order (e.g. Object -> Node -> Node3D -> extension -> script).
  806. // Backward calls subclasses in descending order (e.g. script -> extension -> Node3D -> Node -> Object).
  807. _FORCE_INLINE_ void notification(int p_notification, bool p_reversed = false) {
  808. if (p_reversed) {
  809. _notification_backward(p_notification);
  810. } else {
  811. _notification_forward(p_notification);
  812. }
  813. }
  814. String to_string();
  815. // Used mainly by script, get and set all INCLUDING string.
  816. virtual Variant getvar(const Variant &p_key, bool *r_valid = nullptr) const;
  817. virtual void setvar(const Variant &p_key, const Variant &p_value, bool *r_valid = nullptr);
  818. /* SCRIPT */
  819. // When in debug, some non-virtual functions can be overridden.
  820. #ifdef DEBUG_ENABLED
  821. #define DEBUG_VIRTUAL virtual
  822. #else
  823. #define DEBUG_VIRTUAL
  824. #endif // DEBUG_ENABLED
  825. DEBUG_VIRTUAL void set_script(const Variant &p_script);
  826. DEBUG_VIRTUAL Variant get_script() const;
  827. DEBUG_VIRTUAL bool has_meta(const StringName &p_name) const;
  828. DEBUG_VIRTUAL void set_meta(const StringName &p_name, const Variant &p_value);
  829. DEBUG_VIRTUAL void remove_meta(const StringName &p_name);
  830. DEBUG_VIRTUAL Variant get_meta(const StringName &p_name, const Variant &p_default = Variant()) const;
  831. DEBUG_VIRTUAL void get_meta_list(List<StringName> *p_list) const;
  832. DEBUG_VIRTUAL void merge_meta_from(const Object *p_src);
  833. #ifdef TOOLS_ENABLED
  834. void set_edited(bool p_edited);
  835. bool is_edited() const;
  836. // This function is used to check when something changed beyond a point, it's used mainly for generating previews.
  837. uint32_t get_edited_version() const;
  838. #endif
  839. void set_script_instance(ScriptInstance *p_instance);
  840. _FORCE_INLINE_ ScriptInstance *get_script_instance() const { return script_instance; }
  841. void add_user_signal(const MethodInfo &p_signal);
  842. template <typename... VarArgs>
  843. Error emit_signal(const StringName &p_name, VarArgs... p_args) {
  844. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  845. const Variant *argptrs[sizeof...(p_args) + 1];
  846. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  847. argptrs[i] = &args[i];
  848. }
  849. return emit_signalp(p_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  850. }
  851. DEBUG_VIRTUAL Error emit_signalp(const StringName &p_name, const Variant **p_args, int p_argcount);
  852. DEBUG_VIRTUAL bool has_signal(const StringName &p_name) const;
  853. DEBUG_VIRTUAL void get_signal_list(List<MethodInfo> *p_signals) const;
  854. DEBUG_VIRTUAL void get_signal_connection_list(const StringName &p_signal, List<Connection> *p_connections) const;
  855. DEBUG_VIRTUAL void get_all_signal_connections(List<Connection> *p_connections) const;
  856. DEBUG_VIRTUAL int get_persistent_signal_connection_count() const;
  857. DEBUG_VIRTUAL uint32_t get_signal_connection_flags(const StringName &p_name, const Callable &p_callable) const;
  858. DEBUG_VIRTUAL void get_signals_connected_to_this(List<Connection> *p_connections) const;
  859. DEBUG_VIRTUAL Error connect(const StringName &p_signal, const Callable &p_callable, uint32_t p_flags = 0);
  860. DEBUG_VIRTUAL void disconnect(const StringName &p_signal, const Callable &p_callable);
  861. DEBUG_VIRTUAL bool is_connected(const StringName &p_signal, const Callable &p_callable) const;
  862. DEBUG_VIRTUAL bool has_connections(const StringName &p_signal) const;
  863. template <typename... VarArgs>
  864. void call_deferred(const StringName &p_name, VarArgs... p_args) {
  865. MessageQueue::get_singleton()->push_call(this, p_name, p_args...);
  866. }
  867. void set_deferred(const StringName &p_property, const Variant &p_value);
  868. void set_block_signals(bool p_block);
  869. bool is_blocking_signals() const;
  870. Variant::Type get_static_property_type(const StringName &p_property, bool *r_valid = nullptr) const;
  871. Variant::Type get_static_property_type_indexed(const Vector<StringName> &p_path, bool *r_valid = nullptr) const;
  872. // Translate message (internationalization).
  873. String tr(const StringName &p_message, const StringName &p_context = "") const;
  874. String tr_n(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context = "") const;
  875. bool is_queued_for_deletion() const;
  876. _FORCE_INLINE_ void set_message_translation(bool p_enable) { _can_translate = p_enable; }
  877. _FORCE_INLINE_ bool can_translate_messages() const { return _can_translate; }
  878. virtual StringName get_translation_domain() const;
  879. virtual void set_translation_domain(const StringName &p_domain);
  880. #ifdef TOOLS_ENABLED
  881. virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const;
  882. void editor_set_section_unfold(const String &p_section, bool p_unfolded, bool p_initializing = false);
  883. bool editor_is_section_unfolded(const String &p_section);
  884. const HashSet<String> &editor_get_section_folding() const { return editor_section_folding; }
  885. void editor_clear_section_folding() { editor_section_folding.clear(); }
  886. #endif
  887. // Used by script languages to store binding data.
  888. void *get_instance_binding(void *p_token, const GDExtensionInstanceBindingCallbacks *p_callbacks);
  889. // Used on creation by binding only.
  890. void set_instance_binding(void *p_token, void *p_binding, const GDExtensionInstanceBindingCallbacks *p_callbacks);
  891. bool has_instance_binding(void *p_token);
  892. void free_instance_binding(void *p_token);
  893. #ifdef TOOLS_ENABLED
  894. void clear_internal_extension();
  895. void reset_internal_extension(ObjectGDExtension *p_extension);
  896. bool is_extension_placeholder() const { return _extension && _extension->is_placeholder; }
  897. #endif
  898. void clear_internal_resource_paths();
  899. _ALWAYS_INLINE_ bool is_ref_counted() const { return _has_ancestry(AncestralClass::REF_COUNTED); }
  900. void cancel_free();
  901. Object();
  902. virtual ~Object();
  903. };
  904. bool predelete_handler(Object *p_object);
  905. void postinitialize_handler(Object *p_object);
  906. template <typename T, typename O>
  907. bool Object::derives_from() const {
  908. if constexpr (std::is_base_of_v<T, O>) {
  909. // We derive statically from T (or are the same class), so casting to it is trivial.
  910. return true;
  911. } else {
  912. static_assert(std::is_base_of_v<Object, O>, "derives_from can only be used with Object subclasses.");
  913. static_assert(std::is_base_of_v<O, T>, "Cannot cast argument to T because T does not derive from the argument's known class.");
  914. static_assert(std::is_same_v<std::decay_t<T>, typename T::self_type>, "T must use GDCLASS or GDSOFTCLASS.");
  915. // If there is an explicitly set ancestral class on the type, we can use that.
  916. if constexpr (T::static_ancestral_class != T::super_type::static_ancestral_class) {
  917. return _has_ancestry(T::static_ancestral_class);
  918. } else {
  919. return is_class_ptr(T::get_class_ptr_static());
  920. }
  921. }
  922. }
  923. class ObjectDB {
  924. // This needs to add up to 63, 1 bit is for reference.
  925. #define OBJECTDB_VALIDATOR_BITS 39
  926. #define OBJECTDB_VALIDATOR_MASK ((uint64_t(1) << OBJECTDB_VALIDATOR_BITS) - 1)
  927. #define OBJECTDB_SLOT_MAX_COUNT_BITS 24
  928. #define OBJECTDB_SLOT_MAX_COUNT_MASK ((uint64_t(1) << OBJECTDB_SLOT_MAX_COUNT_BITS) - 1)
  929. #define OBJECTDB_REFERENCE_BIT (uint64_t(1) << (OBJECTDB_SLOT_MAX_COUNT_BITS + OBJECTDB_VALIDATOR_BITS))
  930. struct ObjectSlot { // 128 bits per slot.
  931. uint64_t validator : OBJECTDB_VALIDATOR_BITS;
  932. uint64_t next_free : OBJECTDB_SLOT_MAX_COUNT_BITS;
  933. uint64_t is_ref_counted : 1;
  934. Object *object = nullptr;
  935. };
  936. static SpinLock spin_lock;
  937. static uint32_t slot_count;
  938. static uint32_t slot_max;
  939. static ObjectSlot *object_slots;
  940. static uint64_t validator_counter;
  941. friend class Object;
  942. friend void unregister_core_types();
  943. static void cleanup();
  944. static ObjectID add_instance(Object *p_object);
  945. static void remove_instance(Object *p_object);
  946. friend void register_core_types();
  947. static void setup();
  948. public:
  949. typedef void (*DebugFunc)(Object *p_obj, void *p_user_data);
  950. _ALWAYS_INLINE_ static Object *get_instance(ObjectID p_instance_id) {
  951. uint64_t id = p_instance_id;
  952. uint32_t slot = id & OBJECTDB_SLOT_MAX_COUNT_MASK;
  953. ERR_FAIL_COND_V(slot >= slot_max, nullptr); // This should never happen unless RID is corrupted.
  954. spin_lock.lock();
  955. uint64_t validator = (id >> OBJECTDB_SLOT_MAX_COUNT_BITS) & OBJECTDB_VALIDATOR_MASK;
  956. if (unlikely(object_slots[slot].validator != validator)) {
  957. spin_lock.unlock();
  958. return nullptr;
  959. }
  960. Object *object = object_slots[slot].object;
  961. spin_lock.unlock();
  962. return object;
  963. }
  964. template <typename T>
  965. _ALWAYS_INLINE_ static T *get_instance(ObjectID p_instance_id) {
  966. return Object::cast_to<T>(get_instance(p_instance_id));
  967. }
  968. template <typename T>
  969. _ALWAYS_INLINE_ static Ref<T> get_ref(ObjectID p_instance_id); // Defined in ref_counted.h
  970. static void debug_objects(DebugFunc p_func, void *p_user_data);
  971. static int get_object_count();
  972. };
  973. // Using `RequiredResult<T>` as the return type indicates that null will only be returned in the case of an error.
  974. // This allows GDExtension language bindings to use the appropriate error handling mechanism for that language
  975. // when null is returned (for example, throwing an exception), rather than simply returning the value.
  976. template <typename T>
  977. class RequiredResult {
  978. static_assert(!is_fully_defined_v<T> || std::is_base_of_v<Object, T>, "T must be an Object subtype");
  979. public:
  980. using element_type = T;
  981. using ptr_type = std::conditional_t<std::is_base_of_v<RefCounted, T>, Ref<T>, T *>;
  982. private:
  983. ptr_type _value = ptr_type();
  984. public:
  985. _FORCE_INLINE_ RequiredResult() = default;
  986. RequiredResult(const RequiredResult &p_other) = default;
  987. RequiredResult(RequiredResult &&p_other) = default;
  988. RequiredResult &operator=(const RequiredResult &p_other) = default;
  989. RequiredResult &operator=(RequiredResult &&p_other) = default;
  990. _FORCE_INLINE_ RequiredResult(std::nullptr_t) :
  991. RequiredResult() {}
  992. _FORCE_INLINE_ RequiredResult &operator=(std::nullptr_t) { _value = nullptr; }
  993. // These functions should not be called directly, they are only for internal use.
  994. _FORCE_INLINE_ ptr_type _internal_ptr_dont_use() const { return _value; }
  995. _FORCE_INLINE_ static RequiredResult<T> _err_return_dont_use() { return RequiredResult<T>(); }
  996. template <typename T_Other, std::enable_if_t<std::is_base_of_v<T, T_Other>, int> = 0>
  997. _FORCE_INLINE_ RequiredResult(const RequiredResult<T_Other> &p_other) :
  998. _value(p_other._value) {}
  999. template <typename T_Other, std::enable_if_t<std::is_base_of_v<T, T_Other>, int> = 0>
  1000. _FORCE_INLINE_ RequiredResult &operator=(const RequiredResult<T_Other> &p_other) {
  1001. _value = p_other._value;
  1002. return *this;
  1003. }
  1004. template <typename T_Other, std::enable_if_t<std::is_base_of_v<T, T_Other>, int> = 0>
  1005. _FORCE_INLINE_ RequiredResult(T_Other *p_ptr) :
  1006. _value(p_ptr) {}
  1007. template <typename T_Other, std::enable_if_t<std::is_base_of_v<T, T_Other>, int> = 0>
  1008. _FORCE_INLINE_ RequiredResult &operator=(T_Other *p_ptr) {
  1009. _value = p_ptr;
  1010. return *this;
  1011. }
  1012. template <typename T_Other, std::enable_if_t<std::is_base_of_v<T, T_Other>, int> = 0>
  1013. _FORCE_INLINE_ RequiredResult(const Ref<T_Other> &p_ref) :
  1014. _value(p_ref) {}
  1015. template <typename T_Other, std::enable_if_t<std::is_base_of_v<T, T_Other>, int> = 0>
  1016. _FORCE_INLINE_ RequiredResult &operator=(const Ref<T_Other> &p_ref) {
  1017. _value = p_ref;
  1018. return *this;
  1019. }
  1020. template <typename T_Other, std::enable_if_t<std::is_base_of_v<T, T_Other>, int> = 0>
  1021. _FORCE_INLINE_ RequiredResult(Ref<T_Other> &&p_ref) :
  1022. _value(std::move(p_ref)) {}
  1023. template <typename T_Other, std::enable_if_t<std::is_base_of_v<T, T_Other>, int> = 0>
  1024. _FORCE_INLINE_ RequiredResult &operator=(Ref<T_Other> &&p_ref) {
  1025. _value = std::move(p_ref);
  1026. return &this;
  1027. }
  1028. template <typename U = T, std::enable_if_t<std::is_base_of_v<RefCounted, U>, int> = 0>
  1029. _FORCE_INLINE_ RequiredResult(const Variant &p_variant) :
  1030. _value(Object::cast_to<T>(p_variant.get_validated_object())) {}
  1031. template <typename U = T, std::enable_if_t<std::is_base_of_v<RefCounted, U>, int> = 0>
  1032. _FORCE_INLINE_ RequiredResult &operator=(const Variant &p_variant) {
  1033. _value = Object::cast_to<T>(p_variant.get_validated_object());
  1034. return *this;
  1035. }
  1036. template <typename U = T, std::enable_if_t<!std::is_base_of_v<RefCounted, U>, int> = 0>
  1037. _FORCE_INLINE_ RequiredResult(const Variant &p_variant) :
  1038. _value(Object::cast_to<T>(p_variant.operator Object *())) {}
  1039. template <typename U = T, std::enable_if_t<!std::is_base_of_v<RefCounted, U>, int> = 0>
  1040. _FORCE_INLINE_ RequiredResult &operator=(const Variant &p_variant) {
  1041. _value = Object::cast_to<T>(p_variant.operator Object *());
  1042. return *this;
  1043. }
  1044. template <typename U = T, std::enable_if_t<std::is_base_of_v<RefCounted, U>, int> = 0>
  1045. _FORCE_INLINE_ element_type *ptr() const {
  1046. return *_value;
  1047. }
  1048. template <typename U = T, std::enable_if_t<!std::is_base_of_v<RefCounted, U>, int> = 0>
  1049. _FORCE_INLINE_ element_type *ptr() const {
  1050. return _value;
  1051. }
  1052. _FORCE_INLINE_ operator ptr_type() const {
  1053. return _value;
  1054. }
  1055. template <typename U = T, typename T_Other, std::enable_if_t<std::is_base_of_v<RefCounted, U> && std::is_base_of_v<U, T_Other>, int> = 0>
  1056. _FORCE_INLINE_ operator Ref<T_Other>() const {
  1057. return Ref<T_Other>(_value);
  1058. }
  1059. _FORCE_INLINE_ element_type *operator*() const {
  1060. return ptr();
  1061. }
  1062. _FORCE_INLINE_ element_type *operator->() const {
  1063. return ptr();
  1064. }
  1065. };
  1066. // Using `RequiredParam<T>` as an argument type indicates that passing null as that parameter is an error,
  1067. // that will prevent the method from doing its intended function.
  1068. // This allows GDExtension bindings to use language-specific mechanisms to prevent users from passing null,
  1069. // because it is never valid to do so.
  1070. template <typename T>
  1071. class RequiredParam {
  1072. static_assert(!is_fully_defined_v<T> || std::is_base_of_v<Object, T>, "T must be an Object subtype");
  1073. public:
  1074. static constexpr bool is_ref = std::is_base_of_v<RefCounted, T>;
  1075. using element_type = T;
  1076. using extracted_type = std::conditional_t<is_ref, const Ref<T> &, T *>;
  1077. using persistent_type = std::conditional_t<is_ref, Ref<T>, T *>;
  1078. private:
  1079. T *_value = nullptr;
  1080. _FORCE_INLINE_ RequiredParam() = default;
  1081. public:
  1082. // These functions should not be called directly, they are only for internal use.
  1083. _FORCE_INLINE_ extracted_type _internal_ptr_dont_use() const {
  1084. if constexpr (is_ref) {
  1085. // Pretend _value is a Ref, for ease of use with existing `const Ref &` accepting APIs.
  1086. // This only works as long as Ref is internally T *.
  1087. // The double indirection should be optimized away by the compiler.
  1088. static_assert(sizeof(Ref<T>) == sizeof(T *));
  1089. return *((const Ref<T> *)&_value);
  1090. } else {
  1091. return _value;
  1092. }
  1093. }
  1094. _FORCE_INLINE_ bool _is_null_dont_use() const { return _value == nullptr; }
  1095. _FORCE_INLINE_ static RequiredParam<T> _err_return_dont_use() { return RequiredParam<T>(); }
  1096. // Prevent erroneously assigning null values by explicitly removing nullptr constructor/assignment.
  1097. RequiredParam(std::nullptr_t) = delete;
  1098. RequiredParam &operator=(std::nullptr_t) = delete;
  1099. RequiredParam(const RequiredParam &p_other) = default;
  1100. RequiredParam(RequiredParam &&p_other) = default;
  1101. RequiredParam &operator=(const RequiredParam &p_other) = default;
  1102. RequiredParam &operator=(RequiredParam &&p_other) = default;
  1103. template <typename T_Other, std::enable_if_t<std::is_base_of_v<T, T_Other>, int> = 0>
  1104. _FORCE_INLINE_ RequiredParam(const RequiredParam<T_Other> &p_other) :
  1105. _value(p_other._internal_ptr_dont_use()) {}
  1106. template <typename T_Other, std::enable_if_t<std::is_base_of_v<T, T_Other>, int> = 0>
  1107. _FORCE_INLINE_ RequiredParam &operator=(const RequiredParam<T_Other> &p_other) {
  1108. _value = p_other._internal_ptr_dont_use();
  1109. return *this;
  1110. }
  1111. template <typename T_Other, std::enable_if_t<std::is_base_of_v<T, T_Other>, int> = 0>
  1112. _FORCE_INLINE_ RequiredParam(T_Other *p_ptr) :
  1113. _value(p_ptr) {}
  1114. template <typename T_Other, std::enable_if_t<std::is_base_of_v<T, T_Other>, int> = 0>
  1115. _FORCE_INLINE_ RequiredParam &operator=(T_Other *p_ptr) {
  1116. _value = p_ptr;
  1117. return *this;
  1118. }
  1119. template <typename T_Other, std::enable_if_t<std::is_base_of_v<T, T_Other>, int> = 0>
  1120. _FORCE_INLINE_ RequiredParam(const Ref<T_Other> &p_ref) :
  1121. _value(*p_ref) {}
  1122. template <typename T_Other, std::enable_if_t<std::is_base_of_v<T, T_Other>, int> = 0>
  1123. _FORCE_INLINE_ RequiredParam &operator=(const Ref<T_Other> &p_ref) {
  1124. _value = *p_ref;
  1125. return *this;
  1126. }
  1127. template <typename U = T, std::enable_if_t<std::is_base_of_v<RefCounted, U>, int> = 0>
  1128. _FORCE_INLINE_ RequiredParam(const Variant &p_variant) :
  1129. _value(Object::cast_to<T>(p_variant.get_validated_object())) {}
  1130. template <typename U = T, std::enable_if_t<std::is_base_of_v<RefCounted, U>, int> = 0>
  1131. _FORCE_INLINE_ RequiredParam &operator=(const Variant &p_variant) {
  1132. _value = Object::cast_to<T>(p_variant.get_validated_object());
  1133. return *this;
  1134. }
  1135. template <typename U = T, std::enable_if_t<!std::is_base_of_v<RefCounted, U>, int> = 0>
  1136. _FORCE_INLINE_ RequiredParam(const Variant &p_variant) :
  1137. _value(Object::cast_to<T>(p_variant.operator Object *())) {}
  1138. template <typename U = T, std::enable_if_t<!std::is_base_of_v<RefCounted, U>, int> = 0>
  1139. _FORCE_INLINE_ RequiredParam &operator=(const Variant &p_variant) {
  1140. _value = Object::cast_to<T>(p_variant.operator Object *());
  1141. return *this;
  1142. }
  1143. };
  1144. #define TMPL_EXTRACT_PARAM_OR_FAIL(m_name, m_param, m_retval, m_msg, m_editor) \
  1145. if (unlikely(m_param._is_null_dont_use())) { \
  1146. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Required object \"" _STR(m_param) "\" is null.", m_msg, m_editor); \
  1147. return m_retval; \
  1148. } \
  1149. typename std::decay_t<decltype(m_param)>::extracted_type m_name = m_param._internal_ptr_dont_use(); \
  1150. static_assert(true)
  1151. // These macros are equivalent to the ERR_FAIL_NULL*() family of macros, only for RequiredParam<T> instead of raw pointers.
  1152. #define EXTRACT_PARAM_OR_FAIL(m_name, m_param) TMPL_EXTRACT_PARAM_OR_FAIL(m_name, m_param, void(), "", false)
  1153. #define EXTRACT_PARAM_OR_FAIL_MSG(m_name, m_param, m_msg) TMPL_EXTRACT_PARAM_OR_FAIL(m_name, m_param, void(), m_msg, false)
  1154. #define EXTRACT_PARAM_OR_FAIL_EDMSG(m_name, m_param, m_msg) TMPL_EXTRACT_PARAM_OR_FAIL(m_name, m_param, void(), m_msg, true)
  1155. #define EXTRACT_PARAM_OR_FAIL_V(m_name, m_param, m_retval) TMPL_EXTRACT_PARAM_OR_FAIL(m_name, m_param, m_retval, "", false)
  1156. #define EXTRACT_PARAM_OR_FAIL_V_MSG(m_name, m_param, m_retval, m_msg) TMPL_EXTRACT_PARAM_OR_FAIL(m_name, m_param, m_retval, m_msg, false)
  1157. #define EXTRACT_PARAM_OR_FAIL_V_EDMSG(m_name, m_param, m_retval, m_msg) TMPL_EXTRACT_PARAM_OR_FAIL(m_name, m_param, m_retval, m_msg, true)