From 465c05ec8d9369b8f3fe47697d7a06c7d6029c7f Mon Sep 17 00:00:00 2001 From: Christopher Durham Date: Wed, 25 May 2022 19:24:41 -0500 Subject: [PATCH] Move primitive type registration into bevy_reflect --- crates/bevy_core/src/lib.rs | 16 +--------- crates/bevy_reflect/src/type_registry.rs | 38 +++++++++++++++++++++++- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index b06302296e1ad5..ff48402bc437a7 100644 --- a/crates/bevy_core/src/lib.rs +++ b/crates/bevy_core/src/lib.rs @@ -44,21 +44,7 @@ impl Plugin for CorePlugin { } fn register_rust_types(app: &mut App) { - app.register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() + app.register_type::>() .register_type::() .register_type::>(); } diff --git a/crates/bevy_reflect/src/type_registry.rs b/crates/bevy_reflect/src/type_registry.rs index 5155895178021b..c663cae6decdfe 100644 --- a/crates/bevy_reflect/src/type_registry.rs +++ b/crates/bevy_reflect/src/type_registry.rs @@ -6,7 +6,6 @@ use serde::Deserialize; use std::{any::TypeId, fmt::Debug, sync::Arc}; /// A registry of reflected types. -#[derive(Default)] pub struct TypeRegistry { registrations: HashMap, short_name_to_id: HashMap, @@ -35,7 +34,44 @@ pub trait GetTypeRegistration { fn get_type_registration() -> TypeRegistration; } +impl Default for TypeRegistry { + fn default() -> Self { + Self::new() + } +} + impl TypeRegistry { + /// Create a type registry with *no* registered types. + pub fn empty() -> Self { + Self { + registrations: Default::default(), + short_name_to_id: Default::default(), + full_name_to_id: Default::default(), + ambiguous_names: Default::default(), + } + } + + /// Create a type registry with default registrations for primitive types. + pub fn new() -> Self { + let mut registry = Self::empty(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry + } + /// Registers the type `T`. pub fn register(&mut self) where