Skip to content

Convert PtrToArg macros to regular C++ structs. #105231

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

Merged
merged 1 commit into from
Jun 9, 2025

Conversation

Ivorforce
Copy link
Member

@Ivorforce Ivorforce commented Apr 10, 2025

I'd like to reduce the number of both macro and template magic throughout Godot. Some of it is pretty convoluted and can be simplified.

As a first step, macros should be converted to regular C++ structs as much as possible.
C style macros are difficult to edit, because they are (until called) not 'regular' code. For example, IDEs struggle to syntax highlight them, or give insights. Therefore, they are undesirable.

For this PR, I simply copy-pasted macro code to named structs. Then, I replaced the macro contents to simply instantiate the requested type with a specialization. Finally, I used my IDE to replace the macros with their contents, to avoid any mistakes with type arguments if I was manually converting.

As a second step, some of these can probably be simplified with C++ template magic in the future. But that's out of scope for this PR.

@Ivorforce Ivorforce added this to the 4.x milestone Apr 10, 2025
@Ivorforce Ivorforce requested a review from Repiteo April 10, 2025 09:26
@Ivorforce Ivorforce requested a review from a team as a code owner April 10, 2025 09:26
@Ivorforce Ivorforce force-pushed the ptr-to-arg-nomacro branch from 44fcd89 to 1151d9d Compare April 10, 2025 09:30
Copy link
Contributor

@Repiteo Repiteo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than globally-defining structs with a leading underscore, could we contain them in an Internal namespace instead?

@Ivorforce Ivorforce force-pushed the ptr-to-arg-nomacro branch from 1151d9d to 42dd13f Compare April 10, 2025 18:34
@Ivorforce
Copy link
Member Author

Rather than globally-defining structs with a leading underscore, could we contain them in an Internal namespace instead?

Good idea, done!

Copy link
Contributor

@dsnopek dsnopek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I went through and compared the new templates line-by-line to the original macros, and double checked that the right ones were used in the conversion. It all looked good to me!

I also built this and run it with the godot-cpp unit tests, and it all worked, but they don't comprehensively test all possible conversions

In any case, this looks great to me!

@Ivorforce Ivorforce force-pushed the ptr-to-arg-nomacro branch from 42dd13f to 78ae591 Compare June 7, 2025 20:17
@Ivorforce
Copy link
Member Author

Rebased and removed PtrToArgVector and PtrToArgDirectVectorFromArray, as suggested.
If they're needed in the future, we can still reference this implementation (or make a new one, it's not that complicated :) ).

Copy link
Contributor

@Repiteo Repiteo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@Repiteo Repiteo modified the milestones: 4.x, 4.5 Jun 9, 2025
@Repiteo Repiteo merged commit 01ef1c0 into godotengine:master Jun 9, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Jun 9, 2025

Thanks!

@Ivorforce Ivorforce deleted the ptr-to-arg-nomacro branch June 9, 2025 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants