diff --git a/Cargo.toml b/Cargo.toml index d76733b1d3..cea3e2bd3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,6 @@ edition = "2018" [dependencies] legion = { git = "https://github.com/TomGillen/legion.git", rev = "940ef3bfcb77e5d074ee3184b776ff1600da228d", features = ["serde-1"] } -legion_transform = { path = "src/transform" } wgpu = { git = "https://github.com/gfx-rs/wgpu-rs.git", rev = "4a0da16fe6764c4e1dc918a31cbd7467d404df51"} glam = "0.8.4" winit = "0.20.0-alpha6" @@ -21,6 +20,8 @@ uuid = { version = "0.8", features = ["v4"] } erased-serde = "0.3" type-uuid = "0.1" shaderc = "0.6" +bevy_derive = { path = "bevy_derive" } +bevy_transform = { path = "bevy_transform" } [profile.release] debug = true \ No newline at end of file diff --git a/bevy_derive/Cargo.toml b/bevy_derive/Cargo.toml new file mode 100644 index 0000000000..efa36b6681 --- /dev/null +++ b/bevy_derive/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "bevy_derive" +version = "0.1.0" +authors = ["Carter Anderson "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +proc-macro = true + +[dependencies] + +syn = "1.0" +quote = "1.0" + +[dev-dependencies] \ No newline at end of file diff --git a/bevy_derive/src/lib.rs b/bevy_derive/src/lib.rs new file mode 100644 index 0000000000..449391a318 --- /dev/null +++ b/bevy_derive/src/lib.rs @@ -0,0 +1,25 @@ +use proc_macro::TokenStream; +use syn::{parse_macro_input, DeriveInput, Data, DataStruct, Fields}; +use quote::quote; + +#[proc_macro_derive(EntityArchetype)] +pub fn derive_entity_archetype(input: TokenStream) -> TokenStream { + let ast = parse_macro_input!(input as DeriveInput); + let fields = match &ast.data { + Data::Struct(DataStruct { fields: Fields::Named(fields), .. }) => &fields.named, + _ => panic!("expected a struct with named fields"), + }; + + let struct_name = &ast.ident; + let field_name = fields.iter().map(|field| &field.ident); + + TokenStream::from(quote! { + impl EntityArchetype for #struct_name { + fn insert(self, world: &mut World) -> Entity { + *world.insert((), vec![( + #(self.#field_name),* + )]).first().unwrap() + } + } + }) +} diff --git a/src/transform/.gitignore b/bevy_transform/.gitignore similarity index 100% rename from src/transform/.gitignore rename to bevy_transform/.gitignore diff --git a/src/transform/.travis.yml b/bevy_transform/.travis.yml similarity index 100% rename from src/transform/.travis.yml rename to bevy_transform/.travis.yml diff --git a/src/transform/Cargo.toml b/bevy_transform/Cargo.toml similarity index 87% rename from src/transform/Cargo.toml rename to bevy_transform/Cargo.toml index 3a8b24bdbd..0ccb518bcc 100644 --- a/src/transform/Cargo.toml +++ b/bevy_transform/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "legion_transform" +name = "bevy_transform" version = "0.3.0" authors = ["Alec Thilenius "] edition = "2018" @@ -8,7 +8,6 @@ license = "MIT" [dependencies] legion = { git = "https://github.com/TomGillen/legion.git", rev = "940ef3bfcb77e5d074ee3184b776ff1600da228d" } -#legion = { path = "../legion" } glam = "0.8.3" log = "0.4" rayon = "1.2" diff --git a/src/transform/LICENSE b/bevy_transform/LICENSE similarity index 100% rename from src/transform/LICENSE rename to bevy_transform/LICENSE diff --git a/src/transform/README.md b/bevy_transform/README.md similarity index 100% rename from src/transform/README.md rename to bevy_transform/README.md diff --git a/src/transform/benches/local_to_world.rs b/bevy_transform/benches/local_to_world.rs similarity index 100% rename from src/transform/benches/local_to_world.rs rename to bevy_transform/benches/local_to_world.rs diff --git a/src/transform/examples/hierarchy.rs b/bevy_transform/examples/hierarchy.rs similarity index 100% rename from src/transform/examples/hierarchy.rs rename to bevy_transform/examples/hierarchy.rs diff --git a/src/transform/examples/types_of_transforms.rs b/bevy_transform/examples/types_of_transforms.rs similarity index 100% rename from src/transform/examples/types_of_transforms.rs rename to bevy_transform/examples/types_of_transforms.rs diff --git a/src/transform/src/components/children.rs b/bevy_transform/src/components/children.rs similarity index 100% rename from src/transform/src/components/children.rs rename to bevy_transform/src/components/children.rs diff --git a/src/transform/src/components/local_to_parent.rs b/bevy_transform/src/components/local_to_parent.rs similarity index 100% rename from src/transform/src/components/local_to_parent.rs rename to bevy_transform/src/components/local_to_parent.rs diff --git a/src/transform/src/components/local_to_world.rs b/bevy_transform/src/components/local_to_world.rs similarity index 100% rename from src/transform/src/components/local_to_world.rs rename to bevy_transform/src/components/local_to_world.rs diff --git a/src/transform/src/components/mod.rs b/bevy_transform/src/components/mod.rs similarity index 100% rename from src/transform/src/components/mod.rs rename to bevy_transform/src/components/mod.rs diff --git a/src/transform/src/components/non_uniform_scale.rs b/bevy_transform/src/components/non_uniform_scale.rs similarity index 100% rename from src/transform/src/components/non_uniform_scale.rs rename to bevy_transform/src/components/non_uniform_scale.rs diff --git a/src/transform/src/components/parent.rs b/bevy_transform/src/components/parent.rs similarity index 100% rename from src/transform/src/components/parent.rs rename to bevy_transform/src/components/parent.rs diff --git a/src/transform/src/components/rotation.rs b/bevy_transform/src/components/rotation.rs similarity index 100% rename from src/transform/src/components/rotation.rs rename to bevy_transform/src/components/rotation.rs diff --git a/src/transform/src/components/scale.rs b/bevy_transform/src/components/scale.rs similarity index 100% rename from src/transform/src/components/scale.rs rename to bevy_transform/src/components/scale.rs diff --git a/src/transform/src/components/translation.rs b/bevy_transform/src/components/translation.rs similarity index 100% rename from src/transform/src/components/translation.rs rename to bevy_transform/src/components/translation.rs diff --git a/src/transform/src/hierarchy_maintenance_system.rs b/bevy_transform/src/hierarchy_maintenance_system.rs similarity index 100% rename from src/transform/src/hierarchy_maintenance_system.rs rename to bevy_transform/src/hierarchy_maintenance_system.rs diff --git a/src/transform/src/lib.rs b/bevy_transform/src/lib.rs similarity index 100% rename from src/transform/src/lib.rs rename to bevy_transform/src/lib.rs diff --git a/src/transform/src/local_to_parent_system.rs b/bevy_transform/src/local_to_parent_system.rs similarity index 100% rename from src/transform/src/local_to_parent_system.rs rename to bevy_transform/src/local_to_parent_system.rs diff --git a/src/transform/src/local_to_world_propagate_system.rs b/bevy_transform/src/local_to_world_propagate_system.rs similarity index 100% rename from src/transform/src/local_to_world_propagate_system.rs rename to bevy_transform/src/local_to_world_propagate_system.rs diff --git a/src/transform/src/local_to_world_system.rs b/bevy_transform/src/local_to_world_system.rs similarity index 100% rename from src/transform/src/local_to_world_system.rs rename to bevy_transform/src/local_to_world_system.rs diff --git a/src/transform/src/transform_system_bundle.rs b/bevy_transform/src/transform_system_bundle.rs similarity index 100% rename from src/transform/src/transform_system_bundle.rs rename to bevy_transform/src/transform_system_bundle.rs diff --git a/examples/entity_builder_comparison.rs b/examples/entity_builder_comparison.rs index 4f72282be9..dd58774eb0 100644 --- a/examples/entity_builder_comparison.rs +++ b/examples/entity_builder_comparison.rs @@ -1,5 +1,4 @@ use bevy::prelude::*; -use bevy::ecs::*; fn main() { AppBuilder::new().add_defaults().setup_world(setup).run(); diff --git a/src/app/app_builder.rs b/src/app/app_builder.rs index 428158e665..e0d17759f1 100644 --- a/src/app/app_builder.rs +++ b/src/app/app_builder.rs @@ -3,11 +3,11 @@ use crate::{ asset::*, core::Time, legion::prelude::{Runnable, Schedulable, Schedule, Universe, World}, - legion_transform::transform_system_bundle, render::{passes::*, *}, ui, }; +use bevy_transform::transform_system_bundle; use std::collections::HashMap; pub const UPDATE: &str = "update"; diff --git a/src/ecs/archetypes.rs b/src/ecs/archetypes.rs deleted file mode 100644 index f0ac386e1c..0000000000 --- a/src/ecs/archetypes.rs +++ /dev/null @@ -1,70 +0,0 @@ -use crate::prelude::*; -use legion::prelude::*; - - -// builder macro that makes defaults easy? Object3dBuilder { Option } impl Builder for Object3dBuilder { } -pub trait EntityArchetype { - fn insert(self, world: &mut World) -> Entity; - - // this would make composing entities from multiple archetypes possible - // add_components appears to be missing from World. it will be less efficient without that - // fn add_components(self, world: &mut World); - - // generate by macro. maybe a separate macro? - // fn query() -> Query -} - -pub struct Object3dEntity { - pub mesh: Handle, - pub material: Material, - pub local_to_world: LocalToWorld, - pub translation: Translation, -} - -// TODO: make this a macro -impl EntityArchetype for Object3dEntity { - fn insert(self, world: &mut World) -> Entity { - *world.insert((), vec![( - self.mesh, - self.material, - self.local_to_world, - self.translation, - )]).first().unwrap() - } -} - -pub struct LightEntity { - pub light: Light, - pub local_to_world: LocalToWorld, - pub translation: Translation, - pub rotation: Rotation, -} - -// TODO: make this a macro -impl EntityArchetype for LightEntity { - fn insert(self, world: &mut World) -> Entity { - *world.insert((), vec![( - self.light, - self.local_to_world, - self.translation, - self.rotation, - )]).first().unwrap() - } -} - -pub struct CameraEntity { - pub camera: Camera, - pub active_camera: ActiveCamera, - pub local_to_world: LocalToWorld, -} - -// TODO: make this a macro -impl EntityArchetype for CameraEntity { - fn insert(self, world: &mut World) -> Entity { - *world.insert((), vec![( - self.camera, - self.active_camera, - self.local_to_world, - )]).first().unwrap() - } -} \ No newline at end of file diff --git a/src/ecs/default_archetypes.rs b/src/ecs/default_archetypes.rs new file mode 100644 index 0000000000..d780b00e59 --- /dev/null +++ b/src/ecs/default_archetypes.rs @@ -0,0 +1,25 @@ +use crate::prelude::*; +use bevy_derive::EntityArchetype; + +#[derive(EntityArchetype)] +pub struct Object3dEntity { + pub mesh: Handle, + pub material: Material, + pub local_to_world: LocalToWorld, + pub translation: Translation, +} + +#[derive(EntityArchetype)] +pub struct LightEntity { + pub light: Light, + pub local_to_world: LocalToWorld, + pub translation: Translation, + pub rotation: Rotation, +} + +#[derive(EntityArchetype)] +pub struct CameraEntity { + pub camera: Camera, + pub active_camera: ActiveCamera, + pub local_to_world: LocalToWorld, +} \ No newline at end of file diff --git a/src/ecs/entity_archetype.rs b/src/ecs/entity_archetype.rs new file mode 100644 index 0000000000..dd2485f357 --- /dev/null +++ b/src/ecs/entity_archetype.rs @@ -0,0 +1,13 @@ +use legion::prelude::*; + +// builder macro that makes defaults easy? Object3dBuilder { Option } impl Builder for Object3dBuilder { } +pub trait EntityArchetype { + fn insert(self, world: &mut World) -> Entity; + + // this would make composing entities from multiple archetypes possible + // add_components appears to be missing from World. it will be less efficient without that + // fn add_components(self, world: &mut World); + + // generate by macro. maybe a separate macro? + // fn query() -> Query +} \ No newline at end of file diff --git a/src/ecs/mod.rs b/src/ecs/mod.rs index 69fb1d5dda..76931a9c9b 100644 --- a/src/ecs/mod.rs +++ b/src/ecs/mod.rs @@ -1,10 +1,12 @@ mod entity_builder; -mod archetypes; +mod entity_archetype; +pub mod default_archetypes; pub use entity_builder::*; -pub use archetypes::*; +pub use entity_archetype::*; -use crate::prelude::{Children, Entity, SubWorld, World}; +use legion::{prelude::{Entity, World}, system::SubWorld}; +use bevy_transform::prelude::Children; pub fn run_on_hierarchy( world: &World, diff --git a/src/lib.rs b/src/lib.rs index 2be241439d..5e6443f2f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ pub mod app; pub mod asset; -pub mod core; pub mod ecs; +pub mod core; pub mod prelude; pub mod render; pub mod serialization; @@ -9,5 +9,5 @@ pub mod ui; pub use glam as math; pub use legion; -pub use legion_transform; -pub use wgpu; +pub use bevy_transform as transform; +pub use wgpu; \ No newline at end of file diff --git a/src/prelude.rs b/src/prelude.rs index cc72e992a0..894c406936 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -3,6 +3,8 @@ pub use crate::{ asset::{Asset, AssetStorage, Handle, Mesh, MeshType, Texture, TextureType}, core::Time, ecs, + ecs::{EntityArchetype, EntityBuilder, EntityBuilderSource}, + ecs::default_archetypes::*, render::{ ActiveCamera, ActiveCamera2d, Albedo, Camera, CameraType, Instanced, Light, Material, }, @@ -15,5 +17,5 @@ pub use legion::{ system::SubWorld, system::SystemBuilder, }; -pub use legion_transform::prelude::*; +pub use bevy_transform::prelude::*; pub use math::{Mat3, Mat4, Quat, Vec2, Vec3, Vec4};