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: README.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,10 +19,12 @@ $ mdbook serve
19
19
20
20
This repository is for documentation only. Please make pull requests for the library itself in the [main repo](https://github.com/godot-rust/godot-rust).
21
21
22
+
22
23
## Contributing
23
24
24
25
See the [contribution guidelines]([CONTRIBUTING.md](https://github.com/godot-rust/godot-rust/blob/book/CONTRIBUTING.md)) in the main repo.
25
26
27
+
26
28
## License
27
29
28
-
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be licensed under the [MIT license](LICENSE.md), without any additional terms or conditions.
30
+
Any contribution intentionally submitted for inclusion in the work by you shall be licensed under the [MIT license](LICENSE.md), without any additional terms or conditions.
Copy file name to clipboardExpand all lines: src/advanced-guides/custom-godot.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,8 @@ If everything goes well, you can now update the dependencies of your GDNative li
37
37
```toml
38
38
[dependencies]
39
39
40
-
# Use the exact version corresponding to `gdnative-bindings`, and disable the default re-export.
40
+
# Use the exact version corresponding to `gdnative-bindings`
41
+
# and disable the default re-export.
41
42
gdnative = { version = "=0.9.0", default-features = false, features = [] }
42
43
43
44
# Use your custom bindings crate as a path dependency
@@ -48,6 +49,7 @@ Here, `gdnative` is specified using an exact version because the bindings genera
48
49
49
50
Finally, replace references to `gdnative::api` with `gdnative-bindings-custom`. You should now be able to use the APIs in your custom build in Rust!
50
51
52
+
51
53
## Generating documentation
52
54
53
55
However, if you try to generate documentation with rustdoc at this point, you might notice that documentation might be missing or wrong for some of the types or methods. This is due to documentation being stored separately from the API description itself, and can be easily fixed if you have access to the source code from which your custom Godot binary is built.
Copy file name to clipboardExpand all lines: src/advanced-guides/migrating-0-8.md
+7-1Lines changed: 7 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,8 @@
1
-
# Migrating from godot-rust 0.8.x
1
+
# Migrating from godot-rust 0.8
2
2
3
3
In version 0.9, we are attempting to resolve many long-standing problems in the older API. As a result, there are many breaking changes in the public interface. This is a quick guide to the new API for users that have used older versions.
Typos in variant names of `VariantOperator` and `GodotError` are fixed. Change to the correct names if this breaks your code.
62
63
64
+
63
65
## Changes to derive macros
64
66
65
67
The `NativeScript` derive macro now looks for `new` instead of `_init` as the constructor.
@@ -95,6 +97,7 @@ impl Thing {
95
97
}
96
98
```
97
99
100
+
98
101
## Argument casts
99
102
100
103
Generated methods taking objects, `Variant`, and `GodotString` are now made generic using `impl Trait` in argument position. This make calls much less verbose, but may break inference for some existing code. If you have code that looks like:
This is arguably less convenient, but passing explicit nulls should be rare enough a use case that the benefits of having polymorphic arguments are much more significant.
141
144
145
+
142
146
## Object semantics
143
147
144
148
In 0.9, the way Godot objects are represented in the API is largely remodeled to closely match the behavior of Godot. For the sake of illustration, we'll use the type `Node` in the following examples.
@@ -284,6 +288,7 @@ where
284
288
}
285
289
```
286
290
291
+
287
292
## Casting
288
293
289
294
The casting API is made more convenient with 0.9, using the `SubClass` trait. Casting is now covered by two generic methods implemented on all object reference types: `cast` and `upcast`. Both methods enforce cast validity statically, which means that the compiler will complain about casts that will always fail at runtime. The generated `to_*` methods are removed in favor of `upcast`.
@@ -329,6 +334,7 @@ where
329
334
330
335
Note that this function is also polymorphic over the `Access` typestate, which is explained the the following section.
331
336
337
+
332
338
## Typestates
333
339
334
340
The typestate pattern is introduced in 0.9 to statically provide fine-grained reference safety guarantees depending on thread access state. There are three typestates in the API:
Copy file name to clipboardExpand all lines: src/exporting/android.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,7 @@
4
4
5
5
In order to export to Android, we need to compile our Rust source for the appropriate targets. Unlike compiling for our native targets, there are a few extra steps involved with cross-compiling for another target.
6
6
7
+
7
8
## Installing prerequisites
8
9
9
10
First, we need to install the **Android SDK** with **NDK** enabled. This contains the necessary tools for each architecture. Once the Android SDK is installed, open Editor Settings in the Godot GUI (*Editor > Editor Settings > Export > Android*) and set the **absolute paths** to `adb`, `jarsigner`, and the debug keystore (`debug.keystore`), all of which can be found in the Android SDK installation.
To make Cargo aware of the proper platform-specific linkers that it needs to use for Android targets, we need to put the paths to the binaries in the Cargo configuration file, which can be found (or created) at `$HOME/.cargo/config` on UNIX-like systems, or `%USERPROFILE%\.cargo\config` on Windows), using [`[target]` tables](https://doc.rust-lang.org/cargo/reference/config.html#target):
**Important note**: ARM and x86 are, by design, different architectures. It is normal to get errors while running `cargo test` with a Rust library targeting ARMv7 on a x86-64 CPU, for example, since the CPU is unable to handle it.
Copy file name to clipboardExpand all lines: src/faq/code.md
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Common Code Questions
1
+
# FAQ: Common code questions
2
2
3
3
## What is the `BorrowFailed` error and why do I keep getting it?
4
4
@@ -261,6 +261,7 @@ While a similar case applies for [`ShaderMaterial`](https://docs.rs/gdnative/lat
261
261
262
262
Direct access to such properties is planned in [godot-rust/godot-rust#689](https://github.com/godot-rust/godot-rust/issues/689).
263
263
264
+
264
265
## What is the godot-rust equivalent of `preload`?
265
266
266
267
Unfortunately, there is no equivalent to preload in languages other than GDScript, because preload is GDScript-specific magic that works at compile time. If you read the official documentation on preload, it says:
@@ -275,6 +276,7 @@ The ResourceLoader should be used in most cases.
275
276
276
277
Also, you can always put a Mutex<HashMap> into a Rust static and load everything you need there during a loading screen.
277
278
279
+
278
280
## How do I keep a reference of `Node`?
279
281
280
282
The idiomatic way to maintain a reference to a node in the SceneTree from Rust is to use `Option<Ref<T>>`.
@@ -315,6 +317,7 @@ Note: As `TRef<T>` is a temporary pointer, it will be necessary to get the base
315
317
316
318
This can be done with the [`TRef<T>::claim()`](https://docs.rs/gdnative/latest/gdnative/struct.TRef.html#method.claim) function that will return the persistent version of the pointer that you can store in your class.
317
319
320
+
318
321
## What is the Rust equivalent to `onready var` in GDScript
319
322
320
323
Rust does not have a direct equivalent to `onready var`. The most idiomatic workaround with Rust is to use `Option<Ref<T>>` of you need the Godot node type or `Option<Instance<T>>` if you are using a Rust based `NativeClass`.
@@ -375,6 +378,7 @@ Some concrete examples of types that can be used with the GDNative API are the f
375
378
- 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).
376
379
- 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).
377
380
381
+
378
382
## How can I profile my code to determine the performance?
379
383
380
384
There are a lot of ways to profile your code and they will vary in complexity.
@@ -48,16 +51,17 @@ Script files can be created in two ways.
48
51
resource_name = "{class name}"
49
52
class_name = "{class name}"
50
53
library = ExtResource( 1 )
51
-
52
54
```
53
55
54
-
## Why aren't my scripts showing up in the Add Node portion of the editor even though they inherit from `Node`, `Node2D`, `Spatial` or `Control`?
55
56
56
-
Due to limitations with Godot 3.x's version of GDNative, NativeScript types do not get registered in the class database. As such, these classes are not included in the "Create New Node" dialog.
57
+
## Why aren't my scripts showing up in the _Add Node_ portion of the editor, even though they inherit from `Node`, `Node2D`, `Spatial` or `Control`?
58
+
59
+
Due to limitations with Godot 3.x's version of GDNative, NativeScript types do not get registered in the class database. As such, these classes are not included in the _Create New Node_ dialog.
57
60
58
-
A workaround to this issue has been included in the recipe [Custom Nodes Plugin](../recipes/custom-nodes-plugin.md).
61
+
A workaround to this issue has been included in the recipe [Custom Nodes Plugin](../recipes/custom-node-plugin.md).
59
62
60
-
## Can I use Rust for a [toolscript](https://docs.godotengine.org/en/stable/tutorials/misc/running_code_in_the_editor.html)?
63
+
64
+
## Can I use Rust for a [tool script](https://docs.godotengine.org/en/stable/tutorials/misc/running_code_in_the_editor.html)?
61
65
62
66
Yes, any Rust struct that inherits from `NativeClass` can be also used as a tool class by using the `InitHandle::add_tool_class` during native script initialization instead of `InitHandle::add_class`.
63
67
@@ -84,6 +88,7 @@ Please also see the [native_plugin](https://github.com/godot-rust/godot-rust/tre
84
88
- Editor plugins do not support the hot reload feature. If making use of tool classes, your `GDNativeLibrary` must have `reloadable=false` or the plugins will crash when the editor loses focus.
85
89
- It is advised that `GDNativeLibrary` files for editor plugins be compiled as a separate "cdylib" from the `GDNativeLibrary` that may need to be recompiled during development, such as game logic.
86
90
91
+
87
92
## Is it possible to use multiple libraries with GDNative?
88
93
89
94
Yes. This is possible, but it should be avoided unless necessary. Generally you should create one `GDNativeLibrary` (`.gdnlib`) and associate many `NativeScript` (`.gdns`) files with the single library.
@@ -94,7 +99,7 @@ If you do have a scenario that requires multiple `GDNativeLibrary`, you can crea
94
99
95
100
To avoid these collisions, rather than the `godot_init!` initialization macro, prefer the use of the individual macros.
96
101
97
-
For example, if we want to define the symbol_prefix for our library "my_symbol_prefix" we can use the macros below.
102
+
For example, if we want to define the symbol_prefix for our library "my_symbol_prefix", we can use the macros below.
98
103
99
104
```rust
100
105
// _ indicates that we do not have any specific callbacks needed from the engine for initialization. So it will automatically create
@@ -108,24 +113,24 @@ godot_nativescript_init!(registration_function as my_symbol_prefix_nativescript_
## Can I expose {insert rust crate name} for use with Godot and GDScript?
116
+
## Can I expose {insert Rust crate name} for use with Godot and GDScript?
112
117
113
-
Yes, with NativeScript so long as you can create a `NativeScript` wrapper you can create GDScript bindings for a rust crate. See the [logging recipe](../recipes/logging.md) for an example of wrapping a Rust logging crate for use with GDScript.
118
+
Yes, with NativeScript so long as you can create a `NativeScript` wrapper you can create GDScript bindings for a Rust crate. See the [logging recipe](../recipes/logging.md) for an example of wrapping a Rust logging crate for use with GDScript.
114
119
115
120
116
-
## How do I get code Auto-completion with rust-analyzer?
121
+
## How do I get auto-completion with rust-analyzer?
117
122
118
123
`godot-rust` generates most of the gdnative type's code at compile-time. Editors using [rust-analyzer](https://github.com/rust-analyzer/rust-analyzer) struggle to autocomplete those types:
119
124
120
-

125
+

121
126
122
127
123
128
People [reported](https://github.com/rust-analyzer/rust-analyzer/issues/5040) similar issues and found that switching on the `"rust-analyzer.cargo.loadOutDirsFromCheck": true` setting fixed it:
124
129
125
-

130
+

126
131
127
132
128
-
## How do I get code Auto-completion with IntelliJRust Plugin
133
+
## How do I get auto-completion with IntelliJ-Rust plugin?
129
134
130
135
Similar to rust-analyzer, IntelliJ-Family IDEs struggle to autocomplete gdnative types generated at compile-time.
131
136
@@ -138,6 +143,7 @@ Second, the bindings files generated (~8mb) are above the 2mb limit for files to
138
143
* add `-Didea.max.intellisense.filesize=limitValue` line where `limitValue` is desired limit in KB, for example, 10240. Note, it cannot be more than 20 MB.
139
144
* restart IDE
140
145
146
+
141
147
## How can I make my debug builds more performant?
142
148
143
149
**Note**: These changes may slow down certain aspects of the build times for your game.
0 commit comments