From d8c5266919bb9368781e71e654c704934e10ce6e 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 | 19 ++---------- crates/bevy_reflect/src/type_registry.rs | 38 +++++++++++++++++++++++- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index b06302296e1ad5..6b770f3a01e7b9 100644 --- a/crates/bevy_core/src/lib.rs +++ b/crates/bevy_core/src/lib.rs @@ -35,8 +35,7 @@ impl Plugin for CorePlugin { app.register_type::>() .register_type::>() .register_type::() - .register_type::() - .register_type::>(); + .register_type::(); register_rust_types(app); register_math_types(app); @@ -44,21 +43,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