Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify module structure (redundant re-exports) #788

Merged
merged 17 commits into from Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions bindings_generator/src/api.rs
Expand Up @@ -422,7 +422,7 @@ impl Ty {
Ty::Bool => syn::parse_quote! { bool },
Ty::Vector2 => syn::parse_quote! { Vector2 },
Ty::Vector3 => syn::parse_quote! { Vector3 },
Ty::Vector3Axis => syn::parse_quote! { vector3::Axis },
Ty::Vector3Axis => syn::parse_quote! { Axis },
Ty::Quat => syn::parse_quote! { Quat },
Ty::Transform => syn::parse_quote! { Transform },
Ty::Transform2D => syn::parse_quote! { Transform2D },
Expand All @@ -448,7 +448,7 @@ impl Ty {
Ty::VariantOperator => syn::parse_quote! { VariantOperator },
Ty::Enum(path) => syn::parse_quote! { #path },
Ty::Object(path) => {
syn::parse_quote! { Option<Ref<#path, thread_access::Shared>> }
syn::parse_quote! { Option<Ref<#path, ownership::Shared>> }
}
}
}
Expand Down Expand Up @@ -597,7 +597,7 @@ impl Ty {
Ty::Object(ref path) => {
quote! {
ptr::NonNull::new(ret)
.map(|sys| <Ref<#path, thread_access::Shared>>::move_from_sys(sys))
.map(|sys| <Ref<#path, ownership::Shared>>::move_from_sys(sys))
}
}
Ty::Result => {
Expand Down
12 changes: 6 additions & 6 deletions bindings_generator/src/special_methods.rs
Expand Up @@ -26,7 +26,7 @@ destroying the object) or destroyed manually using `Ref::free`, or preferably
quote! {
#[doc=#documentation]
#[inline]
pub fn new() -> Ref<Self, thread_access::Unique> {
pub fn new() -> Ref<Self, ownership::Unique> {
unsafe {
let gd_api = get_api();
let ctor = #method_table::get(gd_api).class_constructor.unwrap();
Expand All @@ -42,17 +42,17 @@ pub fn generate_godot_object_impl(class: &GodotClass) -> TokenStream {
let name = &class.name;
let class_name = format_ident!("{}", class.name);

let ref_kind = if class.is_refcounted() {
quote! { ref_kind::RefCounted }
let memory = if class.is_refcounted() {
quote! { memory::RefCounted }
} else {
quote! { ref_kind::ManuallyManaged }
quote! { memory::ManuallyManaged }
};

quote! {
impl gdnative_core::private::godot_object::Sealed for #class_name {}

unsafe impl GodotObject for #class_name {
type RefKind = #ref_kind;
type RefKind = #memory;

#[inline]
fn class_name() -> &'static str {
Expand All @@ -69,7 +69,7 @@ pub fn generate_instantiable_impl(class: &GodotClass) -> TokenStream {
quote! {
impl Instanciable for #class_name {
#[inline]
fn construct() -> Ref<Self, thread_access::Unique> {
fn construct() -> Ref<Self, ownership::Unique> {
#class_name::new()
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/array_export/src/lib.rs
@@ -1,12 +1,12 @@
use gdnative::nativescript::init::property::hint::{ArrayHint, IntHint, RangeHint};
use gdnative::nativescript::export::property::hint::{ArrayHint, IntHint, RangeHint};
use gdnative::prelude::*;

#[derive(NativeClass)]
#[inherit(Node)]
#[register_with(Self::register)]
struct ExportsArrays;

#[gdnative::methods]
#[methods]
impl ExportsArrays {
fn new(_owner: &Node) -> Self {
ExportsArrays
Expand Down
2 changes: 1 addition & 1 deletion examples/dodge_the_creeps/src/main_scene.rs
Expand Up @@ -140,7 +140,7 @@ impl Main {
/// scene as the root. For instance Spatial is used for this example.
fn instance_scene<Root>(scene: &Ref<PackedScene, Shared>) -> Ref<Root, Unique>
where
Root: gdnative::GodotObject<RefKind = ManuallyManaged> + SubClass<Node>,
Root: gdnative::object::GodotObject<RefKind = ManuallyManaged> + SubClass<Node>,
{
let scene = unsafe { scene.assume_safe() };

Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world/src/lib.rs
Expand Up @@ -4,7 +4,7 @@ use gdnative::prelude::*;
#[inherit(Node)]
struct HelloWorld;

#[gdnative::methods]
#[methods]
impl HelloWorld {
fn new(_owner: &Node) -> Self {
HelloWorld
Expand Down
4 changes: 2 additions & 2 deletions examples/resource/src/lib.rs
Expand Up @@ -8,7 +8,7 @@ struct GreetingResource {
name: String,
}

#[gdnative::methods]
#[methods]
impl GreetingResource {
fn new(_owner: &Resource) -> Self {
Self { name: "".into() }
Expand All @@ -29,7 +29,7 @@ struct Greeter {
greeting_resource: Option<Instance<GreetingResource, Shared>>,
}

#[gdnative::methods]
#[methods]
impl Greeter {
fn new(_owner: &Node) -> Self {
Greeter {
Expand Down
12 changes: 6 additions & 6 deletions examples/scene_create/src/lib.rs
Expand Up @@ -6,7 +6,7 @@ pub enum ManageErrs {
RootClassNotSpatial(String),
}

#[derive(gdnative::NativeClass)]
#[derive(gdnative::derive::NativeClass)]
#[inherit(Spatial)]
struct SceneCreate {
// Store the loaded scene for a very slight performance boost but mostly to show you how.
Expand All @@ -24,7 +24,7 @@ struct SceneCreate {
// Note, the same mechanism which is used to call from panel into spawn_one and remove_one can be
// used to call other GDNative classes here in rust.

#[gdnative::methods]
#[gdnative::derive::methods]
impl SceneCreate {
fn new(_owner: &Spatial) -> Self {
SceneCreate {
Expand All @@ -33,7 +33,7 @@ impl SceneCreate {
}
}

#[export]
#[gdnative::derive::export]
fn _ready(&mut self, _owner: &Spatial) {
self.template = load_scene("res://Child_scene.tscn");
match &self.template {
Expand All @@ -42,7 +42,7 @@ impl SceneCreate {
}
}

#[export]
#[gdnative::derive::export]
fn spawn_one(&mut self, owner: &Spatial, message: GodotString) {
godot_print!("Called spawn_one({})", message.to_string());

Expand Down Expand Up @@ -77,7 +77,7 @@ impl SceneCreate {
update_panel(owner, num_children);
}

#[export]
#[gdnative::derive::export]
fn remove_one(&mut self, owner: &Spatial, str: GodotString) {
godot_print!("Called remove_one({})", str);
let num_children = owner.get_child_count();
Expand Down Expand Up @@ -116,7 +116,7 @@ pub fn load_scene(path: &str) -> Option<Ref<PackedScene, ThreadLocal>> {
/// scene as the root. For instance Spatial is used for this example.
fn instance_scene<Root>(scene: &PackedScene) -> Result<Ref<Root, Unique>, ManageErrs>
where
Root: gdnative::GodotObject<RefKind = ManuallyManaged> + SubClass<Node>,
Root: gdnative::object::GodotObject<RefKind = ManuallyManaged> + SubClass<Node>,
{
let instance = scene
.instance(PackedScene::GEN_EDIT_STATE_DISABLED)
Expand Down
6 changes: 3 additions & 3 deletions examples/spinning_cube/src/lib.rs
@@ -1,9 +1,9 @@
use gdnative::api::MeshInstance;
use gdnative::prelude::*;

use gdnative::nativescript::init::property::{EnumHint, IntHint, StringHint};
use gdnative::nativescript::export::property::{EnumHint, IntHint, StringHint};

#[derive(gdnative::NativeClass)]
#[derive(gdnative::derive::NativeClass)]
#[inherit(MeshInstance)]
#[register_with(register_properties)]
struct RustTest {
Expand Down Expand Up @@ -36,7 +36,7 @@ fn register_properties(builder: &ClassBuilder<RustTest>) {
.done();
}

#[gdnative::methods]
#[methods]
impl RustTest {
fn new(_owner: &MeshInstance) -> Self {
RustTest {
Expand Down
3 changes: 1 addition & 2 deletions gdnative-bindings/src/generated.rs
Expand Up @@ -8,10 +8,9 @@ use std::sync::Once;

use gdnative_core::core_types::*;
use gdnative_core::object::*;
use gdnative_core::object::{memory, ownership};
use gdnative_core::private::get_api;
use gdnative_core::sys;
use gdnative_core::sys::GodotApi;
use gdnative_core::thread_access;
use gdnative_core::{ref_kind, GodotResult};

include!(concat!(env!("OUT_DIR"), "/generated.rs"));
5 changes: 2 additions & 3 deletions gdnative-bindings/src/utils.rs
Expand Up @@ -2,9 +2,8 @@

use super::generated::{Engine, Node, SceneTree};
use gdnative_core::nativescript::{NativeClass, RefInstance};
use gdnative_core::object::SubClass;
use gdnative_core::thread_access::Shared;
use gdnative_core::TRef;
use gdnative_core::object::ownership::Shared;
use gdnative_core::object::{SubClass, TRef};

/// Convenience method to obtain a reference to an "auto-load" node, that is a child of the root
/// node. Returns `None` if the node does not exist or is not of the correct type.
Expand Down
15 changes: 8 additions & 7 deletions gdnative-core/Cargo.toml
Expand Up @@ -18,16 +18,17 @@ type_tag_fallback = []

[dependencies]
gdnative-sys = { path = "../gdnative-sys", version = "0.9.3" }
libc = "0.2.98"
gdnative-impl-proc-macros = { path = "../impl/proc_macros", version = "=0.9.3" }
ahash = "0.7.4"
approx = "0.5.0"
atomic-take = "1.0.0"
bitflags = { version = "1.2.1", optional = true }
glam = "0.18.0"
indexmap = "1.7.0"
ahash = "0.7.4"
libc = "0.2.98"
once_cell = "1.8.0"
parking_lot = { version = "0.11.1", optional = true }
serde = { version = "1", features = ["derive"], optional = true }

gdnative-impl-proc-macros = { path = "../impl/proc_macros", version = "=0.9.3" }

bitflags = { version = "1.2.1", optional = true }
parking_lot = { version = "0.11.1", optional = true }
atomic-take = "1.0.0"
[dev-dependencies]
gdnative = { path = "../gdnative", version = "0.9.3" } # for doc-tests
8 changes: 4 additions & 4 deletions gdnative-core/src/core_types/access.rs
Expand Up @@ -5,21 +5,21 @@ use std::ops::{Deref, DerefMut};
use std::ptr;
use std::slice;

/// A pool array access that may be unaligned.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
/// An pool array access that may be unaligned.
pub struct MaybeUnaligned<G> {
guard: G,
}

/// A pool array access that is (assumed to be) aligned.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
/// An pool array access that is (assumed to be) aligned.
pub struct Aligned<G> {
guard: G,
}

#[derive(Debug)]
/// An pool array write access with an owned aligned copy. The data is written back when this is
/// A pool array write access with an owned aligned copy. The data is written back when this is
/// dropped.
#[derive(Debug)]
pub struct Owned<G>
where
G: Guard + WritePtr,
Expand Down
4 changes: 2 additions & 2 deletions gdnative-core/src/core_types/byte_array.rs
@@ -1,11 +1,11 @@
use crate::core_types::typed_array::TypedArray;
use crate::core_types::TypedArray;

/// A reference-counted vector of `u8` that uses Godot's pool allocator.
pub type ByteArray = TypedArray<u8>;

godot_test!(
test_byte_array_access {
use crate::NewRef as _;
use crate::object::NewRef as _;

let arr = (0..8).collect::<ByteArray>();

Expand Down
4 changes: 2 additions & 2 deletions gdnative-core/src/core_types/color_array.rs
@@ -1,12 +1,12 @@
use crate::core_types::typed_array::TypedArray;
use crate::core_types::Color;
use crate::core_types::TypedArray;

/// A reference-counted vector of `Color` that uses Godot's pool allocator.
pub type ColorArray = TypedArray<Color>;

godot_test!(
test_color_array_access {
use crate::NewRef as _;
use crate::object::NewRef as _;

let arr = ColorArray::from_vec(vec![
Color::from_rgb(1.0, 0.0, 0.0),
Expand Down
4 changes: 2 additions & 2 deletions gdnative-core/src/core_types/dictionary.rs
Expand Up @@ -12,10 +12,10 @@ use crate::core_types::ToVariant;
use crate::core_types::ToVariantEq;
use crate::core_types::Variant;
use crate::core_types::VariantArray;
use crate::NewRef;
use crate::object::NewRef;
use std::fmt;

use crate::thread_access::*;
use crate::object::ownership::*;

/// A reference-counted `Dictionary` of `Variant` key-value pairs.
///
Expand Down
3 changes: 3 additions & 0 deletions gdnative-core/src/core_types/error.rs
Expand Up @@ -82,3 +82,6 @@ impl std::fmt::Display for GodotError {
}

impl std::error::Error for GodotError {}

/// Result type with [GodotError]
pub type GodotResult = Result<(), GodotError>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it the rationale behind moving GodotResult to core_types is that it's the Rust-side implementation for the Godot Error codes, correct? If so, I like this change. It makes a lot of sense to put GodotResult here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and to be honest I didn't know a module that would fit better. But your reason sounds more sophisticated 😅

4 changes: 2 additions & 2 deletions gdnative-core/src/core_types/float32_array.rs
@@ -1,11 +1,11 @@
use crate::core_types::typed_array::TypedArray;
use crate::core_types::TypedArray;

/// A reference-counted vector of `f32` that uses Godot's pool allocator.
pub type Float32Array = TypedArray<f32>;

godot_test!(
test_float32_array_access {
use crate::NewRef as _;
use crate::object::NewRef as _;

let arr = (0..8).map(|i| i as f32).collect::<Float32Array>();

Expand Down
4 changes: 2 additions & 2 deletions gdnative-core/src/core_types/int32_array.rs
@@ -1,11 +1,11 @@
use crate::core_types::typed_array::TypedArray;
use crate::core_types::TypedArray;

/// A reference-counted vector of `i32` that uses Godot's pool allocator.
pub type Int32Array = TypedArray<i32>;

godot_test!(
test_int32_array_access {
use crate::NewRef as _;
use crate::object::NewRef as _;

let arr = (0..8).collect::<Int32Array>();

Expand Down