diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-10-05 10:35:54 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-10-05 10:35:54 +0200 |
commit | 91afc08de1bbd8277d96c81cf6bab0e83ceb96e7 (patch) | |
tree | 121719018cfc4791592689b46e5a872cde462a6f /include/godot_cpp | |
parent | 4e5d0ee3a8707f7065dbac6b36fcd0e77b721706 (diff) | |
parent | 5de2c059d1e793f37ed4e128694c29a15eed313d (diff) | |
download | redot-cpp-91afc08de1bbd8277d96c81cf6bab0e83ceb96e7.tar.gz |
Merge pull request #855 from Zylann/fix_issue854_virtual_methods
Fix deriving a custom class with virtual methods
Diffstat (limited to 'include/godot_cpp')
-rw-r--r-- | include/godot_cpp/classes/wrapped.hpp | 6 | ||||
-rw-r--r-- | include/godot_cpp/core/class_db.hpp | 10 |
2 files changed, 10 insertions, 6 deletions
diff --git a/include/godot_cpp/classes/wrapped.hpp b/include/godot_cpp/classes/wrapped.hpp index 62ec0d8..94f9f97 100644 --- a/include/godot_cpp/classes/wrapped.hpp +++ b/include/godot_cpp/classes/wrapped.hpp @@ -145,9 +145,9 @@ protected: return (::godot::String(::godot::Wrapped::*)()) & m_class::_to_string; \ } \ \ - template <class T> \ + template <class T, class B> \ static void register_virtuals() { \ - m_inherits::register_virtuals<T>(); \ + m_inherits::register_virtuals<T, B>(); \ } \ \ public: \ @@ -159,7 +159,7 @@ public: m_inherits::initialize_class(); \ if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods()) { \ _bind_methods(); \ - m_inherits::register_virtuals<m_class>(); \ + m_inherits::register_virtuals<m_class, m_inherits>(); \ } \ initialized = true; \ } \ diff --git a/include/godot_cpp/core/class_db.hpp b/include/godot_cpp/core/class_db.hpp index fd8be1e..89b4286 100644 --- a/include/godot_cpp/core/class_db.hpp +++ b/include/godot_cpp/core/class_db.hpp @@ -89,10 +89,12 @@ public: std::unordered_map<std::string, GDNativeExtensionClassCallVirtual> virtual_methods; std::set<std::string> property_names; std::set<std::string> constant_names; + // Pointer to the parent custom class, if any. Will be null if the parent class is a Godot class. ClassInfo *parent_ptr = nullptr; }; private: + // This may only contain custom classes, not Godot classes static std::unordered_map<std::string, ClassInfo> classes; static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const MethodDefinition &method_name, const void **p_defs, int p_defcount); @@ -158,10 +160,12 @@ void ClassDB::register_class() { cl.name = T::get_class_static(); cl.parent_name = T::get_parent_class_static(); cl.level = current_level; - classes[cl.name] = cl; - if (classes.find(cl.parent_name) != classes.end()) { - cl.parent_ptr = &classes[cl.parent_name]; + std::unordered_map<std::string, ClassInfo>::iterator parent_it = classes.find(cl.parent_name); + if (parent_it != classes.end()) { + // Assign parent if it is also a custom class + cl.parent_ptr = &parent_it->second; } + classes[cl.name] = cl; // Register this class with Godot GDNativeExtensionClassCreationInfo class_info = { |