@@ -681,8 +681,58 @@ pub fn derive_godot_class(input: TokenStream) -> TokenStream {
681
681
///
682
682
/// You can use the `#[rpc]` attribute to let your functions act as remote procedure calls (RPCs) in Godot. This is the Rust equivalent of
683
683
/// GDScript's [`@rpc` annotation](https://docs.godotengine.org/en/stable/tutorials/networking/high_level_multiplayer.html#remote-procedure-calls).
684
+ /// `#[rpc]` is only supported for classes inheriting `Node`, and they need to declare a `Base<T>` field.
684
685
///
686
+ /// The syntax follows GDScript'a `@rpc`. You can optionally specify up to four keys; omitted ones use their default value.
687
+ /// Here's an overview:
685
688
///
689
+ /// | Setting | Type | Possible values (first is default) |
690
+ /// |---------------|------------------|----------------------------------------------------|
691
+ /// | RPC mode | [`RpcMode`] | **`authority`**, `any_peer` |
692
+ /// | Sync | `bool` | **`call_remote`**, `call_local` |
693
+ /// | Transfer mode | [`TransferMode`] | **`unreliable`**, `unreliable_ordered`, `reliable` |
694
+ /// | Channel | `u32` | any |
695
+ ///
696
+ /// You can also use `#[rpc(config = value)]`, with `value` being a constant of type [`RpcConfig`] in scope. This can be useful to reuse
697
+ /// configurations across multiple RPCs.
698
+ ///
699
+ /// `#[rpc]` implies `#[func]`. You can use both attributes together, if you need to configure other `#[func]`-specific keys.
700
+ ///
701
+ /// For example, the following method declarations are all equivalent:
702
+ /// ```
703
+ /// use godot::classes::multiplayer_api::RpcMode;
704
+ /// use godot::classes::multiplayer_peer::TransferMode;
705
+ /// use godot::prelude::*;
706
+ /// use godot::register::RpcConfig;
707
+ ///
708
+ /// # #[derive(GodotClass)]
709
+ /// # #[class(no_init, base=Node)]
710
+ /// # struct MyStruct {
711
+ /// # base: Base<Node>,
712
+ /// # }
713
+ /// #[godot_api]
714
+ /// impl MyStruct {
715
+ /// #[rpc(unreliable_ordered, channel = 2)]
716
+ /// fn with_defaults(&mut self) {}
717
+ ///
718
+ /// #[rpc(authority, unreliable_ordered, call_remote, channel = 2)]
719
+ /// fn explicit(&mut self) {}
720
+ ///
721
+ /// #[rpc(config = MY_RPC_CONFIG)]
722
+ /// fn external_config(&mut self) {}
723
+ /// }
724
+ ///
725
+ /// const MY_RPC_CONFIG: RpcConfig = RpcConfig {
726
+ /// transfer_mode: TransferMode::UNRELIABLE_ORDERED,
727
+ /// channel: 2,
728
+ /// ..Default::default()
729
+ /// };
730
+ /// ```
731
+ ///
732
+ // Note: for some reason, the intra-doc links don't work here, despite dev-dependency on godot.
733
+ /// [`RpcMode`]: ../classes/multiplayer_api/struct.RpcMode.html
734
+ /// [`TransferMode`]: ../classes/multiplayer_peer/struct.TransferMode.html
735
+ /// [`RpcConfig`]: ../register/struct.RpcConfig.html
686
736
///
687
737
/// # Constants and signals
688
738
///
0 commit comments