deconstructing-godot icon indicating copy to clipboard operation
deconstructing-godot copied to clipboard

Tutorial on how Godot uses c++ typedef

Open jak6jak opened this issue 3 years ago • 3 comments

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?

jak6jak avatar Oct 13 '20 00:10 jak6jak

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.

capnm avatar Oct 13 '20 02:10 capnm

@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).

willnationsdev avatar Oct 13 '20 19:10 willnationsdev

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 :wink:

capnm avatar Oct 14 '20 08:10 capnm