Skip to content

Commit 8dfffb2

Browse files
bors[bot]chitoyuu
andauthored
Merge #1006 #1007
1006: Expose RPC modes for properties r=chitoyuu a=chitoyuu This adds: - The `PropertyBuilder::with_rpc_mode` method - The `#[property(rpc = "mode")]` syntax for the NativeClass macro Close #995 1007: Deprecate specialized pool array aliases r=chitoyuu a=chitoyuu Related: #773 Co-authored-by: Chitose Yuuzaki <chitoyuu@potatoes.gay>
3 parents 2207b6d + 29f39e7 + 246e5f2 commit 8dfffb2

File tree

20 files changed

+172
-98
lines changed

20 files changed

+172
-98
lines changed

examples/rpc/src/client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ impl ServerPuppet {
4747
#[method]
4848
fn on_connected_to_server(&mut self, #[base] owner: TRef<Node>) {
4949
owner.rpc("greet_server", &[Variant::new("hello")]);
50+
owner.rset("foo", 42);
5051
}
5152

5253
#[method(rpc = "puppet")]

examples/rpc/src/server.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ const OUT_BANDWIDTH: i64 = 1000;
88

99
#[derive(NativeClass)]
1010
#[inherit(Node)]
11-
pub struct Server;
11+
pub struct Server {
12+
#[property(rpc = "master", set = "Self::set_foo")]
13+
foo: i32,
14+
}
1215

1316
#[methods]
1417
impl Server {
1518
fn new(_owner: &Node) -> Self {
16-
Self
19+
Self { foo: 0 }
1720
}
1821

1922
#[method]
@@ -41,4 +44,10 @@ impl Server {
4144
&[Variant::new("hello")],
4245
);
4346
}
47+
48+
#[method]
49+
fn set_foo(&mut self, #[base] _owner: TRef<Node>, value: i32) {
50+
godot_print!("Client sets foo to: {}", value);
51+
self.foo = value;
52+
}
4453
}

gdnative-core/src/core_types/byte_array.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ use crate::core_types::PoolArray;
33
/// A reference-counted vector of `u8` that uses Godot's pool allocator.
44
///
55
/// See [`PoolByteArray`](https://docs.godotengine.org/en/stable/classes/class_poolbytearray.html) in Godot.
6+
#[deprecated = "Specialized pool array aliases will be removed in a future godot-rust version. Use PoolArray<T> instead."]
67
pub type ByteArray = PoolArray<u8>;
78

89
godot_test!(
910
test_byte_array_access {
1011
use crate::object::NewRef as _;
1112

12-
let arr = (0..8).collect::<ByteArray>();
13+
let arr = (0..8).collect::<PoolArray<u8>>();
1314

1415
let original_read = {
1516
let read = arr.read();
@@ -48,7 +49,7 @@ godot_test!(
4849

4950
godot_test!(
5051
test_byte_array_debug {
51-
let arr = (0..8).collect::<ByteArray>();
52+
let arr = (0..8).collect::<PoolArray<u8>>();
5253
assert_eq!(format!("{arr:?}"), "[0, 1, 2, 3, 4, 5, 6, 7]");
5354
}
5455
);

gdnative-core/src/core_types/color_array.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ use crate::core_types::PoolArray;
44
/// A reference-counted vector of `Color` that uses Godot's pool allocator.
55
///
66
/// See [`PoolColorArray`](https://docs.godotengine.org/en/stable/classes/class_poolcolorarray.html) in Godot.
7+
#[deprecated = "Specialized pool array aliases will be removed in a future godot-rust version. Use PoolArray<T> instead."]
78
pub type ColorArray = PoolArray<Color>;
89

910
godot_test!(
1011
test_color_array_access {
1112
use crate::object::NewRef as _;
1213

13-
let arr = ColorArray::from_vec(vec![
14+
let arr = PoolArray::from_vec(vec![
1415
Color::from_rgb(1.0, 0.0, 0.0),
1516
Color::from_rgb(0.0, 1.0, 0.0),
1617
Color::from_rgb(0.0, 0.0, 1.0),
@@ -51,7 +52,7 @@ godot_test!(
5152

5253
godot_test!(
5354
test_color_array_debug {
54-
let arr = ColorArray::from_vec(vec![
55+
let arr = PoolArray::from_vec(vec![
5556
Color::from_rgb(1.0, 0.0, 0.0),
5657
Color::from_rgb(0.0, 1.0, 0.0),
5758
Color::from_rgb(0.0, 0.0, 1.0),

gdnative-core/src/core_types/float32_array.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ use crate::core_types::PoolArray;
33
/// A reference-counted vector of `f32` that uses Godot's pool allocator.
44
///
55
/// See [`PoolRealArray`](https://docs.godotengine.org/en/stable/classes/class_poolrealarray.html) in Godot.
6+
#[deprecated = "Specialized pool array aliases will be removed in a future godot-rust version. Use PoolArray<T> instead."]
67
pub type Float32Array = PoolArray<f32>;
78

89
godot_test!(
910
test_float32_array_access {
1011
use crate::object::NewRef as _;
1112

12-
let arr = (0..8).map(|i| i as f32).collect::<Float32Array>();
13+
let arr = (0..8).map(|i| i as f32).collect::<PoolArray<f32>>();
1314

1415
let original_read = {
1516
let read = arr.read();
@@ -42,7 +43,7 @@ godot_test!(
4243

4344
godot_test!(
4445
test_float32_array_debug {
45-
let arr = (0..8).map(|i| i as f32).collect::<Float32Array>();
46+
let arr = (0..8).map(|i| i as f32).collect::<PoolArray<f32>>();
4647
assert_eq!(format!("{arr:?}"), "[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]");
4748
}
4849
);

gdnative-core/src/core_types/int32_array.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ use crate::core_types::PoolArray;
33
/// A reference-counted vector of `i32` that uses Godot's pool allocator.
44
///
55
/// See [`PoolIntArray`](https://docs.godotengine.org/en/stable/classes/class_poolintarray.html) in Godot.
6+
#[deprecated = "Specialized pool array aliases will be removed in a future godot-rust version. Use PoolArray<T> instead."]
67
pub type Int32Array = PoolArray<i32>;
78

89
godot_test!(
910
test_int32_array_access {
1011
use crate::object::NewRef as _;
1112

12-
let arr = (0..8).collect::<Int32Array>();
13+
let arr = (0..8).collect::<PoolArray<i32>>();
1314

1415
let original_read = {
1516
let read = arr.read();
@@ -38,7 +39,7 @@ godot_test!(
3839

3940
godot_test!(
4041
test_int32_array_debug {
41-
let arr = (0..8).collect::<Int32Array>();
42+
let arr = (0..8).collect::<PoolArray<i32>>();
4243
assert_eq!(format!("{arr:?}"), "[0, 1, 2, 3, 4, 5, 6, 7]");
4344
}
4445
);

gdnative-core/src/core_types/string_array.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ use crate::core_types::PoolArray;
44
/// A reference-counted vector of `GodotString` that uses Godot's pool allocator.
55
///
66
/// See [`PoolStringArray`](https://docs.godotengine.org/en/stable/classes/class_poolstringarray.html) in Godot.
7+
#[deprecated = "Specialized pool array aliases will be removed in a future godot-rust version. Use PoolArray<T> instead."]
78
pub type StringArray = PoolArray<GodotString>;
89

910
godot_test!(
1011
test_string_array_access {
1112
use crate::object::NewRef as _;
1213

13-
let arr = StringArray::from_vec(vec![
14+
let arr = PoolArray::from_vec(vec![
1415
GodotString::from("foo"),
1516
GodotString::from("bar"),
1617
GodotString::from("baz"),
@@ -51,7 +52,7 @@ godot_test!(
5152

5253
godot_test!(
5354
test_string_array_debug {
54-
let arr = StringArray::from_vec(vec![
55+
let arr = PoolArray::from_vec(vec![
5556
GodotString::from("foo"),
5657
GodotString::from("bar"),
5758
GodotString::from("baz"),

gdnative-core/src/core_types/variant.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ decl_variant_type!(
155155
Object(Variant) = sys::godot_variant_type_GODOT_VARIANT_TYPE_OBJECT,
156156
Dictionary(Dictionary) = sys::godot_variant_type_GODOT_VARIANT_TYPE_DICTIONARY,
157157
VariantArray(VariantArray) = sys::godot_variant_type_GODOT_VARIANT_TYPE_ARRAY,
158-
ByteArray(ByteArray) = sys::godot_variant_type_GODOT_VARIANT_TYPE_POOL_BYTE_ARRAY,
159-
Int32Array(Int32Array) = sys::godot_variant_type_GODOT_VARIANT_TYPE_POOL_INT_ARRAY,
160-
Float32Array(Float32Array) = sys::godot_variant_type_GODOT_VARIANT_TYPE_POOL_REAL_ARRAY,
161-
StringArray(StringArray) = sys::godot_variant_type_GODOT_VARIANT_TYPE_POOL_STRING_ARRAY,
162-
Vector2Array(Vector2Array) = sys::godot_variant_type_GODOT_VARIANT_TYPE_POOL_VECTOR2_ARRAY,
163-
Vector3Array(Vector3Array) = sys::godot_variant_type_GODOT_VARIANT_TYPE_POOL_VECTOR3_ARRAY,
164-
ColorArray(ColorArray) = sys::godot_variant_type_GODOT_VARIANT_TYPE_POOL_COLOR_ARRAY,
158+
ByteArray(PoolArray<u8>) = sys::godot_variant_type_GODOT_VARIANT_TYPE_POOL_BYTE_ARRAY,
159+
Int32Array(PoolArray<i32>) = sys::godot_variant_type_GODOT_VARIANT_TYPE_POOL_INT_ARRAY,
160+
Float32Array(PoolArray<f32>) = sys::godot_variant_type_GODOT_VARIANT_TYPE_POOL_REAL_ARRAY,
161+
StringArray(PoolArray<GodotString>) = sys::godot_variant_type_GODOT_VARIANT_TYPE_POOL_STRING_ARRAY,
162+
Vector2Array(PoolArray<Vector2>) = sys::godot_variant_type_GODOT_VARIANT_TYPE_POOL_VECTOR2_ARRAY,
163+
Vector3Array(PoolArray<Vector3>) = sys::godot_variant_type_GODOT_VARIANT_TYPE_POOL_VECTOR3_ARRAY,
164+
ColorArray(PoolArray<Color>) = sys::godot_variant_type_GODOT_VARIANT_TYPE_POOL_COLOR_ARRAY,
165165
}
166166
);
167167

@@ -598,13 +598,13 @@ impl_coerce_from_variant!(
598598
impl CoerceFromVariant for GodotString = from_sys(godot_variant_as_string);
599599
impl CoerceFromVariant for Rid = from_sys(godot_variant_as_rid);
600600
impl CoerceFromVariant for VariantArray<Shared> = from_sys(godot_variant_as_array);
601-
impl CoerceFromVariant for ByteArray = from_sys(godot_variant_as_pool_byte_array);
602-
impl CoerceFromVariant for Int32Array = from_sys(godot_variant_as_pool_int_array);
603-
impl CoerceFromVariant for Float32Array = from_sys(godot_variant_as_pool_real_array);
604-
impl CoerceFromVariant for StringArray = from_sys(godot_variant_as_pool_string_array);
605-
impl CoerceFromVariant for Vector2Array = from_sys(godot_variant_as_pool_vector2_array);
606-
impl CoerceFromVariant for Vector3Array = from_sys(godot_variant_as_pool_vector3_array);
607-
impl CoerceFromVariant for ColorArray = from_sys(godot_variant_as_pool_color_array);
601+
impl CoerceFromVariant for PoolArray<u8> = from_sys(godot_variant_as_pool_byte_array);
602+
impl CoerceFromVariant for PoolArray<i32> = from_sys(godot_variant_as_pool_int_array);
603+
impl CoerceFromVariant for PoolArray<f32> = from_sys(godot_variant_as_pool_real_array);
604+
impl CoerceFromVariant for PoolArray<GodotString> = from_sys(godot_variant_as_pool_string_array);
605+
impl CoerceFromVariant for PoolArray<Vector2> = from_sys(godot_variant_as_pool_vector2_array);
606+
impl CoerceFromVariant for PoolArray<Vector3> = from_sys(godot_variant_as_pool_vector3_array);
607+
impl CoerceFromVariant for PoolArray<Color> = from_sys(godot_variant_as_pool_color_array);
608608
impl CoerceFromVariant for Dictionary<Shared> = from_sys(godot_variant_as_dictionary);
609609
);
610610

gdnative-core/src/core_types/vector2_array.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ use crate::core_types::Vector2;
44
/// A reference-counted vector of `Vector2` that uses Godot's pool allocator.
55
///
66
/// See [`PoolVector2Array`](https://docs.godotengine.org/en/stable/classes/class_poolvector2array.html) in Godot.
7+
#[deprecated = "Specialized pool array aliases will be removed in a future godot-rust version. Use PoolArray<T> instead."]
78
pub type Vector2Array = PoolArray<Vector2>;
89

910
godot_test!(
1011
test_vector2_array_access {
1112
use crate::object::NewRef as _;
1213

13-
let arr = Vector2Array::from_vec(vec![
14+
let arr = PoolArray::from_vec(vec![
1415
Vector2::new(1.0, 2.0),
1516
Vector2::new(3.0, 4.0),
1617
Vector2::new(5.0, 6.0),
@@ -51,7 +52,7 @@ godot_test!(
5152

5253
godot_test!(
5354
test_vector2_array_debug {
54-
let arr = Vector2Array::from_vec(vec![
55+
let arr = PoolArray::from_vec(vec![
5556
Vector2::new(1.0, 2.0),
5657
Vector2::new(3.0, 4.0),
5758
Vector2::new(5.0, 6.0),

gdnative-core/src/core_types/vector3_array.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ use crate::core_types::Vector3;
44
/// A reference-counted vector of `Vector3` that uses Godot's pool allocator.
55
///
66
/// See [`PoolVector3Array`](https://docs.godotengine.org/en/stable/classes/class_poolvector3array.html) in Godot.
7+
#[deprecated = "Specialized pool array aliases will be removed in a future godot-rust version. Use PoolArray<T> instead."]
78
pub type Vector3Array = PoolArray<Vector3>;
89

910
godot_test!(
1011
test_vector3_array_access {
1112
use crate::object::NewRef as _;
1213

13-
let arr = Vector3Array::from_vec(vec![
14+
let arr = PoolArray::from_vec(vec![
1415
Vector3::new(1.0, 2.0, 3.0),
1516
Vector3::new(3.0, 4.0, 5.0),
1617
Vector3::new(5.0, 6.0, 7.0),
@@ -52,7 +53,7 @@ godot_test!(
5253

5354
godot_test!(
5455
test_vector3_array_debug {
55-
let arr = Vector3Array::from_vec(vec![
56+
let arr = PoolArray::from_vec(vec![
5657
Vector3::new(1.0, 2.0, 3.0),
5758
Vector3::new(3.0, 4.0, 5.0),
5859
Vector3::new(5.0, 6.0, 7.0),

0 commit comments

Comments
 (0)