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

Tutorial on how Godot uses c++ typedef #1

Open
jak6jak opened this issue Oct 13, 2020 · 3 comments
Open

Tutorial on how Godot uses c++ typedef #1

jak6jak opened this issue Oct 13, 2020 · 3 comments

Comments

@jak6jak
Copy link

jak6jak commented Oct 13, 2020

In the c++ tutorial would it be possible for you to cover typedef? Most of the tutorials online cover really simple cases like: typedef int int_t; Godot sometimes uses typedef in more confusing ways that I don't think most tutorials prepare you for. An example of Godot using typedefs in a complex way is here in visual_script.h:
typedef Ref<VisualScriptNode> (*VisualScriptNodeRegisterFunc)(const String &p_type);
they later use this typedef in a Map:
Map<String, VisualScriptNodeRegisterFunc> register_funcs;
Another example is here:
typedef bool (*CompareEqualFunc)(const CallableCustom *p_a, const CallableCustom *p_b);

Can you explain how these type of typedefs work and why they are used?

@capnm
Copy link

capnm commented Oct 13, 2020

I agree with jak6jak, there are tons of good C++ tutorials or books around every corner, but the Godod source code is completely undocumented and in many ways completely confusing. It would probably be more useful to create a practical tutorial on how to use the tangled Godot's source (macros, classes, signals ...) to write some basic modules.

@willnationsdev
Copy link
Owner

willnationsdev commented Oct 13, 2020

@jak6jak

Can you explain how these type of typedefs work and why they are used?

Yes, I plan to cover those eventually. Those are all "function pointers" which are typedef'd so that you don't have to rewrite the absolute garbage syntax of function pointers in C++ over and over again as you reference the same data type. Basically, they are variables that hold a function as a piece of data and allow a third-party to execute the function remotely. They look awful because they have to detail the full function signature in the typedef and then wrap the name of the data type with (*<name>).

When I cover function pointers, I'll be sure to mention them. And of course, in the main Deconstructing Godot series, we will address what things are doing as we look through code. In those later videos, if anyone has any questions, they'll be able to make a comment with a timestamp and their question, and I'll be sure to give a detailed answer for them. :-)

@capnm

the Godod source code is completely undocumented and in many ways completely confusing.

Undocumented, yeah, kinda. Completely confusing though, I would disagree. It's actually extremely readable in large portions of the codebase that I've seen, mostly because it relies on old-school C++ without too much complexity. The stuff OP referenced is actually pretty tame compared to other codebases I've seen.

It would probably be more useful to create a practical tutorial on how to use the tangled Godot's source (macros, classes, signals ...) to write some basic modules.

This is a planned lesson. Both an introduction to Macros in the GDScript to C++ series and a full summary of implementing a class for a module in the Deconstructing Godot series (and a breakdown of what is actually happening at each stage of that process).

@capnm
Copy link

capnm commented Oct 14, 2020

because it relies on old-school C++ without too much complexity...

That's true, and I appreciate that (the C++ committee extended C to a monster language;), but it also contains a lot of "feature" and "macro" junk that has been picked up and expanded over the years by the many different contributors...

Bildschirmfoto von 2020-10-14 10-49-45
😉

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

No branches or pull requests

3 participants