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

C#: Implement proper generic type name printing for Godot Editor #88363

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

Delsin-Yu
Copy link
Contributor

@Delsin-Yu Delsin-Yu commented Feb 15, 2024

The current Godot Editor Implementation fetches a class_name directly from the System.Type.Name, which does not return the full definition of a generic type (only the generic parameter count).

This PR uses an algorithm created by @ZerxZ, @TML233, and @jinsediaoying for printing the actual underlying generic type definition.
Our tests have convinced us this algorithm is capable of handling all generic use cases, see the following comparison.
This advanced type-printing algorithm only runs when a cached boolean _isEditorHintCached reports true, (fallback to System.Type.Name otherwise), so it should not affect runtime performance (only one extra boolean check).

Before

image

After

image

These are the actual type header definitions in the scripts

public partial class ListItemComponent<TData> : Control { /*other*/ }

public partial class ComplexCrazyListItemComponent<T1, T2, T3, T4> : ListItemComponent<(int, float, (List<Func<List<Dictionary<List<int?>, List<int?[,,]>>>, List<(List<int>, List<int[]>)?>>>, List<int[,,][,][,,,,]>))?> { /*other*/ }

public partial class Test<T> : ComplexCrazyListItemComponent<int, float, GodotObject, List<int>> { /*other*/ }

public partial class Test2 : Test<GodotObject> { /*other*/ }

@Delsin-Yu
Copy link
Contributor Author

Delsin-Yu commented May 19, 2024

I removed the cached StringBuilder and optimized the while(true) section; however, I think we need a consensus on whether we should cache the IsEditorHint or initialize _builtinTypeNameDictionary _tupleTypeSet by default.

I wish to minimize the performance impact on runtime by this PR, where IsEditorHint calls back to the native code base (which is expensive compared to a check on cached boolean), and two collections are never called in runtime so that I don't think we should initialize them at all.

cc @raulsntos

@Delsin-Yu Delsin-Yu requested a review from raulsntos May 19, 2024 15:30
Copy link
Member

@raulsntos raulsntos left a comment

Choose a reason for hiding this comment

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

The .NET team discussed this and we think it's a good addition. The technical aspects look good, this is a code-style review.

@raulsntos raulsntos modified the milestones: 4.x, 4.4 Sep 22, 2024
@Delsin-Yu Delsin-Yu force-pushed the master branch 2 times, most recently from dc65e33 to 96f23f4 Compare September 22, 2024 17:23
@Delsin-Yu Delsin-Yu requested a review from raulsntos September 22, 2024 17:51
Co-authored-by: Raul Santos <raulsntos@gmail.com>
Copy link
Member

@raulsntos raulsntos 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 to me and works as expected. Thanks!

@akien-mga akien-mga merged commit 6bea41d into godotengine:master Sep 24, 2024
19 checks passed
@akien-mga
Copy link
Member

Thanks!

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.

4 participants