summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2022-09-02 10:41:24 +0300
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2022-09-14 08:41:09 +0300
commit36273baa7e6210d9e353144442d2699659eb1684 (patch)
tree67146b71219b43f544d9707bdaf5cc41fe960609 /include
parent420c86eb90f13194b26e8a28d8173d22bd9d064f (diff)
downloadredot-cpp-36273baa7e6210d9e353144442d2699659eb1684.tar.gz
Change PropertyInfo members to String.
Diffstat (limited to 'include')
-rw-r--r--include/godot_cpp/classes/ref.hpp12
-rw-r--r--include/godot_cpp/classes/wrapped.hpp6
-rw-r--r--include/godot_cpp/core/class_db.hpp7
-rw-r--r--include/godot_cpp/core/method_bind.hpp48
-rw-r--r--include/godot_cpp/core/property_info.hpp21
-rw-r--r--include/godot_cpp/core/type_info.hpp87
6 files changed, 106 insertions, 75 deletions
diff --git a/include/godot_cpp/classes/ref.hpp b/include/godot_cpp/classes/ref.hpp
index 671551f..0e65f48 100644
--- a/include/godot_cpp/classes/ref.hpp
+++ b/include/godot_cpp/classes/ref.hpp
@@ -240,7 +240,7 @@ public:
template <class T>
struct PtrToArg<Ref<T>> {
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
- return Ref<T>(reinterpret_cast<T*>(godot::internal::gdn_interface->object_get_instance_binding(*(const GDNativeObjectPtr *)p_ptr, godot::internal::token, &T::___binding_callbacks)));
+ return Ref<T>(reinterpret_cast<T *>(godot::internal::gdn_interface->object_get_instance_binding(*(const GDNativeObjectPtr *)p_ptr, godot::internal::token, &T::___binding_callbacks)));
}
typedef Ref<T> EncodeT;
@@ -255,7 +255,7 @@ struct PtrToArg<const Ref<T> &> {
typedef Ref<T> EncodeT;
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
- return Ref<T>(reinterpret_cast<T*>(godot::internal::gdn_interface->object_get_instance_binding(*(const GDNativeObjectPtr *)p_ptr, godot::internal::token, &T::___binding_callbacks)));
+ return Ref<T>(reinterpret_cast<T *>(godot::internal::gdn_interface->object_get_instance_binding(*(const GDNativeObjectPtr *)p_ptr, godot::internal::token, &T::___binding_callbacks)));
}
};
@@ -264,8 +264,8 @@ struct GetTypeInfo<Ref<T>, typename EnableIf<TypeInherits<RefCounted, T>::value>
static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT;
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
- static inline PropertyInfo get_class_info() {
- return PropertyInfo(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static());
+ static inline GDNativePropertyInfo get_class_info() {
+ return make_property_info(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static());
}
};
@@ -274,8 +274,8 @@ struct GetTypeInfo<const Ref<T> &, typename EnableIf<TypeInherits<RefCounted, T>
static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT;
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
- static inline PropertyInfo get_class_info() {
- return PropertyInfo(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static());
+ static inline GDNativePropertyInfo get_class_info() {
+ return make_property_info(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static());
}
};
diff --git a/include/godot_cpp/classes/wrapped.hpp b/include/godot_cpp/classes/wrapped.hpp
index cfbf6c0..7881384 100644
--- a/include/godot_cpp/classes/wrapped.hpp
+++ b/include/godot_cpp/classes/wrapped.hpp
@@ -220,10 +220,10 @@ public:
cls->plist_size = 0; \
for (const ::godot::PropertyInfo &E : list) { \
cls->plist[cls->plist_size].type = E.type; \
- cls->plist[cls->plist_size].name = _alloc_and_copy_cstr(E.name); \
+ cls->plist[cls->plist_size].name = _alloc_and_copy_cstr(E.name.utf8().get_data()); \
cls->plist[cls->plist_size].hint = E.hint; \
- cls->plist[cls->plist_size].hint_string = _alloc_and_copy_cstr(E.hint_string); \
- cls->plist[cls->plist_size].class_name = _alloc_and_copy_cstr(E.class_name); \
+ cls->plist[cls->plist_size].hint_string = _alloc_and_copy_cstr(E.hint_string.utf8().get_data()); \
+ cls->plist[cls->plist_size].class_name = _alloc_and_copy_cstr(E.class_name.utf8().get_data()); \
cls->plist[cls->plist_size].usage = E.usage; \
cls->plist_size++; \
} \
diff --git a/include/godot_cpp/core/class_db.hpp b/include/godot_cpp/core/class_db.hpp
index 02e7a79..fd8be1e 100644
--- a/include/godot_cpp/core/class_db.hpp
+++ b/include/godot_cpp/core/class_db.hpp
@@ -99,6 +99,13 @@ private:
static void initialize_class(const ClassInfo &cl);
static void bind_method_godot(const char *p_class_name, MethodBind *p_method);
+ static _FORCE_INLINE_ char *_alloc_and_copy_cstr(const char *p_str) {
+ size_t size = strlen(p_str) + 1;
+ char *ret = reinterpret_cast<char *>(memalloc(size));
+ memcpy(ret, p_str, size);
+ return ret;
+ }
+
public:
template <class T>
static void register_class();
diff --git a/include/godot_cpp/core/method_bind.hpp b/include/godot_cpp/core/method_bind.hpp
index cc332f1..1bf410b 100644
--- a/include/godot_cpp/core/method_bind.hpp
+++ b/include/godot_cpp/core/method_bind.hpp
@@ -136,16 +136,16 @@ class MethodBindVarArgBase : public MethodBind {
protected:
R(T::*method)
(const Variant **, GDNativeInt, GDNativeCallError &);
- MethodInfo method_info;
+ std::vector<GDNativePropertyInfo> arguments;
public:
virtual GDNativePropertyInfo gen_argument_type_info(int p_arg) const {
if (p_arg < 0) {
return _gen_return_type_info();
- } else if (p_arg < method_info.arguments.size()) {
- return method_info.arguments[p_arg];
+ } else if (p_arg < arguments.size()) {
+ return arguments[p_arg];
} else {
- return PropertyInfo(Variant::NIL, "vararg", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
+ return make_property_info(GDNATIVE_VARIANT_TYPE_NIL, "vararg", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
}
}
@@ -161,31 +161,51 @@ public:
ERR_FAIL(); // Can't call.
}
+ static _FORCE_INLINE_ char *_alloc_and_copy_cstr(const char *p_str) {
+ size_t size = strlen(p_str) + 1;
+ char *ret = reinterpret_cast<char *>(memalloc(size));
+ memcpy(ret, p_str, size);
+ return ret;
+ }
+
MethodBindVarArgBase(
R (T::*p_method)(const Variant **, GDNativeInt, GDNativeCallError &),
const MethodInfo &p_method_info,
bool p_return_nil_is_variant) :
- method(p_method), method_info(p_method_info) {
+ method(p_method) {
set_vararg(true);
set_const(true);
- set_argument_count(method_info.arguments.size());
- if (method_info.arguments.size()) {
+ set_argument_count(p_method_info.arguments.size());
+ if (p_method_info.arguments.size()) {
std::vector<std::string> names;
- names.reserve(method_info.arguments.size());
- for (int i = 0; i < method_info.arguments.size(); i++) {
- names.push_back(method_info.arguments[i].name);
+ names.reserve(p_method_info.arguments.size());
+ for (int i = 0; i < p_method_info.arguments.size(); i++) {
+ names.push_back(p_method_info.arguments[i].name.utf8().get_data());
+ arguments.push_back(GDNativePropertyInfo{
+ static_cast<uint32_t>(p_method_info.arguments[i].type), // uint32_t type;
+ _alloc_and_copy_cstr(p_method_info.arguments[i].name.utf8().get_data()), // const char *name;
+ _alloc_and_copy_cstr(p_method_info.arguments[i].class_name.utf8().get_data()), // const char *class_name;
+ p_method_info.arguments[i].hint, // NONE //uint32_t hint;
+ _alloc_and_copy_cstr(p_method_info.arguments[i].hint_string.utf8().get_data()), // const char *hint_string;
+ p_method_info.arguments[i].usage, // DEFAULT //uint32_t usage;
+ });
}
set_argument_names(names);
}
- if (p_return_nil_is_variant) {
- method_info.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
- }
- generate_argument_types((int)method_info.arguments.size());
+ generate_argument_types((int)p_method_info.arguments.size());
set_return(should_returns);
}
+ ~MethodBindVarArgBase() {
+ for (GDNativePropertyInfo &arg : arguments) {
+ memfree(const_cast<char *>(arg.name));
+ memfree(const_cast<char *>(arg.class_name));
+ memfree(const_cast<char *>(arg.hint_string));
+ }
+ }
+
private:
GDNativePropertyInfo _gen_return_type_info() const {
return reinterpret_cast<const Derived *>(this)->_gen_return_type_info_impl();
diff --git a/include/godot_cpp/core/property_info.hpp b/include/godot_cpp/core/property_info.hpp
index 4bdf31a..69d7fb5 100644
--- a/include/godot_cpp/core/property_info.hpp
+++ b/include/godot_cpp/core/property_info.hpp
@@ -45,26 +45,15 @@ namespace godot {
struct PropertyInfo {
Variant::Type type = Variant::NIL;
- const char *name = nullptr;
- const char *class_name = nullptr;
+ String name;
+ String class_name;
uint32_t hint = 0;
- const char *hint_string = nullptr;
+ String hint_string;
uint32_t usage = 7;
- operator GDNativePropertyInfo() const {
- GDNativePropertyInfo info;
- info.type = type;
- info.name = name;
- info.hint = hint;
- info.hint_string = hint_string;
- info.class_name = class_name;
- info.usage = usage;
- return info;
- }
-
PropertyInfo() = default;
- PropertyInfo(Variant::Type p_type, const char *p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const char *p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const char *p_class_name = "") :
+ PropertyInfo(Variant::Type p_type, const String &p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const String &p_class_name = "") :
type(p_type),
name(p_name),
hint(p_hint),
@@ -77,7 +66,7 @@ struct PropertyInfo {
}
}
- PropertyInfo(GDNativeVariantType p_type, const char *p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const char *p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const char *p_class_name = "") :
+ PropertyInfo(GDNativeVariantType p_type, const String &p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const String &p_class_name = "") :
PropertyInfo((Variant::Type)p_type, p_name, p_hint, p_hint_string, p_usage, p_class_name) {}
};
diff --git a/include/godot_cpp/core/type_info.hpp b/include/godot_cpp/core/type_info.hpp
index 99a8cbd..5ee81f2 100644
--- a/include/godot_cpp/core/type_info.hpp
+++ b/include/godot_cpp/core/type_info.hpp
@@ -68,6 +68,21 @@ struct TypeInherits {
!TypesAreSame<B volatile const, void volatile const>::value;
};
+static GDNativePropertyInfo make_property_info(GDNativeVariantType p_type, const char *p_name, uint32_t p_hint = PROPERTY_HINT_NONE, const char *p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const char *p_class_name = "") {
+ GDNativePropertyInfo info;
+ info.type = p_type;
+ info.name = p_name;
+ info.hint = p_hint;
+ info.hint_string = p_hint_string;
+ info.usage = p_usage;
+ if (p_hint == PROPERTY_HINT_RESOURCE_TYPE) {
+ info.class_name = p_hint_string;
+ } else {
+ info.class_name = p_class_name;
+ }
+ return info;
+}
+
// If the compiler fails because it's trying to instantiate the primary 'GetTypeInfo' template
// instead of one of the specializations, it's most likely because the type 'T' is not supported.
// If 'T' is a class that inherits 'Object', make sure it can see the actual class declaration
@@ -83,7 +98,7 @@ struct GetTypeInfo;
static constexpr GDNativeVariantType VARIANT_TYPE = m_var_type; \
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
static inline GDNativePropertyInfo get_class_info() { \
- return PropertyInfo(VARIANT_TYPE, ""); \
+ return make_property_info(VARIANT_TYPE, ""); \
} \
}; \
template <> \
@@ -91,7 +106,7 @@ struct GetTypeInfo;
static constexpr GDNativeVariantType VARIANT_TYPE = m_var_type; \
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
static inline GDNativePropertyInfo get_class_info() { \
- return PropertyInfo(VARIANT_TYPE, ""); \
+ return make_property_info(VARIANT_TYPE, ""); \
} \
};
@@ -101,7 +116,7 @@ struct GetTypeInfo;
static constexpr GDNativeVariantType VARIANT_TYPE = m_var_type; \
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = m_metadata; \
static inline GDNativePropertyInfo get_class_info() { \
- return PropertyInfo(VARIANT_TYPE, ""); \
+ return make_property_info(VARIANT_TYPE, ""); \
} \
}; \
template <> \
@@ -109,7 +124,7 @@ struct GetTypeInfo;
static constexpr GDNativeVariantType VARIANT_TYPE = m_var_type; \
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = m_metadata; \
static inline GDNativePropertyInfo get_class_info() { \
- return PropertyInfo(VARIANT_TYPE, ""); \
+ return make_property_info(VARIANT_TYPE, ""); \
} \
};
@@ -167,7 +182,7 @@ struct GetTypeInfo<Variant> {
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_NIL;
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
static inline GDNativePropertyInfo get_class_info() {
- return PropertyInfo(GDNATIVE_VARIANT_TYPE_NIL, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
+ return make_property_info(GDNATIVE_VARIANT_TYPE_NIL, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
}
};
@@ -176,7 +191,7 @@ struct GetTypeInfo<const Variant &> {
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_NIL;
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
static inline GDNativePropertyInfo get_class_info() {
- return PropertyInfo(GDNATIVE_VARIANT_TYPE_NIL, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
+ return make_property_info(GDNATIVE_VARIANT_TYPE_NIL, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
}
};
@@ -184,8 +199,8 @@ template <typename T>
struct GetTypeInfo<T *, typename EnableIf<TypeInherits<Object, T>::value>::type> {
static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT;
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
- static inline PropertyInfo get_class_info() {
- return PropertyInfo(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static());
+ static inline GDNativePropertyInfo get_class_info() {
+ return make_property_info(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static());
}
};
@@ -193,19 +208,19 @@ template <typename T>
struct GetTypeInfo<const T *, typename EnableIf<TypeInherits<Object, T>::value>::type> {
static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT;
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
- static inline PropertyInfo get_class_info() {
- return PropertyInfo(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static());
+ static inline GDNativePropertyInfo get_class_info() {
+ return make_property_info(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static());
}
};
-#define TEMPL_MAKE_ENUM_TYPE_INFO(m_class, m_enum, m_impl) \
- template <> \
- struct GetTypeInfo<m_impl> { \
- static const Variant::Type VARIANT_TYPE = Variant::INT; \
- static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
- static inline GDNativePropertyInfo get_class_info() { \
- return PropertyInfo(GDNATIVE_VARIANT_TYPE_INT, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_ENUM, #m_class "." #m_enum); \
- } \
+#define TEMPL_MAKE_ENUM_TYPE_INFO(m_class, m_enum, m_impl) \
+ template <> \
+ struct GetTypeInfo<m_impl> { \
+ static const Variant::Type VARIANT_TYPE = Variant::INT; \
+ static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
+ static inline GDNativePropertyInfo get_class_info() { \
+ return make_property_info(GDNATIVE_VARIANT_TYPE_INT, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_ENUM, #m_class "." #m_enum); \
+ } \
};
#define MAKE_ENUM_TYPE_INFO(m_class, m_enum) \
@@ -235,24 +250,24 @@ public:
_FORCE_INLINE_ operator Variant() const { return value; }
};
-#define TEMPL_MAKE_BITFIELD_TYPE_INFO(m_class, m_enum, m_impl) \
- template <> \
- struct GetTypeInfo<m_impl> { \
- static const Variant::Type VARIANT_TYPE = Variant::INT; \
- static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
- static inline GDNativePropertyInfo get_class_info() { \
- return PropertyInfo(GDNATIVE_VARIANT_TYPE_INT, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_BITFIELD, \
- #m_class "." #m_enum); \
- } \
- }; \
- template <> \
- struct GetTypeInfo<BitField<m_impl>> { \
- static const Variant::Type VARIANT_TYPE = Variant::INT; \
- static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
- static inline GDNativePropertyInfo get_class_info() { \
- return PropertyInfo(GDNATIVE_VARIANT_TYPE_INT, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_BITFIELD, \
- #m_class "." #m_enum); \
- } \
+#define TEMPL_MAKE_BITFIELD_TYPE_INFO(m_class, m_enum, m_impl) \
+ template <> \
+ struct GetTypeInfo<m_impl> { \
+ static const Variant::Type VARIANT_TYPE = Variant::INT; \
+ static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
+ static inline GDNativePropertyInfo get_class_info() { \
+ return make_property_info(GDNATIVE_VARIANT_TYPE_INT, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_BITFIELD, \
+ #m_class "." #m_enum); \
+ } \
+ }; \
+ template <> \
+ struct GetTypeInfo<BitField<m_impl>> { \
+ static const Variant::Type VARIANT_TYPE = Variant::INT; \
+ static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
+ static inline GDNativePropertyInfo get_class_info() { \
+ return make_property_info(GDNATIVE_VARIANT_TYPE_INT, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_BITFIELD, \
+ #m_class "." #m_enum); \
+ } \
};
#define MAKE_BITFIELD_TYPE_INFO(m_class, m_enum) \