-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Your Godot version:
Godot 4.5 (stable branch of the documentation)
Issue description:
The new godot-cpp documentation page could do with being expanded.
It covers the essentials for setting up and compiling a project, plus a bit on method binding, properties, and signals. It then describes the documentation compilation system. However, a lot of the details of actually using it are not discussed. It's clearly a work in progress but I wanted to mark the issue explicitly here (since I would find more documentation helpful) and also note some topics I found that could do with more discussion or links for.
- Memory Allocation -- Explain the correct ways to manage memory in godot-cpp. The engine architecture section touches on this with
memnew
,memdelete
, etc. but it'd be helpful to cover either what parts of that should be used in addons or link directly to the page if it's all applicable. - Memory Management -- There's a big difference between how we handle ReferenceCounted objects (
Ref<SomeType>
) vs Node objects (allocate as usual, must free manually iff detached from the tree) vs everything else (full manual memory management); it'd be helpful to lay that out somewhere clearly. - Variable Types -- My impression is that we should prefer using standard c99 data types for simple things but prefer engine container templates (
Vector
,List
,HashMap
,HashSet
,String
,StringName
) over e.g. the STL, but that's just a guess based on the engine documentation. Also, it looks like there are some templates (RBMap
,VMap
) undocumented even in the engine docs section. - Class Registration -- The steps for this are covered in the Getting Started section in aggregate, but an explicit list of steps would be nice. I think they are this (but I might be wrong):
#include
a Godot class (at least Object) and inherit from it.#include godot_cpp/classes/wrapped.hpp
and placeGDCLASS(YourClass, ParentClass)
at the top of the declaration.- Create a
_bind_methods
function, use_bind_method
andADD_PROPERTY
macros to register methods and properties. - In the module initialization
initialize_gdextension_types
, useGDREGISTER_RUNTIME_CLASS
to register the class.
- Method and Property Binding -- This is used in the Getting Started tutorial, but only explained a little. Some possible additions:
- The
ADD_GROUP
,ADD_SUBGROUP
,ADD_PROPERTYI
macros exist but aren't documented AFAICT. ADD_PROPERTY
requires that the getter and setter are bound by_bind_methods
or it will silently fail. Also, it looks like type-checking can stop the function call if there's a problem (no data corruption), but doesn't report the error.- Properties must be Variants from this list (there's a enum in Godot::Variant::Type), but Object is an option and you can restrict it further with
PROPERTY_HINT_RESOURCE_TYPE
.
- The
- Godotexteinsion File -- The GDExtension section on the descriptor file is very helpful but IMO should be linked to somewhere in the godot-cpp section too.
- Overriding Virtual Methods -- I actually don't know what the recommended way to override e.g.
_ready()
is. I can do it, but I'm not sure it's correct. It's not the same as in C#. It'd be very helpful to add the right approach somewhere.
Anyway, hopefully that is helpful; while I am willing to write a draft of it (presumably based on how the C# section is structured), it'd probably be better done by someone who didn't learn everything about this in the last two weeks -- these are basically my condensed notes. Also, aside from the in-progress documentation, godot-cpp seems to work quite well so thank you to everybody that has been working on it.
URL to the documentation page (if already existing):
https://docs.godotengine.org/en/latest/tutorials/scripting/cpp/gdextension_cpp_example.html
Edit: The documentation pages this refers to are now in the stable branch, rather than just latest.