You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/bind/classes.md
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -33,21 +33,21 @@ fn init(handle: InitHandle) {
33
33
34
34
## Class definition
35
35
36
-
Similar to the [Hello World](../getting-started/hello-world.md#overriding-a-godot-method) example, we can define the `GodotApi` native class as follows:
36
+
Similar to the [Hello World](../intro/hello-world.md#overriding-a-godot-method) example, we can define the `GodotApi` native class as follows:
37
37
```rust
38
-
// Tell godot-rust that this struct is exported as a native class
38
+
// Tell godot-rust that this struct is exported as a native class
39
39
// (implements NativeClass trait)
40
40
#[derive(NativeClass)]
41
41
42
42
// Specify the base class (corresponds to 'extends' statement in GDScript).
43
-
// * Like 'extends' in GDScript, this can be omitted.
43
+
// * Like 'extends' in GDScript, this can be omitted.
44
44
// In that case, the 'Reference' class is used as a base.
45
45
// * Unlike 'extends' however, only existing Godot types are permitted,
46
46
// no other user-defined scripts.
47
47
#[inherit(Node)]
48
48
pubstructGodotApi {}
49
49
50
-
// Exactly one impl block can have the #[methods] annotation,
50
+
// Exactly one impl block can have the #[methods] annotation,
51
51
// which registers methods in the background.
52
52
#[methods]
53
53
implGodotApi {
@@ -58,10 +58,10 @@ impl GodotApi {
58
58
}
59
59
```
60
60
61
-
The [`#[derive(NativeClass)]` macro](https://docs.rs/gdnative/latest/gdnative/derive.NativeClass.html) enables a Rust type to be usable as a _native class_ in Godot. It implements [the `NativeClass` trait](https://docs.rs/gdnative/latest/gdnative/nativescript/trait.NativeClass.html), which fills in the glue code required to make the class available in Godot. Among other information, this includes class name and registry of exported methods and properties. For the user, the utility methods `new_instance()` and `emplace()` are provided for constructing `Instance` objects.
61
+
The [`#[derive(NativeClass)]` macro](https://docs.rs/gdnative/latest/gdnative/derive/derive.NativeClass.html) enables a Rust type to be usable as a _native class_ in Godot. It implements [the `NativeClass` trait](https://docs.rs/gdnative/latest/gdnative/export/trait.NativeClass.html), which fills in the glue code required to make the class available in Godot. Among other information, this includes class name and registry of exported methods and properties. For the user, the utility methods `new_instance()` and `emplace()` are provided for constructing `Instance` objects.
62
62
63
63
The function `new()` corresponds to `_init()` in GDScript. The _base_ is the base object of the script, and must correspond to the class specified in the `#[inherit]` attribute (or `Reference` if the attribute is absent). The parameter can be a shared reference `&T` or a `TRef<T>`.
64
64
65
65
With a `new()` method, you are able to write `GodotApi.new()` in GDScript. If you don't need this, you can add the `#[no_constructor]` attribute to the struct declaration.
66
66
67
-
At this point, arguments cannot be passed into the constructor. Consult [this FAQ entry](../faq.md#passing-additional-arguments-to-a-class-constructor) for available workarounds.
67
+
At this point, arguments cannot be passed into the constructor. Consult [this FAQ entry](../faq/code.html#can-the-new-constructor-have-additional-parameters) for available workarounds.
This chapter provides an exhaustive list of mechanisms to pass data through the Rust GDNative binding, in both directions:
3
+
This chapter provides an exhaustive list of mechanisms to pass data through the Rust GDNative binding, in both directions:
4
4
***GDScript -> Rust**, e.g. to react to an input event with custom Rust logic
5
5
***Rust -> GDScript**, e.g. to apply a game logic change to a graphics node in Godot
6
6
7
-
The goal is to serve as both an in-depth learning resource for newcomers and a reference to look up specific mechanisms at a later stage. Before delving into this chapter, make sure to read [An Overview of GDNative](gdnative-overview.md), which explains several fundamental concepts used here.
7
+
The goal is to serve as both an in-depth learning resource for newcomers and a reference to look up specific mechanisms at a later stage. Before delving into this chapter, make sure to read [An Overview of GDNative](../overview), which explains several fundamental concepts used here.
8
8
9
9
The subchapters are intended to be read in order, but you can navigate to them directly:
Copy file name to clipboardExpand all lines: src/bind/methods.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ In order to receive data from Godot, you can export methods. With the `#[method]
6
6
> `#[export]` has been renamed to `#[method]` and is now deprecated.
7
7
> It keeps working for the time being though (i.e. gdnative 0.11).
8
8
>
9
-
> For more information, see [`gdnative::derive::NativeClass`](https://godot-rust.github.io/docs/gdnative/derive/derive.NativeClass.html).
9
+
> For more information, see [`gdnative::derive::NativeClass`](https://docs.rs/gdnative/latest/gdnative/derive/derive.NativeClass.html).
10
10
11
11
The exported method's first parameter is always `&self` or `&mut self` (operating on the Rust object), and the second parameter is `&T` or `TRef<T>` (operating on the Godot base object, with `T` being the inherited type).
12
12
@@ -24,7 +24,7 @@ impl GodotApi {
24
24
godot_print!("_init()");
25
25
Self { enemy_count:0 }
26
26
}
27
-
27
+
28
28
#[method]
29
29
fncreate_enemy(
30
30
&mutself,
@@ -48,7 +48,7 @@ impl GodotApi {
48
48
#[method]
49
49
fncount_enemies(&self) ->i32 {
50
50
self.enemy_count
51
-
}
51
+
}
52
52
}
53
53
```
54
54
The two creation methods are semantically equivalent, yet they demonstrate how godot-rust implicitly converts the values to the parameter types (unmarshalling). You could use `Variant` everywhere, however it is more type-safe and expressive to use specific types. The same applies to return types, you could use `Variant` instead of `i32`.
Copy file name to clipboardExpand all lines: src/bind/traits.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ For more information about how you can customize the behavior of the dervive mac
31
31
32
32
## Export Trait
33
33
34
-
The Godot editor retrieves property information from [Object::get_property_list](https://docs.godotengine.org/en/stable/classes/class_object.html#id2). To populate this data, `godot-rust` requires that the [`Export`](https://docs.rs/gdnative/latest/gdnative/nativescript/trait.Export.html) trait be implemented for each type Rust struct.
34
+
The Godot editor retrieves property information from [Object::get_property_list](https://docs.godotengine.org/en/stable/classes/class_object.html#id2). To populate this data, `godot-rust` requires that the [`Export`](https://docs.rs/gdnative/latest/gdnative/export/trait.Export.html) trait be implemented for each type Rust struct.
35
35
36
36
There are no derive macros that can be used for `Export` but many of the primitive types have it implemented by default.
The GDNative API supports any type that implements the [`ToVariant`](https://docs.rs/gdnative/latest/gdnative/core_types/trait.ToVariant.html) and/or [`FromVariant`](https://docs.rs/gdnative/latest/gdnative/core_types/trait.FromVariant.html) traits.
441
441
442
-
To use a type as a property, in addition to the above, the type will also need to implement the [`Export`](https://docs.rs/gdnative/latest/gdnative/nativescript/trait.Export.html) trait.
442
+
To use a type as a property, in addition to the above, the type will also need to implement the [`Export`](https://docs.rs/gdnative/latest/gdnative/export/trait.Export.html) trait.
443
443
444
444
Some concrete examples of types that can be used with the GDNative API are the following:
445
445
446
446
-[`Variant`](https://docs.rs/gdnative/latest/gdnative/core_types/struct.Variant.html), this is Godot's "any" type. It must be converted before it can be used.
447
447
- A subset of scalar types such as `i64`, `f64`, `bool`, etc.
448
448
-[`String`](https://doc.rust-lang.org/std/string/struct.String.html) and [`GodotString`](https://docs.rs/gdnative/latest/gdnative/core_types/struct.GodotString.html).
449
-
-[Godot core types](https://docs.rs/gdnative/latest/gdnative/core_types/index.html) such as [`Color`](https://docs.rs/gdnative/latest/gdnative/core_types/struct.Color.html), [`Aabb`](https://docs.rs/gdnative/latest/gdnative/core_types/struct.Aabb.html), [`Transform2D`](https://docs.rs/gdnative/latest/gdnative/core_types/type.Transform2D.html), [`Vector2`](https://docs.rs/gdnative/latest/gdnative/core_types/type.Vector2.html), etc.
450
-
- Godot classes such as `Node`, `Reference`, etc. which must be accessed via [`Ref<T>`](https://docs.rs/gdnative/latest/gdnative/struct.Ref.html) (you can't pass them by value, because Godot owns them).
451
-
- Any Rust struct that derives [`NativeClass`](https://docs.rs/gdnative/latest/gdnative/derive.NativeClass.html), through [`Instance<T>`](https://docs.rs/gdnative/latest/gdnative/nativescript/struct.Instance.html).
449
+
-[Godot core types](https://docs.rs/gdnative/latest/gdnative/core_types/index.html) such as [`Color`](https://docs.rs/gdnative/latest/gdnative/core_types/struct.Color.html), [`Aabb`](https://docs.rs/gdnative/latest/gdnative/core_types/struct.Aabb.html), [`Transform2D`](https://docs.rs/gdnative/latest/gdnative/core_types/struct.Transform2D.html), [`Vector2`](https://docs.rs/gdnative/latest/gdnative/core_types/struct.Vector2.html), etc.
450
+
- Godot classes such as `Node`, `Reference`, etc. which must be accessed via [`Ref<T>`](https://docs.rs/gdnative/latest/gdnative/object/struct.Ref.html) (you can't pass them by value, because Godot owns them).
451
+
- Any Rust struct that derives [`NativeClass`](https://docs.rs/gdnative/latest/gdnative/derive/derive.NativeClass.html), through [`Instance<T>`](https://docs.rs/gdnative/latest/gdnative/object/struct.Instance.html).
452
452
453
453
454
454
## How can I profile my code to measure performance?
Copy file name to clipboardExpand all lines: src/intro/hello-world.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ gdnative = "0.10"
44
44
> While it's also possible to place the Rust crate within the Godot project, doing so might lead to problems with Godot's resource importer. It's best to place the Rust crate somewhere outside the Godot project directory.
45
45
>
46
46
> Previously, some third-party resources have recommended separating Rust code into multiple crates. While this is fine to do, godot-rust works best when there is a single `cdylib` crate acting as the entry point for all crates in the workspace. Script downcasting, for example, only works for types registered in the same GDNative library. Code from `std` and other dependencies can also lead to code bloat when duplicated in multiple binaries.
47
-
>
47
+
>
48
48
> We suggest that users start projects as a single crate, and only split code into workspaces when necessary.
49
49
50
50
@@ -88,7 +88,7 @@ This macro defines the necessary C callbacks used by Godot. You only need *one*
88
88
89
89
> ### GDNative internals
90
90
>
91
-
> The purposes of this macro will be discussed in detail in [_An Overview of GDNative_](../gdnative-overview.md). For now, treat it as a magic incantation.
91
+
> The purposes of this macro will be discussed in detail in [_An Overview of GDNative_](../overview). For now, treat it as a magic incantation.
Copy file name to clipboardExpand all lines: src/intro/setup.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ Before we can start creating a hello-world project using godot-rust, we'll need
6
6
7
7
The default API version is currently 3.2.3-stable. For the rest of the tutorial, we'll assume that you have Godot 3.2.3-stable installed, and available in your `PATH` as `godot`.
8
8
9
-
You may download binaries of Godot 3.2.3-stable from the official repository: [https://downloads.tuxfamily.org/godotengine/3.2.3/](https://downloads.tuxfamily.org/godotengine/3.2.3/).
9
+
You may download binaries of Godot 3.2.3-stable from the official repository: [https://godotengine.org/download/archive/3.2.3-stable/](https://godotengine.org/download/archive/3.2.3-stable/).
Copy file name to clipboardExpand all lines: src/overview/data-representations.md
+10-10Lines changed: 10 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Data representations
2
2
3
-
The godot-rust library uses many different approaches to store and transport data. This chapter explains high-level concepts of related terminology used throughout the library and its documentation. It is not a usage guide however -- to see the concepts in action, check out [Binding to Rust code](../rust-binding.md).
3
+
The godot-rust library uses many different approaches to store and transport data. This chapter explains high-level concepts of related terminology used throughout the library and its documentation. It is not a usage guide however -- to see the concepts in action, check out [Binding to Rust code](../bind).
4
4
5
5
6
6
## Object and class
@@ -16,24 +16,24 @@ Every user-defined class inherits `Object` directly or indirectly, and thus all
16
16
17
17
`Object` itself comes with manual memory management. All instances must be deallocated using the `free()` method. This is typically not what you want, instead you will most often work with the following classes inherited from `Object`:
18
18
19
-
***`Reference`**
20
-
Reference-counted objects. This is the default base class if you don't use the `extends` keyword in GDScript. Allows to pass around instances of this type freely, managing memory automatically when the last reference goes out of scope.
19
+
***`Reference`**
20
+
Reference-counted objects. This is the default base class if you don't use the `extends` keyword in GDScript. Allows to pass around instances of this type freely, managing memory automatically when the last reference goes out of scope.
21
21
Do not confuse this type with the godot-rust `Ref` smart pointer.
22
-
***`Node`**
23
-
Anything that's part of the scene tree, such as `Spatial` (3D), `CanvasItem` and `Node2D` (2D). Each node in the tree is responsible of its children and will deallocate them automatically when it is removed from the tree. At the latest, the entire tree will be destroyed when ending the application.
22
+
***`Node`**
23
+
Anything that's part of the scene tree, such as `Spatial` (3D), `CanvasItem` and `Node2D` (2D). Each node in the tree is responsible of its children and will deallocate them automatically when it is removed from the tree. At the latest, the entire tree will be destroyed when ending the application.
24
24
**Important:** as long as a node is not attached to the scene tree, it behaves like an `Object` instance and must be freed manually. On the other hand, as long as it is part of the tree, it can be destroyed (e.g. when its parent is removed) and other references pointing to it become invalid.
25
-
***`Resource`**
25
+
***`Resource`**
26
26
Data set that is loaded from disk and cached in memory, for example 3D meshes, materials, textures, fonts or music (see also [Godot tutorial](https://docs.godotengine.org/en/stable/getting_started/step_by_step/resources.html)).
27
-
`Resource` inherits `Reference`, so in the context of godot-rust, it can be treated like a normal, reference-counted class.
27
+
`Resource` inherits `Reference`, so in the context of godot-rust, it can be treated like a normal, reference-counted class.
28
28
29
29
When talking about inheritance, we always mean the relationship in GDScript code. Rust does not have inheritance, instead godot-rust implements `Deref` traits to allow implicit upcasts. This enables to invoke all parent methods and makes the godot-rust API very close to GDScript.
30
30
31
31
Classes need to be added as `NativeScript` resources inside the Godot editor, see [here](../intro/hello-world.html#creating-the-nativescript-resource) for a description.
_See `GodotObject`, the Rust trait implemented for all Godot classes, in [godot-rust docs](https://docs.rs/gdnative/latest/gdnative/trait.GodotObject.html)_
_See `GodotObject`, the Rust trait implemented for all Godot classes, in [godot-rust docs](https://docs.rs/gdnative/latest/gdnative/object/trait.GodotObject.html)_
37
37
38
38
39
39
## Variant
@@ -53,7 +53,7 @@ _See `Variant` in
53
53
54
54
Scripts are programmable building blocks that can be attached to nodes in the scene tree, in order to customize their behavior. Depending on the language in which the script is written, there are different classes which inherit the `Script` class; relevant here will be `NativeScript` for classes defined in Rust, and `GDScript` for classes defined in GDScript. Scripts are stored as Godot resources (like materials, textures, shaders etc), usually in their own separate file.
55
55
56
-
Scripts _always_ inherit another class from Godot's `Object` hierarchy, either an existing one from Godot or a user-defined one. In Rust, scripts are limited to inherit an existing Godot class; other scripts cannot be inherited. This makes each script a class on their own: they provide the properties and methods from their _base object_, plus all the properties and methods that you define in the script.
56
+
Scripts _always_ inherit another class from Godot's `Object` hierarchy, either an existing one from Godot or a user-defined one. In Rust, scripts are limited to inherit an existing Godot class; other scripts cannot be inherited. This makes each script a class on their own: they provide the properties and methods from their _base object_, plus all the properties and methods that you define in the script.
0 commit comments