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

Consolidate type and inheritance checks with a TypeServer. #2804

Open
willnationsdev opened this issue May 31, 2021 · 0 comments
Open

Consolidate type and inheritance checks with a TypeServer. #2804

willnationsdev opened this issue May 31, 2021 · 0 comments

Comments

@willnationsdev
Copy link
Contributor

willnationsdev commented May 31, 2021

Describe the project you are working on

Working on godotengine/godot#44879 and godotengine/godot#48201, among many other related things.

Describe the problem or limitation you are having in your project

There are specific snippets of code that query Godot's type system for various purposes.

  1. Check if a class A exists.
  2. Check if class A inherits from class B.
  3. Get the base class of A.
  4. Get the native base class of A.
  5. Get the Script associated with class of name A (if any).
  6. Instantiate class A.
  7. Find the name A associated with a resource file path P (if any).

These sorts of checks may involve different backend data structures from different sources (ClassDB, ScriptServer, EditorData custom type map, evaluating a particular Script resource or Object instance).

The checks may involve completely different algorithms depending on whether the request takes place in an editor context or not (e.g. script path to name lookup is cached in Editor context).

Each time a query of this nature is needed, the local code manually checks each applicable data source and performs inline logic for how the results of the sub-queries map to the desired result of the overall query for that use case. However, most of the time, this logic is identical and can be generalized. Currently the code is usually duplicated completely (adding to maintenance work over time) or inaccurately (leading to logical errors that need fixing).

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

Just like how similar checks for class-name-based editor icon lookups were abstracted into EditorNode::get_class_icon and EditorNode::get_object_icon, we should add a TypeServer singleton that abstracts and consolidates all logic for the 7 operations mentioned above and replaces all code in the codebase that attempts to deal with such operations. This will reduce the maintenance burden on core devs and improve both the clarity and readability of code throughout Godot Engine's codebase.

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

  1. Add TypeServer singleton that abstracts class-related query methods.
  2. Find and replace all references to ClassDB, ScriptServer, and EditorData custom type method calls that deal with the aforementioned query methods.

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

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

Relates only to internal engine operations. Irrelevant to script code.

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

2 participants