godotengine / godot-cpp

C++ bindings for the Godot script API
MIT License
1.75k stars 578 forks source link

Enums defined with enum classes in-engine are not using enum classes in godot-cpp #1620

Open aaronfranke opened 1 month ago

aaronfranke commented 1 month ago

Godot version

Godot master

godot-cpp version

Master of godot-cpp 6facde3c29abe4d8b0ff365c252c9aeb16fc5f66

System information

macOS 14.6.1 arm64

Issue description

Enums such as Key, MouseButton, MouseButtonMask, and more using enum class in-engine are not using enum class in godot-cpp, they are just using regular enum. Using enum class improves type safety, but I am not sure if Godot provides a mechanism for godot-cpp to know which enums are using enum class.

This issue is not super important because there is an easy workaround. In my project, I am using these defines that only get used when compiling as a module, and writing KEY_ in my code, which auto-replace when compiled as a module.

#if GODOT_MODULE
#define KEY_A Key::A
#define KEY_D Key::D
#define KEY_E Key::E
#define KEY_F Key::F
#define KEY_Q Key::Q
#define KEY_R Key::R
#define KEY_S Key::S
#define KEY_T Key::T
#define KEY_W Key::W
#define KEY_SHIFT Key::SHIFT

#define MOUSE_BUTTON_LEFT MouseButton::RIGHT
#define MOUSE_BUTTON_MASK_MIDDLE MouseButtonMask::MIDDLE
#define MOUSE_BUTTON_MASK_RIGHT MouseButtonMask::RIGHT
#define MOUSE_BUTTON_RIGHT MouseButton::RIGHT
#define MOUSE_BUTTON_WHEEL_UP MouseButton::WHEEL_UP
#define MOUSE_BUTTON_WHEEL_DOWN MouseButton::WHEEL_DOWN
#endif

Steps to reproduce

Try using one of the values in the Key enum in-engine vs in godot-cpp.

Minimal reproduction project

Trivial to reproduce with one line of code in a new godot-cpp GDExtension project.

dsnopek commented 1 month ago

Godot doesn't provide this information to us, but I think it would be inappropriate to add it to extension_api.json, because it's so C++-specific or even really godot-cpp-specific because we're the only binding that has the goal of being API compatible with Godot (another theoretical C++ binding that doesn't have this goal could just decide to make all enums as enum class or enum per the type of API they wish to provide).

Maybe we could maintain a list of them in godot-cpp's binding_generator.py?