Skip to content

Commit

Permalink
Re-integrate virtual compat methods
Browse files Browse the repository at this point in the history
Revert "Minimal changes to make PR mergeable before upstream virtual-compat is ready"
This reverts commit 60e48ff.
  • Loading branch information
Bromeon committed Jan 12, 2025
1 parent 3dafef1 commit 95feb9b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
7 changes: 2 additions & 5 deletions godot-codegen/src/models/domain_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,12 @@ impl ClassMethod {
let direction = FnDirection::Virtual {
#[cfg(since_api = "4.4")]
hash: {
// TODO(v0.3,virtual-compat): re-enable this in favor of 0 fallback.
/*let hash_i64 = method.hash.unwrap_or_else(|| {
let hash_i64 = method.hash.unwrap_or_else(|| {
panic!(
"virtual class methods must have a hash since Godot 4.4; missing: {}.{}",
class_name.godot_ty, method.name
)
});*/
// Temporarily use hash 0 until upstream PR is merged.
let hash_i64 = method.hash.unwrap_or(0);
});

// TODO see if we can use u32 everywhere.
hash_i64.try_into().unwrap_or_else(|_| {
Expand Down
11 changes: 3 additions & 8 deletions godot-core/src/registry/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,12 @@ pub unsafe extern "C" fn free<T: GodotClass>(
pub unsafe extern "C" fn get_virtual<T: cap::ImplementsGodotVirtual>(
_class_user_data: *mut std::ffi::c_void,
name: sys::GDExtensionConstStringNamePtr,
// TODO(v0.3,virtual-compat): re-enable parameter
//hash: u32,
hash: u32,
) -> sys::GDExtensionClassCallVirtual {
// This string is not ours, so we cannot call the destructor on it.
let borrowed_string = StringName::borrow_string_sys(name);
let method_name = borrowed_string.to_string();

// TODO(v0.3,virtual-compat): remove local var
let hash = 0;
T::__virtual_call(method_name.as_str(), hash)
}

Expand All @@ -133,22 +130,20 @@ pub unsafe extern "C" fn get_virtual<T: cap::ImplementsGodotVirtual>(
// This string is not ours, so we cannot call the destructor on it.
let borrowed_string = StringName::borrow_string_sys(name);
let method_name = borrowed_string.to_string();

T::__virtual_call(method_name.as_str())
}

#[cfg(since_api = "4.4")]
pub unsafe extern "C" fn default_get_virtual<T: UserClass>(
_class_user_data: *mut std::ffi::c_void,
name: sys::GDExtensionConstStringNamePtr,
// TODO(v0.3,virtual-compat): re-enable parameter
// hash: u32,
hash: u32,
) -> sys::GDExtensionClassCallVirtual {
// This string is not ours, so we cannot call the destructor on it.
let borrowed_string = StringName::borrow_string_sys(name);
let method_name = borrowed_string.to_string();

// TODO(v0.3,virtual-compat): remove local var
let hash = 0;
T::__default_virtual_call(method_name.as_str(), hash)
}

Expand Down
5 changes: 1 addition & 4 deletions godot-core/src/registry/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ type GodotCreationInfo = sys::GDExtensionClassCreationInfo4;

#[cfg(before_api = "4.4")]
pub(crate) type GodotGetVirtual = <sys::GDExtensionClassGetVirtual as sys::Inner>::FnPtr;
// TODO(v0.3,virtual-compat): re-enable this to use GetVirtual2
// #[cfg(since_api = "4.4")]
// pub(crate) type GodotGetVirtual = <sys::GDExtensionClassGetVirtual2 as sys::Inner>::FnPtr;
#[cfg(since_api = "4.4")]
pub(crate) type GodotGetVirtual = <sys::GDExtensionClassGetVirtual as sys::Inner>::FnPtr;
pub(crate) type GodotGetVirtual = <sys::GDExtensionClassGetVirtual2 as sys::Inner>::FnPtr;

#[derive(Debug)]
struct ClassRegistrationInfo {
Expand Down

0 comments on commit 95feb9b

Please sign in to comment.