Skip to content

Commit

Permalink
Derive Var and Export for DynGd<T, D>
Browse files Browse the repository at this point in the history
- Remove unnecressary derive macros, make some classes private, add few readability fixes.
  • Loading branch information
Yarwin committed Jan 7, 2025
1 parent 321d929 commit a9873ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion godot-core/src/obj/dyn_gd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ where

fn set_property(&mut self, value: Self::Via) {
// `set_property` can't be delegated to Gd<T> since we have to set `erased_obj` as well
*self = Self::from_godot(value);
*self = <Self as FromGodot>::from_godot(value);
}
}

Expand Down
15 changes: 9 additions & 6 deletions godot-core/src/registry/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn global_loaded_classes_by_name() -> GlobalGuard<'static, HashMap<ClassName, Cl
lock_or_panic(&LOADED_CLASSES_BY_NAME, "loaded classes (by name)")
}

pub(crate) fn global_dyn_traits_by_typeid(
fn global_dyn_traits_by_typeid(
) -> GlobalGuard<'static, HashMap<any::TypeId, Vec<DynToClassRelation>>> {
static DYN_TRAITS_BY_TYPEID: Global<HashMap<any::TypeId, Vec<DynToClassRelation>>> =
Global::default();
Expand All @@ -68,7 +68,6 @@ pub struct LoadedClass {
pub struct ClassMetadata {}

/// Represents a `dyn Trait` implemented (and registered) for a class.
#[derive(Debug)]
pub struct DynToClassRelation {
implementing_class_name: ClassName,
erased_dynify_fn: ErasedDynifyFn,
Expand Down Expand Up @@ -194,7 +193,11 @@ pub fn register_class<
});
}

fn fill_the_registries(map: &mut HashMap<ClassName, ClassRegistrationInfo>, init_level: InitLevel) {
/// Populates all the registries with information derived from ClassRegistrationInfo
fn populate_the_registries(
map: &mut HashMap<ClassName, ClassRegistrationInfo>,
init_level: InitLevel,
) {
let mut loaded_classes_by_level = global_loaded_classes_by_init_level();
let mut loaded_classes_by_name = global_loaded_classes_by_name();
let mut dyn_traits_by_typeid = global_dyn_traits_by_typeid();
Expand Down Expand Up @@ -256,10 +259,10 @@ pub fn auto_register_classes(init_level: InitLevel) {
});

// First register all the loaded classes and dyn traits.
// We need all the dyn classes in the registry to properly register the properties;
// We need all the dyn classes in the registry to properly register DynGd properties;
// one can do it directly inside the loop – by locking and unlocking the mutex –
// but it is much slower and doesn't guarantee that all the dependent classes will be loaded in most cases.
fill_the_registries(&mut map, init_level);
// but it is much slower and doesn't guarantee that all the dependent classes will be already loaded in most cases.
populate_the_registries(&mut map, init_level);

// actually register all the classes
for info in map.into_values() {
Expand Down

0 comments on commit a9873ed

Please sign in to comment.