Skip to content

Commit 1cc1439

Browse files
authored
Merge pull request #46 from Bromeon/bugfix/cleanup
Consistency and formatting cleanup + Projects chapter
2 parents a46ccad + 5e44a39 commit 1cc1439

33 files changed

+172
-69
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ $ mdbook serve
1919

2020
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).
2121

22+
2223
## Contributing
2324

2425
See the [contribution guidelines]([CONTRIBUTING.md](https://github.com/godot-rust/godot-rust/blob/book/CONTRIBUTING.md)) in the main repo.
2526

27+
2628
## License
2729

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.

src/SUMMARY.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,30 @@
1414
- [Exported properties](./rust-binding/properties.md)
1515
- [Calling into GDScript from Rust](./rust-binding/calling-gdscript.md)
1616
- [FAQ](./faq.md)
17-
- [Code Questions](./faq/code.md)
18-
- [Multithreading](./faq/multithreading.md)
19-
- [Configuration](./faq/configuration.md)
20-
- [Versioning and supported platforms](./faq/meta.md)
21-
- [Community](./faq/community.md)
22-
- [Godot 4.0 Status](./faq/godot4.md)
17+
- [Common code questions](./faq/code.md)
18+
- [Multithreading](./faq/multithreading.md)
19+
- [Configuration](./faq/configuration.md)
20+
- [Versioning and supported platforms](./faq/support.md)
21+
- [Community](./faq/community.md)
22+
- [Godot 4.0 Status](./faq/godot4.md)
2323
- [(TODO) Testing](./testing.md)
24-
- [Structuring Code for Testing](./testing/structure.md)
25-
- [Testing with the Engine](./testing/engine.md)
24+
- [Structuring code for testing](./testing/structure.md)
25+
- [Testing with the engine](./testing/engine.md)
2626
- [Recipes](./recipes.md)
27-
- [Rust Panic Hook](./recipes/rust_panic_handler.md)
27+
- [Async with Tokio runtime](./recipes/async-tokio.md)
28+
- [Custom node plugin](./recipes/custom-node-plugin.md)
29+
- [Loading external resources](./recipes/external-resources.md)
2830
- [Logging](./recipes/logging.md)
29-
- [Loading external resources](./recipes/loading_external_resources.md)
30-
- [Custom nodes Plugin](./recipes/custom-nodes-plugin.md)
31-
- [Tokio Runtime](./recipes/tokio_runtime.md)
31+
- [Nix as development environment](recipes/nix-build-system.md)
32+
- [Rust panic handler](./recipes/panic-handler.md)
33+
- [Third-party projects](./projects.md)
34+
- [Games](./projects/games.md)
35+
- [Tools and integrations](./projects/tools.md)
36+
- [Applications](./projects/applications.md)
3237
- [Exporting](./exporting.md)
3338
- [Android](./exporting/android.md)
3439
- [(TODO) iOS](./exporting/ios.md)
3540
- [Mac OS X](./exporting/macosx.md)
3641
- [Advanced Guides](./advanced-guides.md)
37-
- [Using custom builds of Godot](./advanced-guides/custom-bindings.md)
38-
- [Nix as A Development Environment](./advanced-guides/nix-build-system.md)
39-
- [Migrating from godot-rust 0.8.x](./migrating-0-8.md)
42+
- [Using custom Godot versions](./advanced-guides/custom-godot.md)
43+
- [Migrating from godot-rust 0.8](advanced-guides/migrating-0-8.md)

src/advanced-guides/custom-bindings.md renamed to src/advanced-guides/custom-godot.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ If everything goes well, you can now update the dependencies of your GDNative li
3737
```toml
3838
[dependencies]
3939

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.
4142
gdnative = { version = "=0.9.0", default-features = false, features = [] }
4243

4344
# 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
4849

4950
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!
5051

52+
5153
## Generating documentation
5254

5355
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.

src/migrating-0-8.md renamed to src/advanced-guides/migrating-0-8.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# Migrating from godot-rust 0.8.x
1+
# Migrating from godot-rust 0.8
22

33
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.
44

5+
56
## Module organization and naming
67

78
### Generated API types
@@ -60,6 +61,7 @@ object.connect("foo", owner, "_handle_foo", VariantArray, ConnectFlags::DEFERRED
6061

6162
Typos in variant names of `VariantOperator` and `GodotError` are fixed. Change to the correct names if this breaks your code.
6263

64+
6365
## Changes to derive macros
6466

6567
The `NativeScript` derive macro now looks for `new` instead of `_init` as the constructor.
@@ -95,6 +97,7 @@ impl Thing {
9597
}
9698
```
9799

100+
98101
## Argument casts
99102

100103
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:
@@ -139,6 +142,7 @@ thing.set_script(Null::null());
139142

140143
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.
141144

145+
142146
## Object semantics
143147

144148
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
284288
}
285289
```
286290

291+
287292
## Casting
288293

289294
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
329334

330335
Note that this function is also polymorphic over the `Access` typestate, which is explained the the following section.
331336

337+
332338
## Typestates
333339

334340
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:

src/before.png

-110 KB
Binary file not shown.

src/exporting/android.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
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.
66

7+
78
## Installing prerequisites
89

910
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.
@@ -47,6 +48,7 @@ apt-get update
4748
apt-get install g++-multilib gcc-multilib libc6-dev-i386 -y
4849
```
4950

51+
5052
## Setting up Cargo
5153

5254
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):
@@ -79,6 +81,7 @@ linker = "/usr/local/lib/android/sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x
7981
linker = "/usr/local/lib/android/sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android29-clang"
8082
```
8183

84+
8285
## Setting up environment variables for `gdnative-sys`
8386

8487
The `gdnative-sys` crate can infer include paths for Android targets, but it requires the following environment variables:
@@ -100,6 +103,7 @@ $env:JAVA_HOME = "C:\path\to\jdk"
100103
$env:ANDROID_SDK_ROOT = "C:\path\to\android\sdk"
101104
```
102105

106+
103107
## Building the GDNative library
104108

105109
Finally, we can now build the GDNative library with Cargo for one or multiple targets:
@@ -110,6 +114,7 @@ cargo build --release --target x86_64-linux-android
110114

111115
**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.
112116

117+
113118
## Exporting in Godot
114119

115120
### Linking to Android binaries in `.gdns`

src/exporting/macosx.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
**Disclaimer**: _Currently, the following steps are tested and confirmed to work on Linux only._
44

5+
56
## Use case
67

78
Exporting for Mac OS X is interesting if:
@@ -11,6 +12,7 @@ Exporting for Mac OS X is interesting if:
1112

1213
If you have access to a real Mac, building natively is easier.
1314

15+
1416
## Why is this complex ?
1517

1618
Cross-compiling Rust programs for Mac OS X is as simple as:
@@ -116,6 +118,7 @@ As a consequence, you do *not* need to put `$MACOSX_CROSS_COMPILER/cross-compile
116118
you only plan to export [godot-rust](https://github.com/godot-rust/godot-rust) based programs, as the
117119
binary needs to be explicitly overloaded.
118120

121+
119122
## Exporting
120123

121124
Once your `.dylib` file is built, a standard Godot export should work:
@@ -131,6 +134,7 @@ folder, ready to use.
131134

132135
Double-check your `.dylib` file is there.
133136

137+
134138
## Useful links
135139

136140
* https://github.com/tpoechtrager/osxcross : tool used to install the Mac OS X SDK on Linux

src/faq/code.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Common Code Questions
1+
# FAQ: Common code questions
22

33
## What is the `BorrowFailed` error and why do I keep getting it?
44

@@ -261,6 +261,7 @@ While a similar case applies for [`ShaderMaterial`](https://docs.rs/gdnative/lat
261261

262262
Direct access to such properties is planned in [godot-rust/godot-rust#689](https://github.com/godot-rust/godot-rust/issues/689).
263263

264+
264265
## What is the godot-rust equivalent of `preload`?
265266

266267
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.
275276

276277
Also, you can always put a Mutex<HashMap> into a Rust static and load everything you need there during a loading screen.
277278

279+
278280
## How do I keep a reference of `Node`?
279281

280282
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
315317

316318
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.
317319

320+
318321
## What is the Rust equivalent to `onready var` in GDScript
319322

320323
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
375378
- 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).
376379
- 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).
377380

381+
378382
## How can I profile my code to determine the performance?
379383

380384
There are a lot of ways to profile your code and they will vary in complexity.

src/faq/community.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Community FAQ
1+
# FAQ: Community
22

33
## I need help, where can I ask?
44

src/faq/configuration.md

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
# Configuration
1+
# FAQ: Configuration
22

33
## How do I create the library file for my GDNative binary?
44

55
You can create .gdnlib files with either of the following methods.
66

7-
### Editor
8-
1. In the editor, right click in the File System and Select "New Resource"
9-
2. Select GDNativeLibrary from the menu.
7+
### Editor
8+
9+
1. In the editor, right click in the File System and Select _New Resource_.
10+
2. Select _GDNativeLibrary_ from the menu.
1011
3. Save as new GDNativeLibrary. The typical file extension is `.gdnlib`.
1112
4. Select the GDNativeLibrary.
12-
5. For each desired target, select a path to the location of the library created by cargo.
13+
5. For each desired target, select a path to the location of the library created by Cargo.
1314

1415
### Manual
15-
Create a text file with the .gdnlib extension with the following content.
16+
17+
Create a text file with the `.gdnlib` extension with the following content.
1618
Please note: you only need to include paths for the targets you plan on building for.
1719

18-
```
20+
```toml
1921
[entry]
2022
X11.64="res://path/to/lib{name_of_binary}.so"
2123
OSX.64="res://path/to/lib{name_of_binary}.dylib"
@@ -33,13 +35,14 @@ symbol_prefix="godot_"
3335
reloadable=true
3436
```
3537

36-
## Once I create the .gdnlib file, how do I create the GDNative Script so that I can attach it to the nodes in the scene tree?
38+
39+
## Once I create the `.gdnlib` file, how do I create the native script, so that I can attach it to the nodes in the scene tree?
3740

3841
Script files can be created in two ways.
3942

4043
1. From the editor.
41-
2. Manually by creating a .gdns file with the following code snippet.
42-
```
44+
2. Manually by creating a `.gdns` file with the following code snippet.
45+
```toml
4346
[gd_resource type="NativeScript" load_steps=2 format=2]
4447

4548
[ext_resource path="res://path/to/{name of file}.gdnlib" type="GDNativeLibrary" id=1]
@@ -48,16 +51,17 @@ Script files can be created in two ways.
4851
resource_name = "{class name}"
4952
class_name = "{class name}"
5053
library = ExtResource( 1 )
51-
5254
```
5355

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`?
5556

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.
5760

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).
5962

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)?
6165

6266
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`.
6367

@@ -84,6 +88,7 @@ Please also see the [native_plugin](https://github.com/godot-rust/godot-rust/tre
8488
- 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.
8589
- 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.
8690

91+
8792
## Is it possible to use multiple libraries with GDNative?
8893

8994
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
9499

95100
To avoid these collisions, rather than the `godot_init!` initialization macro, prefer the use of the individual macros.
96101

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.
98103

99104
```rust
100105
// _ 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_
108113
godot_gdnative_terminate!(_ as my_symbol_prefix_gdnative_terminate);
109114
```
110115

111-
## 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?
112117

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.
114119

115120

116-
## How do I get code Auto-completion with rust-analyzer?
121+
## How do I get auto-completion with rust-analyzer?
117122

118123
`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:
119124

120-
![no-completion](../images/no-completion.png)
125+
![no-completion](img/no-completion.png)
121126

122127

123128
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:
124129

125-
![completion](../images/completion.png)
130+
![completion](img/completion.png)
126131

127132

128-
## How do I get code Auto-completion with IntelliJ Rust Plugin
133+
## How do I get auto-completion with IntelliJ-Rust plugin?
129134

130135
Similar to rust-analyzer, IntelliJ-Family IDEs struggle to autocomplete gdnative types generated at compile-time.
131136

@@ -138,6 +143,7 @@ Second, the bindings files generated (~8mb) are above the 2mb limit for files to
138143
* 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.
139144
* restart IDE
140145

146+
141147
## How can I make my debug builds more performant?
142148

143149
**Note**: These changes may slow down certain aspects of the build times for your game.

0 commit comments

Comments
 (0)