diff --git a/Cargo.toml b/Cargo.toml index ee26789e927da..bc85084c68c6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,7 +75,7 @@ bevy_internal = {path = "crates/bevy_internal", version = "0.3.0", default-featu [dev-dependencies] anyhow = "1.0" rand = "0.7.3" -ron = "0.6" +ron = "0.6.2" serde = {version = "1", features = ["derive"]} [[example]] @@ -255,12 +255,24 @@ name = "touch_input_events" path = "examples/input/touch_input_events.rs" [[example]] -name = "scene" -path = "examples/scene/scene.rs" +name = "reflection" +path = "examples/reflection/reflection.rs" + +[[example]] +name = "reflection_types" +path = "examples/reflection/reflection_types.rs" + +[[example]] +name = "generic_reflection" +path = "examples/reflection/generic_reflection.rs" + +[[example]] +name = "trait_reflection" +path = "examples/reflection/trait_reflection.rs" [[example]] -name = "properties" -path = "examples/scene/properties.rs" +name = "scene" +path = "examples/scene/scene.rs" [[example]] name = "mesh_custom_attribute" diff --git a/assets/scenes/load_scene_example.scn b/assets/scenes/load_scene_example.scn index a68262197272b..5b3672715b2f4 100644 --- a/assets/scenes/load_scene_example.scn +++ b/assets/scenes/load_scene_example.scn @@ -3,16 +3,42 @@ entity: 0, components: [ { - "type": "ComponentB", - "map": { - "value": "hello", + "type": "bevy_transform::components::transform::Transform", + "struct": { + "translation": { + "type": "glam::f32::vec3::Vec3", + "value": (0.0, 0.0, 0.0), + }, + "rotation": { + "type": "glam::f32::quat::Quat", + "value": (0.0, 0.0, 0.0, 1.0), + }, + "scale": { + "type": "glam::f32::vec3::Vec3", + "value": (1.0, 1.0, 1.0), + }, }, }, { - "type": "ComponentA", - "map": { - "x": 1.0, - "y": 2.0, + "type": "scene::ComponentB", + "struct": { + "value": { + "type": "alloc::string::String", + "value": "hello", + }, + }, + }, + { + "type": "scene::ComponentA", + "struct": { + "x": { + "type": "f32", + "value": 1.0, + }, + "y": { + "type": "f32", + "value": 2.0, + }, }, }, ], @@ -21,10 +47,16 @@ entity: 1, components: [ { - "type": "ComponentA", - "map": { - "x": 3.0, - "y": 4.0, + "type": "scene::ComponentA", + "struct": { + "x": { + "type": "f32", + "value": 3.0, + }, + "y": { + "type": "f32", + "value": 4.0, + }, }, }, ], diff --git a/crates/bevy_asset/Cargo.toml b/crates/bevy_asset/Cargo.toml index d0ef595e9434d..31b5d9f075935 100644 --- a/crates/bevy_asset/Cargo.toml +++ b/crates/bevy_asset/Cargo.toml @@ -20,13 +20,11 @@ filesystem_watcher = ["notify"] # bevy bevy_app = { path = "../bevy_app", version = "0.3.0" } bevy_ecs = { path = "../bevy_ecs", version = "0.3.0" } +bevy_reflect = { path = "../bevy_reflect", version = "0.3.0", features = ["bevy"] } bevy_tasks = { path = "../bevy_tasks", version = "0.3.0" } -bevy_type_registry = { path = "../bevy_type_registry", version = "0.3.0" } -bevy_property = { path = "../bevy_property", version = "0.3.0" } bevy_utils = { path = "../bevy_utils", version = "0.3.0" } # other -uuid = { version = "0.8", features = ["v4", "serde"] } serde = { version = "1", features = ["derive"] } ron = "0.6.2" crossbeam-channel = "0.4.4" diff --git a/crates/bevy_asset/src/asset_server.rs b/crates/bevy_asset/src/asset_server.rs index eebda681cb369..90d1bc910bb93 100644 --- a/crates/bevy_asset/src/asset_server.rs +++ b/crates/bevy_asset/src/asset_server.rs @@ -7,12 +7,11 @@ use crate::{ use anyhow::Result; use bevy_ecs::Res; use bevy_tasks::TaskPool; -use bevy_utils::HashMap; +use bevy_utils::{HashMap, Uuid}; use crossbeam_channel::TryRecvError; use parking_lot::RwLock; use std::{collections::hash_map::Entry, path::Path, sync::Arc}; use thiserror::Error; -use uuid::Uuid; /// Errors that occur while loading assets with an AssetServer #[derive(Error, Debug)] diff --git a/crates/bevy_asset/src/assets.rs b/crates/bevy_asset/src/assets.rs index e3fd86c20a478..83cbeccc9433d 100644 --- a/crates/bevy_asset/src/assets.rs +++ b/crates/bevy_asset/src/assets.rs @@ -3,7 +3,6 @@ use crate::{ }; use bevy_app::{prelude::Events, AppBuilder}; use bevy_ecs::{FromResources, ResMut}; -use bevy_type_registry::RegisterType; use bevy_utils::HashMap; use crossbeam_channel::Sender; use std::fmt::Debug; @@ -218,7 +217,6 @@ impl AddAsset for AppBuilder { }; self.add_resource(assets) - .register_component::>() .add_system_to_stage(super::stage::ASSET_EVENTS, Assets::::asset_event_system) .add_system_to_stage(crate::stage::LOAD_ASSETS, update_asset_storage_system::) .add_event::>() diff --git a/crates/bevy_asset/src/handle.rs b/crates/bevy_asset/src/handle.rs index f028309197d37..f14aa5d228d88 100644 --- a/crates/bevy_asset/src/handle.rs +++ b/crates/bevy_asset/src/handle.rs @@ -5,20 +5,20 @@ use std::{ marker::PhantomData, }; -use bevy_property::{Properties, Property}; -use crossbeam_channel::{Receiver, Sender}; -use serde::{Deserialize, Serialize}; -use uuid::Uuid; - use crate::{ path::{AssetPath, AssetPathId}, Asset, Assets, }; +use bevy_reflect::{Reflect, ReflectDeserialize}; +use bevy_utils::Uuid; +use crossbeam_channel::{Receiver, Sender}; +use serde::{Deserialize, Serialize}; /// A unique, stable asset id #[derive( - Debug, Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Serialize, Deserialize, Property, + Debug, Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Serialize, Deserialize, Reflect, )] +#[reflect_value(Serialize, Deserialize, PartialEq, Hash)] pub enum HandleId { Id(Uuid, u64), AssetPathId(AssetPathId), @@ -56,15 +56,15 @@ impl HandleId { /// A handle into a specific Asset of type `T` /// /// Handles contain a unique id that corresponds to a specific asset in the [Assets](crate::Assets) collection. -#[derive(Properties)] +#[derive(Reflect)] pub struct Handle where T: 'static, { pub id: HandleId, - #[property(ignore)] + #[reflect(ignore)] handle_type: HandleType, - #[property(ignore)] + #[reflect(ignore)] marker: PhantomData, } @@ -184,7 +184,7 @@ impl From<&Handle> for HandleId { impl Hash for Handle { fn hash(&self, state: &mut H) { - self.id.hash(state); + Hash::hash(&self.id, state); } } @@ -311,7 +311,7 @@ impl From<&HandleUntyped> for HandleId { impl Hash for HandleUntyped { fn hash(&self, state: &mut H) { - self.id.hash(state); + Hash::hash(&self.id, state); } } diff --git a/crates/bevy_asset/src/info.rs b/crates/bevy_asset/src/info.rs index 506f09dbfe4f1..f781fa0eea66a 100644 --- a/crates/bevy_asset/src/info.rs +++ b/crates/bevy_asset/src/info.rs @@ -1,8 +1,7 @@ use crate::{path::AssetPath, LabelId}; -use bevy_utils::{HashMap, HashSet}; +use bevy_utils::{HashMap, HashSet, Uuid}; use serde::{Deserialize, Serialize}; use std::path::PathBuf; -use uuid::Uuid; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct SourceMeta { diff --git a/crates/bevy_asset/src/lib.rs b/crates/bevy_asset/src/lib.rs index f97abe5e1826e..20941024edd70 100644 --- a/crates/bevy_asset/src/lib.rs +++ b/crates/bevy_asset/src/lib.rs @@ -13,6 +13,7 @@ mod path; pub use asset_server::*; pub use assets::*; +use bevy_reflect::RegisterTypeBuilder; use bevy_tasks::IoTaskPool; pub use handle::*; pub use info::*; @@ -31,7 +32,6 @@ pub mod prelude { } use bevy_app::{prelude::Plugin, AppBuilder}; -use bevy_type_registry::RegisterType; /// Adds support for Assets to an App. Assets are typed collections with change tracking, which are added as App Resources. /// Examples of assets: textures, sounds, 3d models, maps, scenes @@ -76,7 +76,7 @@ impl Plugin for AssetPlugin { app.add_stage_before(bevy_app::stage::PRE_UPDATE, stage::LOAD_ASSETS) .add_stage_after(bevy_app::stage::POST_UPDATE, stage::ASSET_EVENTS) .add_resource(asset_server) - .register_property::() + .register_type::() .add_system_to_stage( bevy_app::stage::PRE_UPDATE, asset_server::free_unused_assets_system, diff --git a/crates/bevy_asset/src/loader.rs b/crates/bevy_asset/src/loader.rs index 903f5efca9ec5..68bca038d055b 100644 --- a/crates/bevy_asset/src/loader.rs +++ b/crates/bevy_asset/src/loader.rs @@ -4,7 +4,7 @@ use crate::{ }; use anyhow::Result; use bevy_ecs::{Res, ResMut, Resource}; -use bevy_type_registry::{TypeUuid, TypeUuidDynamic}; +use bevy_reflect::{TypeUuid, TypeUuidDynamic}; use bevy_utils::{BoxedFuture, HashMap}; use crossbeam_channel::{Receiver, Sender}; use downcast_rs::{impl_downcast, Downcast}; diff --git a/crates/bevy_asset/src/path.rs b/crates/bevy_asset/src/path.rs index 89abed1547a6d..5a116c3608eb7 100644 --- a/crates/bevy_asset/src/path.rs +++ b/crates/bevy_asset/src/path.rs @@ -1,4 +1,4 @@ -use bevy_property::Property; +use bevy_reflect::{Reflect, ReflectDeserialize}; use bevy_utils::AHasher; use serde::{Deserialize, Serialize}; use std::{ @@ -58,18 +58,21 @@ impl<'a> AssetPath<'a> { } #[derive( - Debug, Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Serialize, Deserialize, Property, + Debug, Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Serialize, Deserialize, Reflect, )] +#[reflect_value(PartialEq, Hash, Serialize, Deserialize)] pub struct AssetPathId(SourcePathId, LabelId); #[derive( - Debug, Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Serialize, Deserialize, Property, + Debug, Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Serialize, Deserialize, Reflect, )] +#[reflect_value(PartialEq, Hash, Serialize, Deserialize)] pub struct SourcePathId(u64); #[derive( - Debug, Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Serialize, Deserialize, Property, + Debug, Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Serialize, Deserialize, Reflect, )] +#[reflect_value(PartialEq, Hash, Serialize, Deserialize)] pub struct LabelId(u64); impl<'a> From<&'a Path> for SourcePathId { diff --git a/crates/bevy_audio/Cargo.toml b/crates/bevy_audio/Cargo.toml index 5dac2083c43b5..b4517d9ef829b 100644 --- a/crates/bevy_audio/Cargo.toml +++ b/crates/bevy_audio/Cargo.toml @@ -17,7 +17,7 @@ keywords = ["bevy"] bevy_app = { path = "../bevy_app", version = "0.3.0" } bevy_asset = { path = "../bevy_asset", version = "0.3.0" } bevy_ecs = { path = "../bevy_ecs", version = "0.3.0" } -bevy_type_registry = { path = "../bevy_type_registry", version = "0.3.0" } +bevy_reflect = { path = "../bevy_reflect", version = "0.3.0", features = ["bevy"] } bevy_utils = { path = "../bevy_utils", version = "0.3.0" } # other diff --git a/crates/bevy_audio/src/audio_source.rs b/crates/bevy_audio/src/audio_source.rs index 7f36276a0001b..087640afc4543 100644 --- a/crates/bevy_audio/src/audio_source.rs +++ b/crates/bevy_audio/src/audio_source.rs @@ -1,6 +1,6 @@ use anyhow::Result; use bevy_asset::{AssetLoader, LoadContext, LoadedAsset}; -use bevy_type_registry::TypeUuid; +use bevy_reflect::TypeUuid; use bevy_utils::BoxedFuture; use std::{io::Cursor, sync::Arc}; diff --git a/crates/bevy_core/Cargo.toml b/crates/bevy_core/Cargo.toml index 57d677473a418..2e419c07a4d8b 100644 --- a/crates/bevy_core/Cargo.toml +++ b/crates/bevy_core/Cargo.toml @@ -17,8 +17,7 @@ keywords = ["bevy"] bevy_app = { path = "../bevy_app", version = "0.3.0" } bevy_derive = { path = "../bevy_derive", version = "0.3.0" } bevy_ecs = { path = "../bevy_ecs", version = "0.3.0" } -bevy_property = { path = "../bevy_property", version = "0.3.0" } -bevy_type_registry = { path = "../bevy_type_registry", version = "0.3.0" } bevy_math = { path = "../bevy_math", version = "0.3.0" } -bevy_utils = { path = "../bevy_utils", version = "0.3.0" } +bevy_reflect = { path = "../bevy_reflect", version = "0.3.0", features = ["bevy"] } bevy_tasks = { path = "../bevy_tasks", version = "0.3.0" } +bevy_utils = { path = "../bevy_utils", version = "0.3.0" } diff --git a/crates/bevy_core/src/label.rs b/crates/bevy_core/src/label.rs index e01aa170a536d..ebcceb490bc1e 100644 --- a/crates/bevy_core/src/label.rs +++ b/crates/bevy_core/src/label.rs @@ -1,5 +1,5 @@ use bevy_ecs::prelude::*; -use bevy_property::Properties; +use bevy_reflect::Reflect; use bevy_utils::{HashMap, HashSet}; use std::{ borrow::Cow, @@ -8,7 +8,7 @@ use std::{ }; /// A collection of labels -#[derive(Default, Properties)] +#[derive(Default, Reflect)] pub struct Labels { labels: HashSet>, } diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index 03edeef476a94..01339438be2f2 100644 --- a/crates/bevy_core/src/lib.rs +++ b/crates/bevy_core/src/lib.rs @@ -4,6 +4,9 @@ mod label; mod task_pool_options; mod time; +use std::ops::Range; + +use bevy_reflect::RegisterTypeBuilder; pub use bytes::*; pub use float_ord::*; pub use label::*; @@ -15,8 +18,6 @@ pub mod prelude { } use bevy_app::prelude::*; -use bevy_math::{Mat3, Mat4, Quat, Vec2, Vec3}; -use bevy_type_registry::RegisterType; /// Adds core functionality to Apps. #[derive(Default)] @@ -32,13 +33,9 @@ impl Plugin for CorePlugin { app.init_resource::