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

Add GDExtension C++ code snippets to GettingStarted

Open dementive opened this issue 1 year ago • 4 comments

I have been writing a project entirely in GDExtension C++ and I noticed the Godot 3.6 documentation had C++ snippets all over but there are still not any C++ snippets for anything in the 4.0 docs.

So I'd like to start an effort to get all of these filled out because GDExtension is extremely usable at this point in my opinion. Unfortunately it is not very accessible to most due to the current lack of documentation (unless you are sadistic and actually enjoy reading C++ source code to find out how to do things like me).

I figured it would be best to start at the beginning of the docs with the first place code blocks found in scripting_first_script.rst. I want to get some feedback on this and if the way I am doing it is acceptable I can go through and do a lot more of them, transcribing Gdscript to C++ is a pretty trivial and mindless task for me at this point so I can get through a lot of them pretty quickly I feel, especially with some help from other C++ fellas.

To ensure the documentation I am writing is both consistently formatted and actually correct. I have a specific setup to make sure I'm not writing nonsense code that doesn't work.

  1. Setting up a basic GDExtension project to write the documentation in so I can use clangd to ensure all the code I'm writing and adding to the docs will actually compile without benign easy to find errors.

  2. Compiling my code, testing it in the editor (if possible) and making sure it is actually doing what the documentation describes.

  3. Before I add any of my code to the documentation blocks I run clang-format -i ./File.cpp from inside the Godot repository to ensure the formatting uses the exact same rules Godot source code would. There are some formatting things clang-format won't enforce, so I'm also comparing my style to the code style of godot-cpp's header files and trying to make sure they are always the exact same.

  4. Building the docs and testing that my changes actually did what they were supposed to.

If I am doing anything wrong here or you think my process could be improved let me know! If everything here looks good let me know and I'll keep working through these to add C++ code blocks everywhere.

dementive avatar Aug 23 '24 17:08 dementive

Should be all good now. I worked through everything you mentioned, thanks for the detailed feedback!

I am going to try to finish up the "Listening to player input" section over the weekend. Also will add a info box to the top of the "Using Signals" article with a link to the bottom of the "GDExtension Example" documentation that discussed signals. This seems like it will be sufficient since the articles are both basically identical, I don't see a point in filling out the "Using Signals" article with C++ snippets when the same info is in another place.

Looking forward I don't really see a point in adding C++ snippets to either of the "Your first X game" sections because if it is a users first attempt at using Godot they really shouldn't use C++ (in my opinion) since they will need to know a good amount of gdscript to effectively use GDExtension anyway.

So I'm thinking this will be good to merge once I finish up "Listening to player input" and "Using Signals".

dementive avatar Aug 23 '24 18:08 dementive

This is absolutely lovely, I wish knew about this and #9837 when learning GDExtension!

I wonder how to link this best from the GDExtension tutorial? I only found out by browsing PR list, after I already went through the path of reading source code and error traces.

Maarrk avatar Jan 29 '25 11:01 Maarrk

Merged in your changes and squashed, should be good to go now.

dementive avatar Feb 04 '25 19:02 dementive

Thanks so much @dementive ! Regarding the Your First Game tutorials: When I was learning to use C++ with GDNative in Godot 3, I found the C++ snippets to be extremely helpful in translating between GDScript and C++. So while I understand your reasoning behind skipping those, I would still love to help fill them in.

Fortunately, @j-dax has already written C++ code for version 4.3's Your First 2D Game tutorial. My plan is to try to convert that code into snippets (and update them for 4.6 where needed). Once they're ready, or if I need some debugging help, I'll post an update here!

kburchfiel avatar Nov 05 '25 04:11 kburchfiel