diff options
author | reduz <reduzio@gmail.com> | 2021-08-23 20:57:52 -0300 |
---|---|---|
committer | reduz <reduzio@gmail.com> | 2021-08-23 21:55:45 -0300 |
commit | 65ca132a80760be9f4c0fe1a175445e867bb7ac8 (patch) | |
tree | 1798a0e9c5da9047319ff3c73bf555a9e9f4f8d3 | |
parent | aa3c3a9ebbc096bba9eda324b91acbb7f14a7b07 (diff) |
Expose RID creation utilities.
* Exposed as utility functions.
* Not very useful for script, but vital for creating servers using native extensions.
-rw-r--r-- | core/templates/rid_owner.h | 10 | ||||
-rw-r--r-- | core/variant/variant_utility.cpp | 12 | ||||
-rw-r--r-- | doc/classes/@GlobalScope.xml | 13 |
3 files changed, 31 insertions, 4 deletions
diff --git a/core/templates/rid_owner.h b/core/templates/rid_owner.h index 8d139551ef..e947d2211c 100644 --- a/core/templates/rid_owner.h +++ b/core/templates/rid_owner.h @@ -53,14 +53,16 @@ protected: return rid; } - static uint64_t _gen_id() { - return base_id.increment(); - } - static RID _gen_rid() { return _make_from_id(_gen_id()); } + friend struct VariantUtilityFunctions; + + static uint64_t _gen_id() { + return base_id.increment(); + } + public: virtual ~RID_AllocBase() {} }; diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp index 6c57d1de10..f5cb2d40d6 100644 --- a/core/variant/variant_utility.cpp +++ b/core/variant/variant_utility.cpp @@ -35,6 +35,8 @@ #include "core/object/ref_counted.h" #include "core/os/os.h" #include "core/templates/oa_hash_map.h" +#include "core/templates/rid.h" +#include "core/templates/rid_owner.h" #include "core/variant/binder_common.h" #include "core/variant/variant_parser.h" @@ -728,6 +730,13 @@ struct VariantUtilityFunctions { } return p_instance.get_validated_object() != nullptr; } + + static inline uint64_t rid_allocate_id() { + return RID_AllocBase::_gen_id(); + } + static inline RID rid_from_int64(uint64_t p_base) { + return RID::from_uint64(p_base); + } }; #ifdef DEBUG_METHODS_ENABLED @@ -1265,6 +1274,9 @@ void Variant::_register_variant_utility_functions() { FUNCBINDR(instance_from_id, sarray("instance_id"), Variant::UTILITY_FUNC_TYPE_GENERAL); FUNCBINDR(is_instance_id_valid, sarray("id"), Variant::UTILITY_FUNC_TYPE_GENERAL); FUNCBINDR(is_instance_valid, sarray("instance"), Variant::UTILITY_FUNC_TYPE_GENERAL); + + FUNCBINDR(rid_allocate_id, Vector<String>(), Variant::UTILITY_FUNC_TYPE_GENERAL); + FUNCBINDR(rid_from_int64, sarray("base"), Variant::UTILITY_FUNC_TYPE_GENERAL); } void Variant::_unregister_variant_utility_functions() { diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index af39069b38..090ca5a033 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -711,6 +711,19 @@ <description> </description> </method> + <method name="rid_allocate_id"> + <return type="int" /> + <description> + Allocate a unique ID which can be used by the implementation to construct a RID. This is used mainly from native extensions to implement servers. + </description> + </method> + <method name="rid_from_int64"> + <return type="RID" /> + <argument index="0" name="base" type="int" /> + <description> + Create a RID from an int64. This is used mainly from native extensions to build servers. + </description> + </method> <method name="round"> <return type="float" /> <argument index="0" name="x" type="float" /> |