Skip to content

Commit

Permalink
Merge pull request godot-rust#461 from aekobear/mut-cvoid-and-themedb
Browse files Browse the repository at this point in the history
Re-enable `ThemeDb` + impl `GodotConvert` for `*mut c_void`
  • Loading branch information
Bromeon authored Oct 24, 2023
2 parents 01787a7 + 4650b82 commit 0028a86
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
10 changes: 8 additions & 2 deletions godot-codegen/src/special_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ pub(crate) fn is_class_deleted(class_name: &TyName) -> bool {
_ => {}
}

// ThemeDB was previously loaded lazily
// in 4.2 it loads at the Scene level
// see: https://github.com/godotengine/godot/pull/81305
#[cfg(before_api = "4.2")]
if class_name == "ThemeDB" {
return true;
}

match class_name {
// Hardcoded cases that are not accessible.
// Only on Android.
Expand All @@ -76,8 +84,6 @@ pub(crate) fn is_class_deleted(class_name: &TyName) -> bool {
// Only on WASM.
| "JavaScriptBridge"
| "JavaScriptObject"
// lazily loaded; TODO enable this.
| "ThemeDB"

// Thread APIs.
| "Thread"
Expand Down
11 changes: 1 addition & 10 deletions godot-codegen/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ pub enum ClassCodegenLevel {
Servers,
Scene,
Editor,

/// Not pre-fetched because Godot does not load them in time.
Lazy,
}

impl ClassCodegenLevel {
Expand All @@ -54,7 +51,6 @@ impl ClassCodegenLevel {
Self::Servers => "servers",
Self::Scene => "scene",
Self::Editor => "editor",
Self::Lazy => unreachable!("lazy classes should be deleted at the moment"),
}
}

Expand All @@ -63,7 +59,6 @@ impl ClassCodegenLevel {
Self::Servers => "Servers",
Self::Scene => "Scene",
Self::Editor => "Editor",
Self::Lazy => unreachable!("lazy classes should be deleted at the moment"),
}
}

Expand All @@ -72,7 +67,6 @@ impl ClassCodegenLevel {
Self::Servers => quote! { Some(crate::init::InitLevel::Servers) },
Self::Scene => quote! { Some(crate::init::InitLevel::Scene) },
Self::Editor => quote! { Some(crate::init::InitLevel::Editor) },
Self::Lazy => quote! { None },
}
}
}
Expand Down Expand Up @@ -203,10 +197,7 @@ pub fn make_sname_ptr(identifier: &str) -> TokenStream {
}

pub fn get_api_level(class: &Class) -> ClassCodegenLevel {
if class.name == "ThemeDB" {
// registered in C++ register_scene_singletons(), after MODULE_INITIALIZATION_LEVEL_EDITOR happens.
ClassCodegenLevel::Lazy
} else if class.name.ends_with("Server") {
if class.name.ends_with("Server") {
ClassCodegenLevel::Servers
} else if class.api_type == "core" {
ClassCodegenLevel::Scene
Expand Down
17 changes: 17 additions & 0 deletions godot-core/src/builtin/meta/godot_convert/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ impl_godot_scalar!(
// Raw pointers

// const void* is used in some APIs like OpenXrApiExtension::transform_from_pose().
// void* is used by ScriptExtension::instance_create().
// Other impls for raw pointers are generated for native structures.

impl GodotConvert for *const std::ffi::c_void {
Expand All @@ -240,3 +241,19 @@ impl FromGodot for *const std::ffi::c_void {
Some(via as Self)
}
}

impl GodotConvert for *mut std::ffi::c_void {
type Via = i64;
}

impl ToGodot for *mut std::ffi::c_void {
fn to_godot(&self) -> Self::Via {
*self as i64
}
}

impl FromGodot for *mut std::ffi::c_void {
fn try_from_godot(via: Self::Via) -> Option<Self> {
Some(via as Self)
}
}

0 comments on commit 0028a86

Please sign in to comment.