Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassDB: capture nature of constants as being part of a bitfield #2242

Closed
migueldeicaza opened this issue Feb 4, 2021 · 3 comments
Closed

Comments

@migueldeicaza
Copy link

Describe the project you are working on

C# and Swift bindings

Describe the problem or limitation you are having in your project

Currently constants are surfaced as enumerations, but some high-level languages like C# and Swift offer special capabilities for values that should be treated as flags, both during debugging and at the language level.

For instance:

[Flags]
enum ValidColor {
   Red = 1 << 0,
   Blue = 1 << 1,
   Green = 1 << 2
}
var myValid = ValidColor.Red | ValidColor.Blue

The Flags attribute in C# turns the debugging capability that would print "Red, Blue" as opposed as printing the value "3". In Swift this surfaces a different API that allows users to use set-like operations in the language

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add method hints to ClassDB to signal that would allow developers to flag constants in a group as being flags - that is, that they can be combined, as opposed to being alternatives or states.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

ClassDB::bind_integer_constant would take an additional parameter that would flag the enumeration as being part of flags. If any of the flags listed has this flag set, the entire enumeration is considered a flags enumeration. A new macro BIND_ENUM_CONSTANT_FLAG, peer of BIND_ENUM_CONSTANT could simplify that process.

If this enhancement will not be used often, can it be worked around with a few lines of script?

It is purely a matter of surfacing better language and debugging capabilities.

Is there a reason why this should be core and not an add-on in the asset library?

It has to be on the core method database.

@mrushyendra
Copy link

I've created a possible implementation of this proposal here, if anyone wants to build on top of it in the future and thinks is worth including in the core:
godotengine/godot@master...mrushyendra:classdb_enum_flags

@raulsntos
Copy link
Member

Was this implemented by godotengine/godot#62374?

@migueldeicaza
Copy link
Author

This has been implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants