Skip to content

Godot-cpp Section Needs Expanding #11212

@dpthorngren

Description

@dpthorngren

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.

  1. 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.
  2. 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.
  3. 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.
  4. 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):
    1. #include a Godot class (at least Object) and inherit from it.
    2. #include godot_cpp/classes/wrapped.hpp and place GDCLASS(YourClass, ParentClass) at the top of the declaration.
    3. Create a _bind_methods function, use _bind_method and ADD_PROPERTY macros to register methods and properties.
    4. In the module initialization initialize_gdextension_types, use GDREGISTER_RUNTIME_CLASS to register the class.
  5. Method and Property Binding -- This is used in the Getting Started tutorial, but only explained a little. Some possible additions:
    1. The ADD_GROUP, ADD_SUBGROUP, ADD_PROPERTYI macros exist but aren't documented AFAICT.
    2. 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.
    3. 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.
  6. 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.
  7. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions