-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #902 from Houtamelo/rpc_annotation
Add `#[rpc]` attribute to user-defined functions
- Loading branch information
Showing
21 changed files
with
614 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) godot-rust; Bromeon and contributors. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
use crate::builtin::{Dictionary, StringName}; | ||
use crate::classes::multiplayer_api::RpcMode; | ||
use crate::classes::multiplayer_peer::TransferMode; | ||
use crate::classes::Node; | ||
use crate::dict; | ||
use crate::meta::ToGodot; | ||
|
||
/// Configuration for a remote procedure call, typically used with `#[rpc(config = ...)]`. | ||
/// | ||
/// See [Godot documentation](https://docs.godotengine.org/en/stable/tutorials/networking/high_level_multiplayer.html#remote-procedure-calls). | ||
#[derive(Copy, Clone, Debug)] | ||
pub struct RpcConfig { | ||
pub rpc_mode: RpcMode, | ||
pub transfer_mode: TransferMode, | ||
pub call_local: bool, | ||
pub channel: u32, | ||
} | ||
|
||
impl Default for RpcConfig { | ||
fn default() -> Self { | ||
Self { | ||
rpc_mode: RpcMode::AUTHORITY, | ||
transfer_mode: TransferMode::UNRELIABLE, | ||
call_local: false, | ||
channel: 0, | ||
} | ||
} | ||
} | ||
|
||
impl RpcConfig { | ||
/// Register `method` as a remote procedure call on `node`. | ||
pub fn configure_node(self, node: &mut Node, method_name: impl Into<StringName>) { | ||
node.rpc_config(method_name.into(), &self.to_dictionary().to_variant()); | ||
} | ||
|
||
/// Returns a [`Dictionary`] populated with the values required for a call to [`Node::rpc_config()`]. | ||
pub fn to_dictionary(&self) -> Dictionary { | ||
dict! { | ||
"rpc_mode": self.rpc_mode, | ||
"transfer_mode": self.transfer_mode, | ||
"call_local": self.call_local, | ||
"channel": self.channel, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.