Skip to content

Commit

Permalink
Merge #828
Browse files Browse the repository at this point in the history
828: Remove deprecated symbols from v0.9 r=Bromeon a=Bromeon

Changes:
* `PoolArray` type aliases: document name of Godot equivalent + API link
* `ClassBuilder`
  * Remove `add_method()`
  * Remove `add_method_advanced()` -- now private
  * Remove `add_method_with_rpc_mode()`
  * Rename `add_property()` -> `property()`
  * Rename `build_method()` -> `method()`
  * Add `signal()`
* Add `SignalBuilder` + `with_param*()` methods
* Remove `ScriptMethod`, `ScriptMethodFn`, `ScriptMethodAttributes`
* Remove `Color::rgb()`, `Color::rgba()`
* Remove `Reference::init_ref()` (unsound to call directly)
* Remove `FloatHint::Enum` (has no effect)
* Rename `Element` -> `PoolElement`
* Rename `SignalArgument` -> `SignalParam`
* Rename `String::forget()` -> `leak()`
* Rename `Variant::forget()` -> `leak()`
* Fix bug with signal parameter types annotated in builder not propagated to Godot
* Annotate 3 builders with `#[must_use]` to avoid forgetting building
   * Not done for `ClassBuilder`; it's not a builder in that sense

Co-authored-by: Jan Haller <bromeon@gmail.com>
  • Loading branch information
bors[bot] and Bromeon committed Dec 19, 2021
2 parents 86e9583 + 305b57f commit 1d5fc8e
Show file tree
Hide file tree
Showing 36 changed files with 383 additions and 300 deletions.
2 changes: 1 addition & 1 deletion bindings_generator/src/methods.rs
Expand Up @@ -136,7 +136,7 @@ impl MethodSig {
}

fn skip_method(method: &GodotMethod, name: &str) -> bool {
const METHODS: &[&str] = &["free", "reference", "unreference"];
const METHODS: &[&str] = &["free", "reference", "unreference", "init_ref"];
METHODS.contains(&name) || method.is_virtual
}

Expand Down
11 changes: 7 additions & 4 deletions examples/array_export/src/lib.rs
Expand Up @@ -14,25 +14,28 @@ impl ExportsArrays {

fn register(builder: &ClassBuilder<Self>) {
builder
.add_property::<VariantArray>("single_array")
.property::<VariantArray>("single_array")
.with_setter(ExportsArrays::set_single_array)
.done();

builder
.add_property::<VariantArray>("single_array_range")
.property::<VariantArray>("single_array_range")
.with_setter(ExportsArrays::set_single_array_range)
.with_hint(ArrayHint::with_element_hint::<i64>(IntHint::Range(
RangeHint::new(-5, 5),
)))
.done();

builder
.add_property::<VariantArray>("double_array")
.property::<VariantArray>("double_array")
.with_setter(ExportsArrays::set_double_array)
.with_hint(ArrayHint::with_element_hint::<VariantArray>(
ArrayHint::new(),
))
.done();

builder
.add_property::<VariantArray>("double_array_range")
.property::<VariantArray>("double_array_range")
.with_setter(ExportsArrays::set_double_array_range)
.with_hint(ArrayHint::with_element_hint::<VariantArray>(
ArrayHint::with_element_hint::<i64>(IntHint::Range(RangeHint::new(-5, 5))),
Expand Down
5 changes: 1 addition & 4 deletions examples/dodge_the_creeps/src/hud.rs
Expand Up @@ -9,10 +9,7 @@ pub struct Hud;
#[methods]
impl Hud {
fn register_hud(builder: &ClassBuilder<Self>) {
builder.add_signal(Signal {
name: "start_game",
args: &[],
});
builder.signal("start_game").done();
}

fn new(_owner: &CanvasLayer) -> Self {
Expand Down
5 changes: 1 addition & 4 deletions examples/dodge_the_creeps/src/player.rs
Expand Up @@ -16,10 +16,7 @@ pub struct Player {
#[methods]
impl Player {
fn register_player(builder: &ClassBuilder<Self>) {
builder.add_signal(Signal {
name: "hit",
args: &[],
});
builder.signal("hit").done()
}

fn new(_owner: &Area2D) -> Self {
Expand Down
18 changes: 5 additions & 13 deletions examples/signals/src/lib.rs
Expand Up @@ -12,21 +12,13 @@ struct SignalEmitter {
#[methods]
impl SignalEmitter {
fn register_signals(builder: &ClassBuilder<Self>) {
builder.add_signal(Signal {
name: "tick",
args: &[],
});
builder.signal("tick").done();

builder.add_signal(Signal {
name: "tick_with_data",
builder
.signal("tick_with_data")
// Argument list used by the editor for GUI and generation of GDScript handlers. It can be omitted if the signal is only used from code.
args: &[SignalArgument {
name: "data",
default: Variant::new(100),
export_info: ExportInfo::new(VariantType::I64),
usage: PropertyUsage::DEFAULT,
}],
});
.with_param_default("data", Variant::new(100))
.done();
}

fn new(_owner: &Node) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions examples/spinning_cube/src/lib.rs
Expand Up @@ -15,7 +15,7 @@ struct RustTest {

fn register_properties(builder: &ClassBuilder<RustTest>) {
builder
.add_property::<String>("test/test_enum")
.property::<String>("test/test_enum")
.with_hint(StringHint::Enum(EnumHint::new(vec![
"Hello".into(),
"World".into(),
Expand All @@ -25,7 +25,7 @@ fn register_properties(builder: &ClassBuilder<RustTest>) {
.done();

builder
.add_property("test/test_flags")
.property("test/test_flags")
.with_hint(IntHint::Flags(EnumHint::new(vec![
"A".into(),
"B".into(),
Expand Down
4 changes: 1 addition & 3 deletions gdnative-async/src/rt/bridge.rs
Expand Up @@ -134,8 +134,6 @@ impl Method<SignalBridge> for OnSignalFn {

impl NativeClassMethods for SignalBridge {
fn register(builder: &ClassBuilder<Self>) {
builder
.build_method("_on_signal", OnSignalFn)
.done_stateless();
builder.method("_on_signal", OnSignalFn).done_stateless();
}
}
29 changes: 10 additions & 19 deletions gdnative-async/src/rt/func_state.rs
@@ -1,9 +1,8 @@
use gdnative_bindings::Reference;
use gdnative_core::core_types::{ToVariant, Variant, VariantType};
use gdnative_core::core_types::{ToVariant, Variant};
use gdnative_core::export::user_data::{LocalCellData, Map, MapMut};
use gdnative_core::export::{
ClassBuilder, ExportInfo, NativeClass, NativeClassMethods, PropertyUsage, Signal,
SignalArgument, StaticArgs, StaticArgsMethod,
ClassBuilder, NativeClass, NativeClassMethods, StaticArgs, StaticArgsMethod,
};
use gdnative_core::godot_site;
use gdnative_core::object::ownership::Unique;
Expand Down Expand Up @@ -32,20 +31,12 @@ impl NativeClass for FuncState {
}

fn register_properties(builder: &ClassBuilder<Self>) {
builder.add_signal(Signal {
name: "completed",
args: &[SignalArgument {
name: "value",
default: Variant::nil(),
export_info: ExportInfo::new(VariantType::Nil),
usage: PropertyUsage::DEFAULT,
}],
});

builder.add_signal(Signal {
name: "resumable",
args: &[],
});
builder
.signal("completed")
.with_param_untyped("value")
.done();

builder.signal("resumable").done();
}
}

Expand Down Expand Up @@ -169,10 +160,10 @@ impl StaticArgsMethod<FuncState> for ResumeFn {
impl NativeClassMethods for FuncState {
fn register(builder: &ClassBuilder<Self>) {
builder
.build_method("is_valid", StaticArgs::new(IsValidFn))
.method("is_valid", StaticArgs::new(IsValidFn))
.done_stateless();
builder
.build_method("resume", StaticArgs::new(ResumeFn))
.method("resume", StaticArgs::new(ResumeFn))
.done_stateless();
}
}
6 changes: 3 additions & 3 deletions gdnative-core/src/core_types/access.rs
Expand Up @@ -50,12 +50,12 @@ pub unsafe trait Guard: private::Sealed {
pub unsafe trait WritePtr: Guard + private::Sealed {}

pub(crate) mod private {
use crate::core_types::pool_array::Element;
use crate::core_types::PoolElement;

pub trait Sealed {}

impl<'a, T: Element> Sealed for crate::core_types::pool_array::ReadGuard<'a, T> {}
impl<'a, T: Element> Sealed for crate::core_types::pool_array::WriteGuard<'a, T> {}
impl<'a, T: PoolElement> Sealed for crate::core_types::pool_array::ReadGuard<'a, T> {}
impl<'a, T: PoolElement> Sealed for crate::core_types::pool_array::WriteGuard<'a, T> {}
}

impl<G: Guard> MaybeUnaligned<G> {
Expand Down
2 changes: 2 additions & 0 deletions gdnative-core/src/core_types/byte_array.rs
@@ -1,6 +1,8 @@
use crate::core_types::PoolArray;

/// A reference-counted vector of `u8` that uses Godot's pool allocator.
///
/// See [`PoolByteArray`](https://docs.godotengine.org/en/stable/classes/class_poolbytearray.html) in Godot.
pub type ByteArray = PoolArray<u8>;

godot_test!(
Expand Down
12 changes: 0 additions & 12 deletions gdnative-core/src/core_types/color.rs
Expand Up @@ -15,18 +15,6 @@ pub struct Color {
}

impl Color {
#[deprecated]
#[inline]
pub fn rgba(r: f32, g: f32, b: f32, a: f32) -> Color {
Color { r, g, b, a }
}

#[deprecated]
#[inline]
pub fn rgb(r: f32, g: f32, b: f32) -> Color {
Color { r, g, b, a: 1.0 }
}

#[inline]
pub fn from_rgba(r: f32, g: f32, b: f32, a: f32) -> Color {
Color { r, g, b, a }
Expand Down
2 changes: 2 additions & 0 deletions gdnative-core/src/core_types/color_array.rs
Expand Up @@ -2,6 +2,8 @@ use crate::core_types::Color;
use crate::core_types::PoolArray;

/// A reference-counted vector of `Color` that uses Godot's pool allocator.
///
/// See [`PoolColorArray`](https://docs.godotengine.org/en/stable/classes/class_poolcolorarray.html) in Godot.
pub type ColorArray = PoolArray<Color>;

godot_test!(
Expand Down
2 changes: 2 additions & 0 deletions gdnative-core/src/core_types/float32_array.rs
@@ -1,6 +1,8 @@
use crate::core_types::PoolArray;

/// A reference-counted vector of `f32` that uses Godot's pool allocator.
///
/// See [`PoolRealArray`](https://docs.godotengine.org/en/stable/classes/class_poolrealarray.html) in Godot.
pub type Float32Array = PoolArray<f32>;

godot_test!(
Expand Down
2 changes: 2 additions & 0 deletions gdnative-core/src/core_types/int32_array.rs
@@ -1,6 +1,8 @@
use crate::core_types::PoolArray;

/// A reference-counted vector of `i32` that uses Godot's pool allocator.
///
/// See [`PoolIntArray`](https://docs.godotengine.org/en/stable/classes/class_poolintarray.html) in Godot.
pub type Int32Array = PoolArray<i32>;

godot_test!(
Expand Down
2 changes: 1 addition & 1 deletion gdnative-core/src/core_types/mod.rs
Expand Up @@ -37,7 +37,7 @@ pub use float32_array::*;
pub use geom::*;
pub use int32_array::*;
pub use node_path::*;
pub use pool_array::*; // TODO rename Element to something more specific
pub use pool_array::*;
pub use rid::*;
pub use string::*;
pub use string_array::*;
Expand Down

0 comments on commit 1d5fc8e

Please sign in to comment.