Expose RID creation utilities.

* Exposed as utility functions.
* Not very useful for script, but vital for creating servers using native extensions.
This commit is contained in:
reduz 2021-08-23 20:57:52 -03:00
parent aa3c3a9ebb
commit 65ca132a80
3 changed files with 31 additions and 4 deletions

View File

@ -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() {}
};

View File

@ -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() {

View File

@ -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" />