diff options
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | binding_generator.py | 5 | ||||
-rw-r--r-- | include/godot_cpp/classes/wrapped.hpp | 29 | ||||
-rw-r--r-- | include/godot_cpp/core/class_db.hpp | 31 | ||||
-rw-r--r-- | include/godot_cpp/variant/aabb.hpp | 6 | ||||
-rw-r--r-- | include/godot_cpp/variant/variant.hpp | 1 | ||||
-rw-r--r-- | test/src/example.h | 15 | ||||
-rw-r--r-- | test/src/register_types.cpp | 3 |
8 files changed, 56 insertions, 39 deletions
@@ -74,7 +74,10 @@ so formatting is done before your changes are submitted. ## Getting started -It's a bit similar to what it was for 3.x but also a bit different. +You need the same C++ pre-requisites installed that are required for the `godot` repository. Follow the [official build instructions for your target platform](https://docs.godotengine.org/en/latest/contributing/development/compiling/index.html#building-for-target-platforms). + +Getting started with GDExtensions is a bit similar to what it was for 3.x but also a bit different. + This new approach is much more akin to how core Godot modules are structured. Compiling this repository generates a static library to be linked with your shared lib, diff --git a/binding_generator.py b/binding_generator.py index 2cb6a97..7a6fe24 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -1778,9 +1778,9 @@ def generate_global_constant_binds(api, output_dir): continue if enum_def["is_bitfield"]: - header.append(f'VARIANT_BITFIELD_CAST(godot::{enum_def["name"]});') + header.append(f'VARIANT_BITFIELD_CAST({enum_def["name"]});') else: - header.append(f'VARIANT_ENUM_CAST(godot::{enum_def["name"]});') + header.append(f'VARIANT_ENUM_CAST({enum_def["name"]});') # Variant::Type is not a global enum, but only one line, it is worth to place in this file instead of creating new file. header.append(f"VARIANT_ENUM_CAST(godot::Variant::Type);") @@ -2433,6 +2433,7 @@ def get_operator_id_name(op): "unary-": "negate", "unary+": "positive", "%": "module", + "**": "power", "<<": "shift_left", ">>": "shift_right", "&": "bit_and", diff --git a/include/godot_cpp/classes/wrapped.hpp b/include/godot_cpp/classes/wrapped.hpp index f8f921b..32caf39 100644 --- a/include/godot_cpp/classes/wrapped.hpp +++ b/include/godot_cpp/classes/wrapped.hpp @@ -48,6 +48,7 @@ typedef void GodotObject; // Base for all engine classes, to contain the pointer to the engine instance. class Wrapped { friend class GDExtensionBinding; + friend class ClassDB; friend void postinitialize_handler(Wrapped *); protected: @@ -131,17 +132,6 @@ struct EngineClassRegistration { } // namespace godot -#ifdef HOT_RELOAD_ENABLED -#define _GDCLASS_RECREATE(m_class, m_inherits) \ - m_class *new_instance = (m_class *)memalloc(sizeof(m_class)); \ - Wrapped::RecreateInstance recreate_data = { new_instance, obj, Wrapped::recreate_instance }; \ - Wrapped::recreate_instance = &recreate_data; \ - memnew_placement(new_instance, m_class); \ - return new_instance; -#else -#define _GDCLASS_RECREATE(m_class, m_inherits) return nullptr; -#endif - // Use this on top of your own classes. // Note: the trail of `***` is to keep sane diffs in PRs, because clang-format otherwise moves every `\` which makes // every line of the macro different @@ -226,15 +216,6 @@ public: return m_inherits::get_class_static(); \ } \ \ - static GDExtensionObjectPtr create(void *data) { \ - m_class *new_object = memnew(m_class); \ - return new_object->_owner; \ - } \ - \ - static GDExtensionClassInstancePtr recreate(void *data, GDExtensionObjectPtr obj) { \ - _GDCLASS_RECREATE(m_class, m_inherits); \ - } \ - \ static void notification_bind(GDExtensionClassInstancePtr p_instance, int32_t p_what, GDExtensionBool p_reversed) { \ if (p_instance && m_class::_get_notification()) { \ if (m_class::_get_notification() != m_inherits::_get_notification()) { \ @@ -437,14 +418,6 @@ public: return m_inherits::get_class_static(); \ } \ \ - static GDExtensionObjectPtr create(void *data) { \ - return nullptr; \ - } \ - \ - static GDExtensionClassInstancePtr recreate(void *data, GDExtensionObjectPtr obj) { \ - return nullptr; \ - } \ - \ static void free(void *data, GDExtensionClassInstancePtr ptr) { \ } \ \ diff --git a/include/godot_cpp/core/class_db.hpp b/include/godot_cpp/core/class_db.hpp index 4196a76..af394f0 100644 --- a/include/godot_cpp/core/class_db.hpp +++ b/include/godot_cpp/core/class_db.hpp @@ -112,6 +112,33 @@ private: template <class T, bool is_abstract> static void _register_class(bool p_virtual = false, bool p_exposed = true); + template <class T> + static GDExtensionObjectPtr _create_instance_func(void *data) { + if constexpr (!std::is_abstract_v<T>) { + T *new_object = memnew(T); + return new_object->_owner; + } else { + return nullptr; + } + } + + template <class T> + static GDExtensionClassInstancePtr _recreate_instance_func(void *data, GDExtensionObjectPtr obj) { + if constexpr (!std::is_abstract_v<T>) { +#ifdef HOT_RELOAD_ENABLED + T *new_instance = (T *)memalloc(sizeof(T)); + Wrapped::RecreateInstance recreate_data = { new_instance, obj, Wrapped::recreate_instance }; + Wrapped::recreate_instance = &recreate_data; + memnew_placement(new_instance, T); + return new_instance; +#else + return nullptr; +#endif + } else { + return nullptr; + } + } + public: template <class T> static void register_class(bool p_virtual = false); @@ -202,9 +229,9 @@ void ClassDB::_register_class(bool p_virtual, bool p_exposed) { T::to_string_bind, // GDExtensionClassToString to_string_func; nullptr, // GDExtensionClassReference reference_func; nullptr, // GDExtensionClassUnreference unreference_func; - T::create, // GDExtensionClassCreateInstance create_instance_func; /* this one is mandatory */ + &_create_instance_func<T>, // GDExtensionClassCreateInstance create_instance_func; /* this one is mandatory */ T::free, // GDExtensionClassFreeInstance free_instance_func; /* this one is mandatory */ - T::recreate, // GDExtensionClassRecreateInstance recreate_instance_func; + &_recreate_instance_func<T>, // GDExtensionClassRecreateInstance recreate_instance_func; &ClassDB::get_virtual_func, // GDExtensionClassGetVirtual get_virtual_func; nullptr, // GDExtensionClassGetVirtualCallData get_virtual_call_data_func; nullptr, // GDExtensionClassCallVirtualWithData call_virtual_func; diff --git a/include/godot_cpp/variant/aabb.hpp b/include/godot_cpp/variant/aabb.hpp index dde392b..7706d51 100644 --- a/include/godot_cpp/variant/aabb.hpp +++ b/include/godot_cpp/variant/aabb.hpp @@ -201,11 +201,11 @@ inline bool AABB::encloses(const AABB &p_aabb) const { return ( (src_min.x <= dst_min.x) && - (src_max.x > dst_max.x) && + (src_max.x >= dst_max.x) && (src_min.y <= dst_min.y) && - (src_max.y > dst_max.y) && + (src_max.y >= dst_max.y) && (src_min.z <= dst_min.z) && - (src_max.z > dst_max.z)); + (src_max.z >= dst_max.z)); } Vector3 AABB::get_support(const Vector3 &p_normal) const { diff --git a/include/godot_cpp/variant/variant.hpp b/include/godot_cpp/variant/variant.hpp index 4b58642..3c64791 100644 --- a/include/godot_cpp/variant/variant.hpp +++ b/include/godot_cpp/variant/variant.hpp @@ -122,6 +122,7 @@ public: OP_NEGATE, OP_POSITIVE, OP_MODULE, + OP_POWER, // bitwise OP_SHIFT_LEFT, OP_SHIFT_RIGHT, diff --git a/test/src/example.h b/test/src/example.h index 72f6783..c86a51f 100644 --- a/test/src/example.h +++ b/test/src/example.h @@ -198,11 +198,22 @@ protected: static void _bind_methods() {} }; -class ExampleAbstract : public Object { - GDCLASS(ExampleAbstract, Object); +class ExampleAbstractBase : public Object { + GDCLASS(ExampleAbstractBase, Object); protected: static void _bind_methods() {} + + virtual int test_function() = 0; +}; + +class ExampleConcrete : public ExampleAbstractBase { + GDCLASS(ExampleConcrete, ExampleAbstractBase); + +protected: + static void _bind_methods() {} + + virtual int test_function() override { return 25; } }; #endif // EXAMPLE_CLASS_H diff --git a/test/src/register_types.cpp b/test/src/register_types.cpp index dbb37d9..58080d2 100644 --- a/test/src/register_types.cpp +++ b/test/src/register_types.cpp @@ -25,7 +25,8 @@ void initialize_example_module(ModuleInitializationLevel p_level) { ClassDB::register_class<ExampleMin>(); ClassDB::register_class<Example>(); ClassDB::register_class<ExampleVirtual>(true); - ClassDB::register_abstract_class<ExampleAbstract>(); + ClassDB::register_abstract_class<ExampleAbstractBase>(); + ClassDB::register_class<ExampleConcrete>(); } void uninitialize_example_module(ModuleInitializationLevel p_level) { |