Skip to content

Implement packed arrays non-generically #91

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

Merged
merged 1 commit into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 1 addition & 33 deletions godot-core/src/builtin/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use godot_ffi as sys;

use crate::builtin::{inner, FromVariant, ToVariant, Variant, VariantConversionError};
use crate::builtin::*;
use crate::obj::Share;
use std::fmt;
use std::marker::PhantomData;
Expand Down Expand Up @@ -39,16 +39,6 @@ pub struct Array {
opaque: sys::types::OpaqueArray,
}

impl_builtin_stub!(PackedByteArray, OpaquePackedByteArray);
impl_builtin_stub!(PackedColorArray, OpaquePackedColorArray);
impl_builtin_stub!(PackedFloat32Array, OpaquePackedFloat32Array);
impl_builtin_stub!(PackedFloat64Array, OpaquePackedFloat64Array);
impl_builtin_stub!(PackedInt32Array, OpaquePackedInt32Array);
impl_builtin_stub!(PackedInt64Array, OpaquePackedInt64Array);
impl_builtin_stub!(PackedStringArray, OpaquePackedStringArray);
impl_builtin_stub!(PackedVector2Array, OpaquePackedVector2Array);
impl_builtin_stub!(PackedVector3Array, OpaquePackedVector3Array);

impl_builtin_froms!(Array;
PackedByteArray => array_from_packed_byte_array,
PackedColorArray => array_from_packed_color_array,
Expand All @@ -61,16 +51,6 @@ impl_builtin_froms!(Array;
PackedVector3Array => array_from_packed_vector3_array,
);

impl_builtin_froms!(PackedByteArray; Array => packed_byte_array_from_array);
impl_builtin_froms!(PackedColorArray; Array => packed_color_array_from_array);
impl_builtin_froms!(PackedFloat32Array; Array => packed_float32_array_from_array);
impl_builtin_froms!(PackedFloat64Array; Array => packed_float64_array_from_array);
impl_builtin_froms!(PackedInt32Array; Array => packed_int32_array_from_array);
impl_builtin_froms!(PackedInt64Array; Array => packed_int64_array_from_array);
impl_builtin_froms!(PackedStringArray; Array => packed_string_array_from_array);
impl_builtin_froms!(PackedVector2Array; Array => packed_vector2_array_from_array);
impl_builtin_froms!(PackedVector3Array; Array => packed_vector3_array_from_array);

impl Array {
fn from_opaque(opaque: sys::types::OpaqueArray) -> Self {
Self { opaque }
Expand Down Expand Up @@ -606,18 +586,6 @@ impl GodotFfi for Array {
}
}

fn to_i64(i: usize) -> i64 {
i.try_into().unwrap()
}

fn to_usize(i: i64) -> usize {
i.try_into().unwrap()
}

fn to_isize(i: usize) -> isize {
i.try_into().unwrap()
}

#[repr(C)]
pub struct TypedArray<T> {
opaque: OpaqueArray,
Expand Down
26 changes: 13 additions & 13 deletions godot-core/src/builtin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ mod arrays;
mod color;
mod node_path;
mod others;
mod packed_array;
mod string;
mod string_name;
mod variant;
Expand All @@ -55,6 +56,7 @@ pub use arrays::*;
pub use color::*;
pub use node_path::*;
pub use others::*;
pub use packed_array::*;
pub use string::*;
pub use string_name::*;
pub use variant::*;
Expand All @@ -71,16 +73,14 @@ pub mod inner {
pub use crate::gen::builtin_classes::*;
}

// pub struct PackedArray<T> {
// _phantom: std::marker::PhantomData<T>
// }
//
// pub type PackedByteArray = PackedArray<u8>;
// pub type PackedInt32Array = PackedArray<i32>;
// pub type PackedInt64Array = PackedArray<i64>;
// pub type PackedFloat32Array = PackedArray<f32>;
// pub type PackedFloat64Array = PackedArray<f64>;
// pub type PackedStringArray = PackedArray<GodotString>;
// pub type PackedVector2Array = PackedArray<Vector2>;
// pub type PackedVector3Array = PackedArray<Vector3>;
// pub type PackedColorArray = PackedArray<Color>;
pub(crate) fn to_i64(i: usize) -> i64 {
i.try_into().unwrap()
}

pub(crate) fn to_usize(i: i64) -> usize {
i.try_into().unwrap()
}

pub(crate) fn to_isize(i: usize) -> isize {
i.try_into().unwrap()
}
Loading