Skip to content

Commit f7e8250

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

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-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: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
Common functions and macros
15+
---------------------------
16+
17+
Please refer to :ref:`doc_common_engine_methods_and_macros` for this information. The functions and macros documented
18+
there are also available in godot-cpp.
19+
20+
Core types
21+
----------
22+
23+
Godot's :ref:`Core types <doc_core_types>` are also available in godot-cpp, and the same recommendations apply
24+
as described in the article. The types are regularly synchronized with the Godot codebase.
25+
26+
In your own code, you can also use `C++ STL types <https://en.cppreference.com/w/cpp/container.html>`__, or types from
27+
any library you choose, but they won't be compatible with Godot's APIs.
28+
29+
Packed arrays
30+
~~~~~~~~~~~~~
31+
32+
While in Godot, the ``Packed*Array`` types are aliases of ``Vector``, in godot-cpp, they're their own types, using the
33+
Godot bindings. This is because these types, along with their methods, are exposed through the GDExtension interface,
34+
which would not be possible with the templated nature of ``Vector``.
35+
36+
In general though, the ``Packed*Array`` types work the same way as their ``Vector`` aliases. However, you should be
37+
aware that the ``Variant`` wrappers for ``Packed*Array`` treat them as pass-by-reference, while the ``Packed*Array``
38+
types themselves are pass-by-value (implemented as copy-on-write).
39+
40+
In addition, it may be of interest that GDScript calls use the ``Variant`` call interface: Any ``Packed*Array``
41+
arguments to your functions will be passed in a ``Variant``, and unpacked from there. This can create copies of the
42+
types, so the argument you receive may be a copy of the argument that the function was called with. In practice, this
43+
means you cannot rely on whether the argument passed to you can be modified at the caller's site.
44+
45+
Variant class
46+
-------------
47+
48+
Please refer to :ref:`doc_variant_class` to learn about how to work with ``Variant``.
49+
50+
Most importantly, you should be aware that all functions exposed through the GDExtension API must be compatible with
51+
``Variant``.
52+
53+
Object class
54+
------------
55+
56+
Please refer to :ref:`doc_object_class` to learn how to work with or register your own ``Object`` types.
57+
58+
We are not aware of any major differences between the godot-cpp ``Object`` API and Godot's internal ``Object`` API,
59+
except that some methods are available in Godot's internal API that are not available in godot-cpp.
60+
61+
You should be aware that the pointer to your godot-cpp ``Object`` is different from the pointer that Godot uses
62+
internally. This is because the godot-cpp version is an extension instance, allocated separately from the original
63+
``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)