godot-cpp icon indicating copy to clipboard operation
godot-cpp copied to clipboard

Add `is_class_static` virtual method to GDCLASS macro.

Open limbonaut opened this issue 1 year ago • 3 comments

Link to proposal: https://github.com/godotengine/godot-proposals/issues/8852

In the godot-cpp, we already have get_class_static() added by GDCLASS macro. Having also an instance method virtual bool is_class_static(StringName cn) would provide an efficient comparison method to the already existing functionality.

Usage

Ref<MyBaseclass> ref = get_my_class(); // returns Ref<MySubclass>;
if (ref->is_class_static(MySubclass::get_class_static()) {
  // ...
}

limbonaut avatar Jan 10 '24 12:01 limbonaut

Thanks!

However, as I wrote on the proposal: one of godot-cpp's design goals is to have the same API as internally in the engine (at least as much as possible), so, to add an is_class_static() method to godot-cpp, we'd need to first add it to the engine itself.

dsnopek avatar Jan 10 '24 17:01 dsnopek

In your usage, i think ref->get_class() == MySubclass::get_class_static() can work great, no need to add new methods. like:

class A : public Node.
class B : public  A.

Ref<A> ref = get_my_class(); // return Ref<B>;
if (ref->get_class() == B::get_class_static() {
    // ...
}

pupil1337 avatar Apr 25 '24 06:04 pupil1337

It is possible to do this with the existing methods, just as in GDScript. What I propose is to add an efficient StringName-based comparison that would complement an already existing function in godotcpp.

limbonaut avatar Apr 27 '24 11:04 limbonaut