Skip to content

Commit 3aa1d81

Browse files
committed
- Remove GodotFuncMarshal
- Rename VariantMetadata -> GodotMetadata - Add GodotCompatible, ToGodot, FromGodot - Add RawGd - Change everything so that To/FromGodot is the canonical way of passing values over the ffi-boundary - Change `GodotMetadata` to sealed `GodotType` - Implement `GodotType` for various types - Add `GodotFfiVariant` - Add tests for creating newtype wrappers around godot types - Fix to/from variant derives
1 parent 7594e9c commit 3aa1d81

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2060
-1193
lines changed

godot-codegen/src/central_generator.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ fn make_sys_code(central_items: &CentralItems) -> TokenStream {
397397
let [opaque_32bit, opaque_64bit] = opaque_types;
398398

399399
quote! {
400-
use crate::{ffi_methods, GDExtensionTypePtr, GDExtensionVariantOperator, GDExtensionVariantType, GodotFfi};
400+
use crate::{GDExtensionVariantOperator, GDExtensionVariantType};
401401

402402
#[cfg(target_pointer_width = "32")]
403403
pub mod types {
@@ -443,12 +443,6 @@ fn make_sys_code(central_items: &CentralItems) -> TokenStream {
443443
}
444444
}
445445

446-
// SAFETY:
447-
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
448-
unsafe impl GodotFfi for VariantType {
449-
ffi_methods! { type GDExtensionTypePtr = *mut Self; .. }
450-
}
451-
452446
// ----------------------------------------------------------------------------------------------------------------------------------------------
453447

454448
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
@@ -475,12 +469,6 @@ fn make_sys_code(central_items: &CentralItems) -> TokenStream {
475469
self as _
476470
}
477471
}
478-
479-
// SAFETY:
480-
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
481-
unsafe impl GodotFfi for VariantOperator {
482-
ffi_methods! { type GDExtensionTypePtr = *mut Self; .. }
483-
}
484472
}
485473
}
486474

godot-codegen/src/class_generator.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,8 @@ fn make_special_builtin_methods(class_name: &TyName, _ctx: &Context) -> TokenStr
10621062
if class_name.godot_ty == "Array" {
10631063
quote! {
10641064
pub fn from_outer_typed<T>(outer: &Array<T>) -> Self
1065-
where T: crate::builtin::meta::VariantMetadata
1065+
where
1066+
T: crate::builtin::meta::GodotType
10661067
{
10671068
Self {
10681069
_outer_lifetime: std::marker::PhantomData,

godot-codegen/src/util.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -334,21 +334,22 @@ pub fn make_enum_definition(enum_: &Enum) -> TokenStream {
334334
}
335335
#index_enum_impl
336336

337-
impl sys::GodotFuncMarshal for #enum_name {
337+
impl crate::builtin::meta::GodotCompatible for #enum_name {
338338
type Via = i64;
339-
type FromViaError = sys::PrimitiveConversionError<i64, i32>;
340-
type IntoViaError = std::convert::Infallible;
339+
}
341340

342-
fn try_from_via(via: Self::Via) -> std::result::Result<Self, Self::FromViaError> {
343-
let err = sys::PrimitiveConversionError::new(via);
344-
let ord = i32::try_from(via).map_err(|_| err)?;
345-
<Self as crate::obj::EngineEnum>::try_from_ord(ord).ok_or(err)
341+
impl crate::builtin::meta::ToGodot for #enum_name {
342+
fn to_godot(&self) -> Self::Via {
343+
<Self as crate::obj::EngineEnum>::ord(*self) as i64
344+
}
346345
}
347346

348-
fn try_into_via(self) -> std::result::Result<Self::Via, Self::IntoViaError> {
349-
Ok(<Self as crate::obj::EngineEnum>::ord(self).into())
347+
impl crate::builtin::meta::FromGodot for #enum_name {
348+
fn try_from_godot(via: Self::Via) -> Option<Self> {
349+
<Self as crate::obj::EngineEnum>::try_from_ord(i32::try_from(via).ok()?)
350350
}
351351
}
352+
352353
#bitfield_ops
353354
}
354355
}

godot-core/src/builtin/aabb.rs

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use sys::{ffi_methods, GodotFfi};
1010
use crate::builtin::math::ApproxEq;
1111
use crate::builtin::{real, Plane, Vector3, Vector3Axis};
1212

13+
use super::meta::impl_godot_as_self;
14+
1315
/// Axis-aligned bounding box in 3D space.
1416
///
1517
/// `Aabb` consists of a position, a size, and several utility functions. It is typically used for
@@ -396,9 +398,15 @@ impl std::fmt::Display for Aabb {
396398
// SAFETY:
397399
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
398400
unsafe impl GodotFfi for Aabb {
401+
fn variant_type() -> sys::VariantType {
402+
sys::VariantType::Aabb
403+
}
404+
399405
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
400406
}
401407

408+
impl_godot_as_self!(Aabb);
409+
402410
impl ApproxEq for Aabb {
403411
/// Returns `true` if the two `Aabb`s are approximately equal, by calling `is_equal_approx` on
404412
/// `position` and `size`.

0 commit comments

Comments
 (0)