Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve GDExtension tutorial based on own experience #10570

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions tutorials/scripting/gdextension/gdextension_cpp_example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ There are a few prerequisites you'll need:
- a copy of the `godot-cpp
repository <https://github.com/godotengine/godot-cpp>`__.

See also :ref:`Compiling <toc-devel-compiling>` as the build tools are identical
See also :ref:`Configuring an IDE <toc-devel-configuring_an_ide>`
and :ref:`Compiling <toc-devel-compiling>` as the build tools are identical
to the ones you need to compile Godot from source.

You can download the `godot-cpp repository <https://github.com/godotengine/godot-cpp>`__ from GitHub or let Git do the work for you.
Expand Down Expand Up @@ -272,7 +273,7 @@ GDExtension plugin.
return;
}

GDREGISTER_CLASS(GDExample);
GDREGISTER_RUNTIME_CLASS(GDExample);
}

void uninitialize_example_module(ModuleInitializationLevel p_level) {
Expand All @@ -298,7 +299,8 @@ The ``initialize_example_module`` and ``uninitialize_example_module`` functions
called respectively when Godot loads our plugin and when it unloads it. All
we're doing here is parse through the functions in our bindings module to
initialize them, but you might have to set up more things depending on your
needs. We call the ``GDREGISTER_CLASS`` macro for each of our classes in our library.
needs. We call the ``GDREGISTER_RUNTIME_CLASS`` macro for each of our classes
in our library. This will make them run only in game, like the default for GDScript.

The important function is the third function called ``example_library_init``.
We first call a function in our bindings library that creates an initialization object.
Expand Down Expand Up @@ -327,10 +329,11 @@ At last, we need the header file for the ``register_types.cpp`` named
Compiling the plugin
--------------------

We cannot easily write by hand a ``SConstruct`` file that SCons would use for
building. For the purpose of this example, just use
:download:`this hardcoded SConstruct file <files/cpp_example/SConstruct>` we've
prepared. We'll cover a more customizable, detailed example on how to use these
To compile the project we need to define how SCons using should compile it
using a ``SConstruct`` file which references the one in ``godot-cpp``.
Writing it from scratch is outside the scope of this tutorial, but you can
:download:`the SConstruct file we prepared <files/cpp_example/SConstruct>`.
We'll cover a more customizable, detailed example on how to use these
build files in a subsequent tutorial.

.. note::
Expand Down Expand Up @@ -465,7 +468,12 @@ We're going to assign the Godot logo to this node as our texture, disable the

We're finally ready to run the project:

.. image:: img/gdextension_cpp_animated.gif
.. video:: img/gdextension_cpp_animated.webm
:alt: Screen recording of a game window, with Godot logo moving in the top-left corner
:autoplay:
:loop:
:muted:
Maarrk marked this conversation as resolved.
Show resolved Hide resolved
:align: default

Adding properties
-----------------
Expand Down
Binary file not shown.
Binary file not shown.
Loading