Open4
[Rust] gdnative → gdext 差分メモ

https://crates.io/crates/godot を使って GDExtention を作ろうとしている。
ゲームエンジン自体ほぼ初めて触ることもあり Chat AI に聞きまくっているが、 gdnative のコードばかり示してくる。
gdnative のこともわからないため、gdnative と gdext をまとめて差分に注目しながら調査・整理してみる。
参考

gdnative (Godot3)
gdext (Godot 4)
リポジトリ名は gdext だがクレート名は godot

おまじない
gdnative
#[derive(NativeClass)]
#[inherit(Node)]
struct CustomNode {..}
fn init(handle: InitHandle) {
handle.add_class::<CustomNode>();
}
godot_init!(init);
gdext
struct の登録は不要になったよう
特殊な処理をしたくなったときに、 unsafe impl
の中を実装することがあるかもしれないが、一応これで動くようになる
struct RustExtension;
#[gdextension]
unsafe impl ExtensionLibrary for RustExtension {}

マクロ系
gdnative | gdext | |
---|---|---|
#[derive(NativeClass) |
#[derive(GodotClass)] |
|
#[inherit(Node)] |
#[class(base=Node)] |
|
#[methods] |
#[godot_api] |
|
#[method] |
#[func] |