Skip to content

Commit

Permalink
Apply new base rules to itest and dodge-the-creeps
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Aug 1, 2023
1 parent 4bfc044 commit f7dd12b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 51 deletions.
21 changes: 11 additions & 10 deletions examples/dodge-the-creeps/rust/src/main_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,19 @@ impl Main {
self.base.add_child(mob_scene.share().upcast());

let mut mob = mob_scene.cast::<mob::Mob>();
{
// Local scope to bind `mob`
let mut mob = mob.bind_mut();
let range = rng.gen_range(mob.min_speed..mob.max_speed);

mob.set_linear_velocity(Vector2::new(range, 0.0));
let lin_vel = mob.get_linear_velocity().rotated(real::from_f32(direction));
mob.set_linear_velocity(lin_vel);
}
let range = {
// Local scope to bind `mob` user object
let mob = mob.bind();
rng.gen_range(mob.min_speed..mob.max_speed)
};

let mut mob = mob.base_mut();
mob.set_linear_velocity(Vector2::new(range, 0.0));
let lin_vel = mob.get_linear_velocity().rotated(real::from_f32(direction));
mob.set_linear_velocity(lin_vel);

let mut hud = self.base.get_node_as::<Hud>("Hud");
hud.bind_mut().connect(
hud.base_mut().connect(
"start_game".into(),
Callable::from_object_method(mob, "on_start_game"),
);
Expand Down
2 changes: 0 additions & 2 deletions examples/dodge-the-creeps/rust/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ impl Area2DVirtual for Player {
}

fn process(&mut self, delta: f64) {
println!("process");

let mut animated_sprite = self
.base
.get_node_as::<AnimatedSprite2D>("AnimatedSprite2D");
Expand Down
7 changes: 2 additions & 5 deletions itest/rust/src/callable_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@

use godot::bind::{godot_api, GodotClass};
use godot::builtin::{varray, Callable, ToVariant, Variant};
use godot::engine::{Object, RefCounted};
use godot::obj::{Base, Gd, Share};
use godot::engine::Object;
use godot::obj::{Gd, Share};
use godot::prelude::GodotString;
use godot::test::itest;

#[derive(GodotClass)]
#[class(init, base=RefCounted)]
struct CallableTestObj {
#[base]
base: Base<RefCounted>,

value: i32,
}

Expand Down
6 changes: 3 additions & 3 deletions itest/rust/src/codegen_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn codegen_base_renamed() {
// The registration is done at startup time, so it may already fail during GDExtension init.
// Nevertheless, try to instantiate an object with base HttpRequest here.

let obj = Gd::with_base(|base| TestBaseRenamed { base });
let obj = Gd::with_base(|base| TestBaseRenamed { _base: base });
let _id = obj.instance_id();

obj.free();
Expand Down Expand Up @@ -62,7 +62,7 @@ fn codegen_constants() {
#[class(base=HttpRequest)]
pub struct TestBaseRenamed {
#[base]
base: Base<HttpRequest>,
_base: Base<HttpRequest>,
}

#[allow(unused)]
Expand All @@ -81,7 +81,7 @@ impl TestBaseRenamed {
#[godot_api]
impl HttpRequestVirtual for TestBaseRenamed {
fn init(base: Base<HttpRequest>) -> Self {
TestBaseRenamed { base }
TestBaseRenamed { _base: base }
}

// Test unnamed parameter in virtual function
Expand Down
5 changes: 1 addition & 4 deletions itest/rust/src/native_structures_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ use std::cell::Cell;
#[derive(GodotClass)]
#[class(base=TextServerExtension)]
pub struct TestTextServer {
#[base]
base: Base<TextServerExtension>,
glyphs: [Glyph; 2],
cell: Cell<Option<(Rid, i64)>>,
}
Expand All @@ -40,9 +38,8 @@ fn sample_glyph(start: i32) -> Glyph {

#[godot_api]
impl TextServerExtensionVirtual for TestTextServer {
fn init(base: Base<TextServerExtension>) -> Self {
fn init(_base: Base<TextServerExtension>) -> Self {
TestTextServer {
base,
glyphs: [sample_glyph(99), sample_glyph(700)],
cell: Cell::new(None),
}
Expand Down
28 changes: 1 addition & 27 deletions itest/rust/src/object_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

use std::cell::{Cell, RefCell};
use std::mem;
use std::rc::Rc;

use godot::bind::{godot_api, GodotClass};
Expand Down Expand Up @@ -56,7 +55,7 @@ fn object_subtype_swap() {
println!("..swap..");
*/

mem::swap(&mut *a, &mut *b);
std::mem::swap(&mut *a, &mut *b);

/*
dbg!(a_id);
Expand Down Expand Up @@ -792,9 +791,6 @@ fn custom_constructor_works() {
#[derive(GodotClass)]
#[class(init, base=Object)]
struct DoubleUse {
#[base]
base: Base<Object>,

used: Cell<bool>,
}

Expand Down Expand Up @@ -850,25 +846,3 @@ fn double_use_reference() {
double_use.free();
emitter.free();
}

#[derive(GodotClass)]
#[class(init, base=Object)]
struct GodotApiTest {
#[base]
base: Base<Object>,
}

#[godot_api]
impl GodotApiTest {
#[func]
fn func_only_mut(&mut self, mut _a: Gd<Object>, mut _b: Gd<Object>) {}
#[func]
fn func_mut_and_not_mut(&mut self, _a: Gd<Object>, mut _b: Gd<Object>, _c: Gd<Object>) {}
// #[func]
// fn func_optional(&mut self, _a: Gd<Object>, mut _b: Gd<Object>, #[opt(987)] _c: i32) {}
// #[func] // waiting https://github.com/godotengine/godot/pull/75415
// /// Godot Docs
// fn func_docs(&mut self, _a: Gd<Object>, mut _b: Gd<Object>) {}
// #[func]
// fn func_lifetime<'a>(&'a mut self) {}
}

0 comments on commit f7dd12b

Please sign in to comment.