godot-rust / gdext

Rust bindings for Godot 4
https://mastodon.gamedev.place/@GodotRust
Mozilla Public License 2.0
3.06k stars 190 forks source link

Implement `Rid` #102

Closed tengkuizdihar closed 1 year ago

tengkuizdihar commented 1 year ago

Original title: Creating A New Class From PhysicsServer3DExtension

Right now I'm trying to port Rapier Physics Engine to Godot 4 using PhysicsServer3DExtension. I have seen an example of this class in the wild with https://github.com/godot-jolt/godot-jolt/blob/HEAD/src/register_types.cpp#L28, but does anyone know the equivalent in rust gdextension?

So far I got to this point, with errors all over the place.

#[derive(GodotClass)]
#[class(base=PhysicsServer3DExtension)]
pub struct RapierPhysicsServer3D {
    #[base]
    base: Base<PhysicsServer3DExtension>,
}

#[godot_api]
impl RapierPhysicsServer3D {
}

This is the error log I got from cargo build

error[E0599]: the function or associated item `property_info` exists for tuple `(godot::prelude::Rid,)`, but its trait bounds were not satisfied
   --> examples/dodge-the-creeps/rust/src/main_scene.rs:172:1
    |
172 | #[godot_api]
    | ^^^^^^^^^^^^ function or associated item cannot be called on `(godot::prelude::Rid,)` due to unsatisfied trait bounds
    |
   ::: /home/notroot/programming/gdextension/godot-core/src/builtin/others.rs:25:1
    |
25  | impl_builtin_stub!(Rid, OpaqueRid);
    | ----------------------------------
    | |
    | doesn't satisfy `_: godot::prelude::meta::VariantMetadata`
    | doesn't satisfy `godot::prelude::Rid: Debug`
    | doesn't satisfy `godot::prelude::Rid: godot::prelude::ToVariant`
    |
    = note: the following trait bounds were not satisfied:
            `godot::prelude::Rid: godot::prelude::meta::VariantMetadata`
            which is required by `(godot::prelude::Rid,): godot::prelude::meta::SignatureTuple`
            `godot::prelude::Rid: godot::prelude::ToVariant`
            which is required by `(godot::prelude::Rid,): godot::prelude::meta::SignatureTuple`
            `godot::prelude::Rid: Debug`
            which is required by `(godot::prelude::Rid,): godot::prelude::meta::SignatureTuple`
    = note: this error originates in the macro `$crate::gdext_register_method_inner` which comes from the expansion of the attribute macro `godot_api` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: the function or associated item `param_metadata` exists for tuple `(godot::prelude::Rid,)`, but its trait bounds were not satisfied
   --> examples/dodge-the-creeps/rust/src/main_scene.rs:172:1
    |
172 | #[godot_api]
    | ^^^^^^^^^^^^ function or associated item cannot be called on `(godot::prelude::Rid,)` due to unsatisfied trait bounds
    |
   ::: /home/notroot/programming/gdextension/godot-core/src/builtin/others.rs:25:1
    |
25  | impl_builtin_stub!(Rid, OpaqueRid);
    | ----------------------------------
    | |
    | doesn't satisfy `_: godot::prelude::meta::VariantMetadata`
    | doesn't satisfy `godot::prelude::Rid: Debug`
    | doesn't satisfy `godot::prelude::Rid: godot::prelude::ToVariant`
    |
    = note: the following trait bounds were not satisfied:
            `godot::prelude::Rid: godot::prelude::meta::VariantMetadata`
            which is required by `(godot::prelude::Rid,): godot::prelude::meta::SignatureTuple`
            `godot::prelude::Rid: godot::prelude::ToVariant`
            which is required by `(godot::prelude::Rid,): godot::prelude::meta::SignatureTuple`
            `godot::prelude::Rid: Debug`
            which is required by `(godot::prelude::Rid,): godot::prelude::meta::SignatureTuple`
    = note: this error originates in the macro `$crate::gdext_register_method_inner` which comes from the expansion of the attribute macro `godot_api` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `godot::prelude::Rid: godot::prelude::meta::VariantMetadata` is not satisfied
   --> examples/dodge-the-creeps/rust/src/main_scene.rs:172:1
    |
172 | #[godot_api]
    | ^^^^^^^^^^^^ the trait `godot::prelude::meta::VariantMetadata` is not implemented for `godot::prelude::Rid`
    |
    = help: the following other types implement trait `godot::prelude::meta::VariantMetadata`:
              ()
              InstanceId
              Variant
              bool
              f32
              f64
              godot::prelude::Array
              godot::prelude::Color
            and 26 others
    = note: required for `(godot::prelude::Rid,)` to implement `godot::prelude::meta::SignatureTuple`
    = note: this error originates in the macro `$crate::gdext_register_method_inner` which comes from the expansion of the attribute macro `godot_api` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: `godot::prelude::Rid` doesn't implement `Debug`
   --> examples/dodge-the-creeps/rust/src/main_scene.rs:172:1
    |
172 | #[godot_api]
    | ^^^^^^^^^^^^ `godot::prelude::Rid` cannot be formatted using `{:?}` because it doesn't implement `Debug`
    |
    = help: the trait `Debug` is not implemented for `godot::prelude::Rid`
    = help: the following other types implement trait `godot::prelude::meta::SignatureTuple`:
              (R, P0)
              (R, P0, P1)
              (R, P0, P1, P2)
              (R, P0, P1, P2, P3)
              (R, P0, P1, P2, P3, P4)
              (R, P0, P1, P2, P3, P4, P5)
              (R, P0, P1, P2, P3, P4, P5, P6)
              (R, P0, P1, P2, P3, P4, P5, P6, P7)
            and 3 others
    = note: required for `(godot::prelude::Rid,)` to implement `godot::prelude::meta::SignatureTuple`
    = note: this error originates in the macro `$crate::gdext_register_method_inner` which comes from the expansion of the attribute macro `godot_api` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `godot::prelude::Rid: EngineEnum` is not satisfied
   --> examples/dodge-the-creeps/rust/src/main_scene.rs:172:1
    |
172 | #[godot_api]
    | ^^^^^^^^^^^^ the trait `EngineEnum` is not implemented for `godot::prelude::Rid`
    |
    = help: the following other types implement trait `EngineEnum`:
              ASTCFormat
              ActionMode
              ActionType
              AdvanceMode
              AfterGUIInput
              AlphaAntiAliasing
              AlphaMode
              AmbientMode
            and 599 others
    = note: required for `godot::prelude::Rid` to implement `godot::prelude::ToVariant`
    = note: required for `(godot::prelude::Rid,)` to implement `godot::prelude::meta::SignatureTuple`
    = note: this error originates in the macro `$crate::gdext_register_method_inner` which comes from the expansion of the attribute macro `godot_api` (in Nightly builds, run with -Z macro-backtrace for more info)

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `dodge-the-creeps` due to 9 previous errors
warning: build failed, waiting for other jobs to finish...
lilizoey commented 1 year ago

I tried this myself, but gdextension is still missing two main features to make this possible:

  1. A proper implementation of RID (though this can be worked around)
  2. The ability to overload arbitrary virtual methods. For the physicsservers you need to overload all the virtual methods defined in the extension-classes, which is currently not supported.

If you still wanna try to make this work you'll likely need to modify gdextension itself until proper support for at least arbitrary virtual methods is added.

tengkuizdihar commented 1 year ago

understandable, this is itching for me to solve, but I'll probably ask in discord for what could be done. Also, why is RID aren't supported yet, I thought it's basically just a regular UID?

Bromeon commented 1 year ago

Also, why is RID aren't supported yet, I thought it's basically just a regular UID?

It's a bit trickier if you also consider safety, see documentation of Rid in GDNative.

But even apart from that, the library is currently in an early experimental stage, as advertised in the ReadMe. A lot of things are not implemented.

Bromeon commented 1 year ago

I'll keep this issue around to track Rid implementation progress.