@@ -7,7 +7,7 @@ Introduction
77------------
88
99The C++ bindings for GDExtension are built on top of the C GDExtension API
10- and provide a nicer way to "extend" nodes in Godot using C++.
10+ and provide a nicer way to "extend" nodes and other built-in classes in Godot using C++.
1111This new system allows the extension of Godot to nearly the same
1212level as statically linked C++ modules.
1313
@@ -34,14 +34,12 @@ of Godot. GDExtensions will not work in older versions of Godot (only Godot 4 an
3434
3535.. note ::
3636
37- `GDExtension <https://godotengine.org/article/introducing-gd-extensions >`__
38- has been merged in the ``master `` branch of godot-cpp,
39- but it is only compatible with the upcoming Godot 4.0.
40- Therefore, you need to use the ``master `` branch of godot-cpp to use GDExtension
41- and follow this example.
37+ To use `GDExtension <https://godotengine.org/article/introducing-gd-extensions >`__
38+ you need to use the ``master `` branch of godot-cpp,
39+ which is only compatible with Godot 4.0 and follow this example.
4240
43- If you are versioning your project using Git, it is a good idea to add them as
44- Git submodules :
41+ If you are versioning your project using Git, it is a good idea to add it as
42+ a Git submodule :
4543
4644.. code-block :: none
4745
@@ -63,16 +61,11 @@ Do make sure you clone recursively to pull in both repositories:
6361
6462 mkdir gdextension_cpp_example
6563 cd gdextension_cpp_example
66- git clone --recursive - b master https://github.com/godotengine/godot-cpp
64+ git clone -b master https://github.com/godotengine/godot-cpp
6765
6866 .. note ::
6967
70- ``godot-cpp `` now includes ``godot-headers `` as a nested submodule, if you've
71- manually downloaded them please make sure to place ``godot-headers `` inside
72- of the ``godot-cpp `` folder.
73-
74- You don't have to do it this way, but we've found it easiest to manage. If you
75- decide to download the repositories or clone them into your folder,
68+ If you decide to download the repository or clone it into your folder,
7669 make sure to keep the folder layout the same as we've setup here. Much of
7770 the code we'll be showcasing here assumes the project has this layout.
7871
@@ -83,9 +76,9 @@ following commands:
8376.. code-block :: none
8477
8578 cd gdextension_cpp_example
86- git submodule update --init --recursive
79+ git submodule update --init
8780
88- This will clone these two repositories into your project folder.
81+ This will initialize the repository in your project folder.
8982
9083Building the C++ bindings
9184-------------------------
@@ -179,8 +172,6 @@ GDExtension node we'll be creating. We will name it ``gdexample.h``:
179172 GDExample();
180173 ~GDExample();
181174
182- void _init(); // our initializer called by Godot
183-
184175 void _process(float delta);
185176 };
186177
@@ -208,9 +199,7 @@ familiar to some, and one new method.
208199The first is ``_bind_methods ``, which is a static function that Godot will
209200call to find out which methods can be called and which properties it exposes.
210201The second is our ``_process `` function, which will work exactly the same
211- as the ``_process `` function you're used to in GDScript. The third is
212- our ``_init `` function which is called after Godot has properly set up
213- our object.
202+ as the ``_process `` function you're used to in GDScript.
214203
215204Let's implement our functions by creating our ``gdexample.cpp `` file:
216205
@@ -222,7 +211,6 @@ Let's implement our functions by creating our ``gdexample.cpp`` file:
222211 using namespace godot;
223212
224213 void GDExample::_bind_methods() {
225- ClassDB::bind_method(D_METHOD("_process"), &GDExample::_process);
226214 }
227215
228216 GDExample::GDExample() {
@@ -247,9 +235,6 @@ that we defined in our header file.
247235
248236Note our ``_process `` function, which keeps track of how much time has passed
249237and calculates a new position for our sprite using a sine and cosine function.
250- What stands out is calling ``owner->set_position `` to call one of the built-in
251- methods of our Sprite2D. This is because our class is a container
252- class; ``owner `` points to the actual Sprite2D node our script relates to.
253238
254239There is one more C++ file we need; we'll name it ``register_types.cpp ``. Our
255240GDExtension plugin can contain multiple classes, each with their own header
@@ -369,9 +354,9 @@ loaded for each platform and the entry function for the module. It is called ``g
369354
370355 [libraries]
371356
372- linux.64="res://bin/linux/ libgdexample.linux.64.so"
373- windows.x86_64="res://bin/win64/ libgdexample.windows.x86_64.dll"
374- macos="res://bin/osx/ libgdexample.macos.framework"
357+ linux.64="res://bin/libgdexample.linux.64.so"
358+ windows.x86_64="res://bin/libgdexample.windows.x86_64.dll"
359+ macos="res://bin/libgdexample.macos.framework"
375360
376361 This file contains a ``configuration `` section that controls the entry function of the module.
377362
@@ -428,7 +413,7 @@ Adding properties
428413
429414GDScript allows you to add properties to your script using the ``export ``
430415keyword. In GDExtension you have to register the properties with a getter and
431- sett function or directly implement the ``_get_property_list ``, ``_get `` and
416+ setter function or directly implement the ``_get_property_list ``, ``_get `` and
432417``_set `` methods of an object (but that goes far beyond the scope of this
433418tutorial.
434419
@@ -457,7 +442,6 @@ show the methods we end up changing, don't remove the lines we're omitting:
457442 void GDExample::_bind_methods() {
458443 ClassDB::bind_method(D_METHOD("get_amplitude"), &GDExample::get_amplitude);
459444 ClassDB::bind_method(D_METHOD("set_amplitude", "p_amplitude"), &GDExample::set_amplitude);
460-
461445 ClassDB::add_property("GDExample", PropertyInfo(Variant::FLOAT, "amplitude"), "set_amplitude", "get_amplitude");
462446 }
463447
@@ -512,6 +496,7 @@ showing the methods that have changed so don't remove anything we're omitting:
512496.. code-block :: C++
513497
514498 void GDExample::_bind_methods() {
499+ ...
515500 ClassDB::bind_method(D_METHOD("get_speed"), &GDExample::get_speed);
516501 ClassDB::bind_method(D_METHOD("set_speed", "p_speed"), &GDExample::set_speed);
517502 ClassDB::add_property("GDExample", PropertyInfo(Variant::FLOAT, "speed"), "set_speed", "get_speed");
@@ -535,6 +520,8 @@ showing the methods that have changed so don't remove anything we're omitting:
535520 set_position(new_position);
536521 }
537522
523+ ...
524+
538525 void GDExample::set_speed(float p_speed) {
539526 speed = p_speed;
540527 }
0 commit comments