Skip to content

Commit b5ab538

Browse files
committed
Add a section to godot-cpp explaining core types and where to find their documentation.
1 parent 4541167 commit b5ab538

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

engine_details/architecture/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
:allow_comments: False
22

3+
.. _doc_engine_architecture:
4+
35
Engine architecture
46
===================
57

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.. _doc_godot_cpp_core_types:
2+
3+
Core functions and types
4+
========================
5+
6+
godot-cpp's API is designed to be as similar as possible to Godot's internal API.
7+
8+
That means that, in general, you can use the :ref:`Engine details <doc_engine_architecture>` section to learn how to
9+
work with godot-cpp. In addition, it can often be useful to browse the `engine's code <https://github.com/godotengine/godot>`__
10+
for examples for how to work with Godot's API.
11+
12+
That being said, there are some differences to be aware of, which are documented in this section.
13+
14+
Core types
15+
==========
16+
17+
Godot's :ref:`Core types <doc_core_types>` are also available in godot-cpp, and the same recommendations apply
18+
as described in the article. The types are regularly synchronized with changes made to them in the Godot codebase.
19+
20+
In your own code, you can also use `C++ STL types <https://en.cppreference.com/w/cpp/container.html>`__, but they won't
21+
be compatible with Godot's APIs.
22+
23+
Packed arrays
24+
-------------
25+
26+
While in Godot, the ``Packed*Array`` types are aliases of ``Vector``, in godot-cpp, they're their own types, using the
27+
Godot bindings. This is because these types, along with their methods, are exposed through the GDExtension interface,
28+
which would not be possible with the templated nature of ``Vector``.
29+
30+
In general though, the ``Packed*Array`` types work the same way as their ``Vector`` aliases. However, you should be
31+
aware that the ``Variant`` wrappers for ``Packed*Array`` treat them as pass-by-reference, while the ``Packed*Array``
32+
types themselves are pass-by-value (implemented as copy-on-write).
33+
34+
In addition, it may be of interest that GDScript calls use the ``Variant`` call interface: Any ``Packed*Array``
35+
arguments to your functions will be passed with in a ``Variant``, and unpacked from there. This can create copies of the
36+
types, so the argument you receive may be a copy of the argument that the function was called with. In practice, this
37+
means you cannot rely on whether the argument passed to you can be modified at the caller's site.
38+
39+
Object class
40+
============
41+
42+
Please refer to :ref:`doc_object_class` to learn how to work with or register your own ``Object`` types.
43+
44+
We are not aware of any major differences between the godot-cpp ``Object`` API and Godot's internal ``Object`` API,
45+
except that some methods are available in Godot's internal API that are not available in godot-cpp.
46+
47+
You should be aware that the pointer to your godot-cpp ``Object`` is different from the pointer that Godot uses
48+
internally. This is because the godot-cpp version is an extension instance, allocated separately from the original
49+
``Object``. However, in practice, this difference is usually not noticeable.

tutorials/scripting/cpp/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ the official C++ GDExtension bindings maintained as part of the Godot project.
1515
about_godot_cpp
1616
gdextension_cpp_example
1717
build_system/index
18+
core_types
1819
gdextension_docs_system

0 commit comments

Comments
 (0)