Skip to content

Commit 8db2f3e

Browse files
authored
Merge pull request #10631 from Ivorforce/godot-cpp-up
Split C++ (godot-cpp) and GDExtension system info into separate categories, children of Scripting.
2 parents b6d0deb + 028abe1 commit 8db2f3e

20 files changed

+222
-154
lines changed

_tools/redirects/redirects.csv

+3-2
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,9 @@ source,destination
399399
/tutorials/plugins/gdnative/gdnative-c-example.html,/tutorials/scripting/gdnative/gdnative_c_example.html
400400
/tutorials/plugins/gdnative/gdnative-cpp-example.html,/tutorials/scripting/gdnative/gdnative_cpp_example.html
401401
/tutorials/plugins/gdnative/index.html,/tutorials/scripting/gdnative/index.html
402-
/tutorials/scripting/gdnative/gdnative_c_example.html,/tutorials/plugins/gdextension/gdextension_cpp_example.html
403-
/tutorials/scripting/gdnative/gdnative_cpp_example.html,/tutorials/plugins/gdextension/gdextension_cpp_example.html
402+
/tutorials/plugins/gdextension/gdextension_cpp_example.html,/tutorials/plugins/cpp/gdextension_cpp_example.html
403+
/tutorials/scripting/gdnative/gdnative_c_example.html,/tutorials/plugins/cpp/gdextension_cpp_example.html
404+
/tutorials/scripting/gdnative/gdnative_cpp_example.html,/tutorials/plugins/cpp/gdextension_cpp_example.html
404405
/tutorials/scripting/gdnative/index.html,/tutorials/scripting/gdextension/index.html
405406
/tutorials/scripting/gdnative/what_is_gdnative.html,/tutorials/scripting/gdnative/what_is_gdextension.html
406407
/tutorials/shading/advanced_postprocessing.html,/tutorials/shaders/advanced_postprocessing.html

about/docs_changelog.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ GDExtension
8484
~~~~~~~~~~~
8585

8686
- :ref:`doc_gdextension_file`
87-
- :ref:`doc_gdextension_docs_system`
87+
- :ref:`doc_godot_cpp_docs_system`
8888

8989
Migrating
9090
~~~~~~~~~

classes/class_gdextension.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Tutorials
3030

3131
- :doc:`GDExtension overview <../tutorials/scripting/gdextension/what_is_gdextension>`
3232

33-
- :doc:`GDExtension example in C++ <../tutorials/scripting/gdextension/gdextension_cpp_example>`
33+
- :doc:`GDExtension example in C++ <../tutorials/scripting/cpp/gdextension_cpp_example>`
3434

3535
.. rst-class:: classref-reftable-group
3636

classes/class_gdextensionmanager.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Tutorials
3030

3131
- :doc:`GDExtension overview <../tutorials/scripting/gdextension/what_is_gdextension>`
3232

33-
- :doc:`GDExtension example in C++ <../tutorials/scripting/gdextension/gdextension_cpp_example>`
33+
- :doc:`GDExtension example in C++ <../tutorials/scripting/cpp/gdextension_cpp_example>`
3434

3535
.. rst-class:: classref-reftable-group
3636

tutorials/platform/android/android_plugin.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ At build time, the contents of the ``export_scripts_template`` directory as well
231231
Packaging a v2 Android plugin with GDExtension capabilities
232232
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
233233

234-
For GDExtension, we follow the same steps as for `Packaging a v2 Android plugin`_ and add the `GDExtension config file <https://docs.godotengine.org/en/stable/tutorials/scripting/gdextension/gdextension_cpp_example.html#using-the-gdextension-module>`_ in
234+
For GDExtension, we follow the same steps as for `Packaging a v2 Android plugin`_ and add the `GDExtension config file <https://docs.godotengine.org/en/stable/tutorials/scripting/cpp/gdextension_cpp_example.html#using-the-gdextension-module>`_ in
235235
the same location as ``plugin.cfg``.
236236

237237
For reference, here is the `folder structure for the GDExtension Android plugin project template <https://github.com/m4gr3d/GDExtension-Android-Plugin-Template/tree/main/plugin/export_scripts_template>`_.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
.. _doc_about_godot_cpp:
2+
3+
About godot-cpp
4+
===============
5+
6+
`godot-cpp <https://github.com/godotengine/godot-cpp>`__ are the official C++ GDExtension bindings, maintained
7+
as part of the Godot project.
8+
9+
godot-cpp is built with the :ref:`GDExtension system <doc_gdextension>`, which allows access to Godot in almost the
10+
same way as :ref:`modules <doc_custom_modules_in_cpp>`: A lot of `engine code <https://github.com/godotengine/godot>`__
11+
can be used in your godot-cpp project almost exactly as it is.
12+
13+
In particular, godot-cpp has access to all functions that :ref:`GDScript <doc_gdscript>` and :ref:`C# <doc_c_sharp>`
14+
have, and additional access to a few more for fast low-level access of data, or deeper integration with Godot.
15+
16+
Differences between godot-cpp and C++ modules
17+
---------------------------------------------
18+
19+
You can use both `godot-cpp <https://github.com/godotengine/godot-cpp>`__
20+
and :ref:`C++ modules <doc_custom_modules_in_cpp>` to run C or C++ code in a Godot project.
21+
22+
They also both allow you to integrate third-party libraries into Godot. The one
23+
you should choose depends on your needs.
24+
25+
.. warning::
26+
27+
godot-cpp is currently *experimental*, which means that we may
28+
break compatibility in order to fix major bugs or include critical features.
29+
30+
31+
Advantages of godot-cpp
32+
~~~~~~~~~~~~~~~~~~~~~~~
33+
34+
Unlike modules, godot-cpp (and GDExtensions, in general) don't require
35+
compiling the engine's source code, making it easier to distribute your work.
36+
It gives you access to most of the API available to GDScript and C#, allowing
37+
you to code game logic with full control regarding performance. It's ideal if
38+
you need high-performance code you'd like to distribute as an add-on in the
39+
:ref:`asset library <doc_what_is_assetlib>`.
40+
41+
Also:
42+
43+
- You can use the same compiled godot-cpp library in the editor and exported
44+
project. With C++ modules, you have to recompile all the export templates you
45+
plan to use if you require its functionality at runtime.
46+
- godot-cpp only requires you to compile your library, not the whole engine.
47+
That's unlike C++ modules, which are statically compiled into the engine.
48+
Every time you change a module, you need to recompile the engine. Even with
49+
incremental builds, this process is slower than using godot-cpp.
50+
51+
Advantages of C++ modules
52+
~~~~~~~~~~~~~~~~~~~~~~~~~
53+
54+
We recommend :ref:`C++ modules <doc_custom_modules_in_cpp>` in cases where
55+
godot-cpp (or another GDExtension system) isn't enough:
56+
57+
- C++ modules provide deeper integration into the engine. GDExtension's access
58+
is not as deep as static modules.
59+
- You can use C++ modules to provide additional features in a project without
60+
carrying native library files around. This extends to exported projects.
61+
62+
.. note::
63+
64+
If you notice that specific systems are not accessible via godot-cpp
65+
but are via custom modules, feel free to open an issue on the
66+
`godot-cpp repository <https://github.com/godotengine/godot-cpp>`__
67+
to discuss implementation options for exposing the missing functionality.
68+
69+
.. _doc_what_is_gdextension_version_compatibility:
70+
71+
Version compatibility
72+
---------------------
73+
74+
Usually, GDExtensions targeting an earlier version of Godot will work in later
75+
minor versions, but not vice-versa. For example, a GDExtension targeting Godot 4.2
76+
should work just fine in Godot 4.3, but one targeting Godot 4.3 won't work in Godot 4.2.
77+
78+
For this reason, when creating GDExtensions, you may want to target the lowest version of
79+
Godot that has the features you need, *not* the most recent version of Godot. This can
80+
save you from needing to create multiple builds for different versions of Godot.
81+
82+
However, GDExtension is currently *experimental*, which means that we may
83+
break compatibility in order to fix major bugs or include critical features.
84+
For example, GDExtensions created for Godot 4.0 aren't compatible with Godot
85+
4.1 (see :ref:`updating_your_gdextension_for_godot_4_1`).
86+
87+
GDExtensions are also only compatible with engine builds that use the same
88+
level of floating-point precision the extension was compiled for. This means
89+
that if you use an engine build with double-precision floats, the extension must
90+
also be compiled for double-precision floats and use an ``extension_api.json``
91+
file generated by your custom engine build. See :ref:`doc_large_world_coordinates`
92+
for details.
93+
94+
Generally speaking, if you build a custom version of Godot, you should generate an
95+
``extension_api.json`` from it for your GDExtensions, because it may have some differences
96+
from official Godot builds.

tutorials/scripting/gdextension/gdextension_cpp_example.rst renamed to tutorials/scripting/cpp/gdextension_cpp_example.rst

+31-19
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
1-
.. _doc_gdextension_cpp_example:
1+
.. _doc_godot_cpp_getting_started:
22

3-
GDExtension C++ example
4-
=======================
3+
Getting started
4+
===============
55

6-
Introduction
7-
------------
6+
Workflow overview
7+
-----------------
8+
9+
As a GDExtension, godot-cpp is more complicated to use than :ref:`GDScript <doc_gdscript>` and :ref:`C# <doc_c_sharp>`.
10+
If you decide to work with it, here's what to expect your workflow to look like:
811

9-
The C++ bindings for GDExtension are built on top of the C GDExtension API
10-
and provide a nicer way to "extend" nodes and other built-in classes in Godot using C++.
11-
This new system allows the extension of Godot to nearly the same
12-
level as statically linked C++ modules.
12+
* Create a new godot-cpp project (from the `template <https://github.com/godotengine/godot-cpp-template>`__, or from scratch, as explained below).
13+
* Develop your code with your :ref:`favorite IDE <toc-devel-configuring_an_ide>` locally.
14+
* Build and test your code with the earliest compatible Godot version.
15+
* Create builds for all platforms you want to support (e.g. using `GitHub Actions <https://github.com/godotengine/godot-cpp-template/blob/main/.github/workflows/builds.yml>`__).
16+
* Optional: Publish on the `Godot Asset Library <https://godotengine.org/asset-library/asset>`__.
1317

14-
You can download the included example in the test folder of the godot-cpp
15-
repository `on GitHub <https://github.com/godotengine/godot-cpp>`__.
18+
Example project
19+
---------------
20+
21+
For your first godot-cpp project, we recommend starting with this guide to understand the technology involved with
22+
godot-cpp. After you're done, you can use the `godot-cpp template <https://github.com/godotengine/godot-cpp-template>`__,
23+
which has better coverage of features, such as a GitHub action pipeline and useful ``SConstruct`` boilerplate code.
24+
However, the template does not explain itself to a high level of detail, which is why we recommend going through this
25+
guide first.
1626

1727
Setting up the project
1828
----------------------
1929

2030
There are a few prerequisites you'll need:
2131

22-
- a Godot 4 executable,
23-
- a C++ compiler,
24-
- SCons as a build tool,
25-
- a copy of the `godot-cpp
26-
repository <https://github.com/godotengine/godot-cpp>`__.
32+
- A Godot 4 executable.
33+
- A C++ compiler.
34+
- SCons as a build tool.
35+
- A copy of the `godot-cpp repository <https://github.com/godotengine/godot-cpp>`__.
2736

2837
See also :ref:`Configuring an IDE <toc-devel-configuring_an_ide>`
2938
and :ref:`Compiling <toc-devel-compiling>` as the build tools are identical
@@ -712,6 +721,9 @@ Every second, we output our position to the console.
712721
Next steps
713722
----------
714723

715-
We hope the above example showed you the basics. You can
716-
build upon this example to create full-fledged scripts to control nodes in Godot
717-
using C++.
724+
We hope the above example showed you the basics. You can build upon this example to create full-fledged scripts
725+
to control nodes in Godot using C++!
726+
727+
Instead of basing your project off the above example setup, we recommend to restart now by cloning the
728+
`godot-cpp template <https://github.com/godotengine/godot-cpp-template>`__, and base your project off of that.
729+
It has better coverage of features, such as a GitHub build action and additional useful ``SConstruct`` boilerplate.

tutorials/scripting/gdextension/gdextension_docs_system.rst renamed to tutorials/scripting/cpp/gdextension_docs_system.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
.. _doc_gdextension_docs_system:
1+
.. _doc_godot_cpp_docs_system:
22

3-
GDExtension documentation system
4-
================================
3+
Adding documentation
4+
====================
55

66
.. note::
77

@@ -15,7 +15,7 @@ XML files (one per class) to document the exposed constructors, properties, meth
1515

1616
.. note::
1717

18-
We are assuming you are using the project files explained in the :ref:`GDExtension C++ Example <doc_gdextension_cpp_example>`
18+
We are assuming you are using the project files explained in the :ref:`example project <doc_godot_cpp_getting_started>`
1919
with the following structure:
2020

2121
.. code-block:: none

tutorials/scripting/cpp/index.rst

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
:allow_comments: False
2+
3+
.. _doc_godot_cpp:
4+
5+
C++ (godot-cpp)
6+
===============
7+
8+
This section documents `godot-cpp <https://github.com/godotengine/godot-cpp>`__,
9+
the official C++ GDExtension bindings maintained as part of the Godot project.
10+
11+
.. toctree::
12+
:maxdepth: 1
13+
:name: toc-tutorials-godot-cpp
14+
15+
about_godot_cpp
16+
gdextension_cpp_example
17+
gdextension_docs_system

tutorials/scripting/gdextension/gdextension_c_example.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2148,5 +2148,5 @@ quite straightforward and not very verbose.
21482148

21492149
If you want to create actual extensions, it is preferred to use the C++ bindings
21502150
instead, as it takes away all of the boilerplate from your code. Check the
2151-
:ref:`GDExtension C++ example <doc_gdextension_cpp_example>` to see how you can
2151+
:ref:`godot-cpp documentation <doc_godot_cpp>` to see how you can
21522152
do this.

tutorials/scripting/gdextension/gdextension_file.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Introduction
99
The ``.gdextension`` file in your project contains the instructions for how to load
1010
the GDExtension. The instructions are separated into specific sections. This page
1111
should give you a quick overview of the different options available to you. For an introduction
12-
how to get started with GDExtensions take a look at the :ref:`GDExtension C++ Example <doc_gdextension_cpp_example>`.
12+
how to get started with C++ (godot-cpp), take a look at the :ref:`GDExtension C++ Example <doc_godot_cpp_getting_started>`.
1313

1414
Configuration section
1515
---------------------
+18-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
:allow_comments: False
22

3-
GDExtension
4-
===========
3+
.. _doc_gdextension:
4+
5+
The GDExtension system
6+
======================
7+
8+
**GDExtension** is a Godot-specific technology that lets the engine interact with
9+
native `shared libraries <https://en.wikipedia.org/wiki/Library_(computing)#Shared_libraries>`__
10+
at runtime. You can use it to run native code without compiling it with the engine.
11+
12+
.. note:: GDExtension is *not* a scripting language and has no relation to
13+
:ref:`GDScript <doc_gdscript>`.
14+
15+
This section describes how GDExtension works, and is generally aimed at people wanting to make a GDExtension from
16+
scratch, for example to create language bindings. If you want to use existing language bindings, please refer to other
17+
articles instead, such as the articles about :ref:`C++ (godot-cpp) <doc_godot_cpp>` or one of the
18+
:ref:`community-made ones <doc_what_is_gdnative_third_party_bindings>`.
519

620
.. toctree::
721
:maxdepth: 1
8-
:name: toc-tutorials-gdnative
22+
:name: toc-tutorials-gdextension
923

1024
what_is_gdextension
11-
gdextension_cpp_example
12-
gdextension_c_example
1325
gdextension_file
14-
gdextension_docs_system
26+
gdextension_c_example

0 commit comments

Comments
 (0)