godotengine / godot-cpp

C++ bindings for the Godot script API
MIT License
1.58k stars 474 forks source link

ClassDB macros and class registration #1476

Open Kehom opened 1 month ago

Kehom commented 1 month ago

Godot version

4.3 beta 1

godot-cpp version

master

System information

Windows 10 and Linux Mint

Issue description

I recently updated the godot-cpp for my project and noticed now that abstract classes require register_abstract_class<>(). Yet, if we want an internal abstract class we can't with any of the public functions. Would there be a problem if a public function could be provided allowing any possible combination? Or in other words, make the _register_class() template function public.

While taking a look at the class_db.hpp file I noticed there are a few macros meant for class registration, however none of them takes into account a project that doesn't use the godot namespace.

Steps to reproduce

-

Minimal reproduction project

-

AThousandShips commented 1 month ago

In the engine itself classes can only be internal or abstract, this should be matched in extensions, so if it's not by design it has to be changed there first and then here

dsnopek commented 1 month ago

While taking a look at the _classdb.hpp file I noticed there are a few macros meant for class registration, however none of them takes into account a project that doesn't use the godot namespace.

I just made PR https://github.com/godotengine/godot-cpp/pull/1477 to address the namespace issue

Kehom commented 1 month ago

In the engine itself classes can only be internal or abstract, this should be matched in extensions, so if it's not by design it has to be changed there first and then here

It's not that big of a deal. I have an internal class that provides a lot of common code for two different use cases. It would be "better" if it could be abstract, but since I'm not exposing it I know the base class will not be directly used either.