register bevy_transform and bevy_render components

This commit is contained in:
Carter Anderson 2020-05-25 18:49:29 -07:00
parent cb3d60a87f
commit c8d55fe030
11 changed files with 40 additions and 12 deletions

View file

@ -6,6 +6,7 @@ edition = "2018"
[dependencies] [dependencies]
bevy_app = { path = "../bevy_app" } bevy_app = { path = "../bevy_app" }
bevy_component_registry = { path = "../bevy_component_registry" }
bevy_transform = { path = "../bevy_transform" } bevy_transform = { path = "../bevy_transform" }
legion = { path = "../bevy_legion" } legion = { path = "../bevy_legion" }
glam = { path = "../bevy_glam" } glam = { path = "../bevy_glam" }

View file

@ -3,7 +3,8 @@ pub mod time;
pub mod transform; pub mod transform;
use bevy_app::{stage, AppBuilder, AppPlugin}; use bevy_app::{stage, AppBuilder, AppPlugin};
use bevy_transform::transform_system_bundle; use bevy_component_registry::RegisterComponent;
use bevy_transform::{transform_system_bundle, components::{Children, LocalToParent, LocalToWorld, Translation, Rotation, Scale, NonUniformScale}};
use legion::prelude::IntoSystem; use legion::prelude::IntoSystem;
use time::{start_timer_system, stop_timer_system, Time}; use time::{start_timer_system, stop_timer_system, Time};
@ -17,6 +18,13 @@ impl AppPlugin for CorePlugin {
} }
app.init_resource::<Time>() app.init_resource::<Time>()
.register_component::<Children>()
.register_component::<LocalToParent>()
.register_component::<LocalToWorld>()
.register_component::<Translation>()
.register_component::<Rotation>()
.register_component::<Scale>()
.register_component::<NonUniformScale>()
.add_system_to_stage(stage::FIRST, start_timer_system.system()) .add_system_to_stage(stage::FIRST, start_timer_system.system())
.add_system_to_stage(stage::LAST, stop_timer_system.system()); .add_system_to_stage(stage::LAST, stop_timer_system.system());
} }

View file

@ -6,7 +6,7 @@ use darling::FromMeta;
use modules::{get_modules, get_path}; use modules::{get_modules, get_path};
use proc_macro::TokenStream; use proc_macro::TokenStream;
use quote::quote; use quote::quote;
use syn::{parse_macro_input, Data, DataStruct, DeriveInput, Field, Fields, Index, Member}; use syn::{parse_macro_input, Data, DataStruct, DeriveInput, Field, Fields, Index, Member, punctuated::Punctuated};
#[derive(FromMeta, Debug, Default)] #[derive(FromMeta, Debug, Default)]
struct PropAttributeArgs { struct PropAttributeArgs {
@ -19,6 +19,7 @@ static PROP_ATTRIBUTE_NAME: &str = "prop";
#[proc_macro_derive(Properties, attributes(prop, module))] #[proc_macro_derive(Properties, attributes(prop, module))]
pub fn derive_properties(input: TokenStream) -> TokenStream { pub fn derive_properties(input: TokenStream) -> TokenStream {
let ast = parse_macro_input!(input as DeriveInput); let ast = parse_macro_input!(input as DeriveInput);
let unit_struct_punctuated = Punctuated::new();
let fields = match &ast.data { let fields = match &ast.data {
Data::Struct(DataStruct { Data::Struct(DataStruct {
fields: Fields::Named(fields), fields: Fields::Named(fields),
@ -28,6 +29,10 @@ pub fn derive_properties(input: TokenStream) -> TokenStream {
fields: Fields::Unnamed(fields), fields: Fields::Unnamed(fields),
.. ..
}) => &fields.unnamed, }) => &fields.unnamed,
Data::Struct(DataStruct {
fields: Fields::Unit,
..
}) => &unit_struct_punctuated,
_ => panic!("expected a struct with named fields"), _ => panic!("expected a struct with named fields"),
}; };
let fields_and_args = fields let fields_and_args = fields

View file

@ -5,10 +5,10 @@ use glam::Mat4;
use legion::prelude::*; use legion::prelude::*;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
#[derive(Default)] #[derive(Default, Properties)]
pub struct ActiveCamera; pub struct ActiveCamera;
#[derive(Default)] #[derive(Default, Properties)]
pub struct ActiveCamera2d; pub struct ActiveCamera2d;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]

View file

@ -75,6 +75,9 @@ impl AppPlugin for RenderPlugin {
.add_asset::<PipelineDescriptor>() .add_asset::<PipelineDescriptor>()
.add_asset_loader::<Texture, PngTextureLoader>() .add_asset_loader::<Texture, PngTextureLoader>()
.register_component::<Camera>() .register_component::<Camera>()
.register_component::<Renderable>()
.register_component::<ActiveCamera>()
.register_component::<ActiveCamera2d>()
.init_resource::<RenderGraph>() .init_resource::<RenderGraph>()
.init_resource::<PipelineAssignments>() .init_resource::<PipelineAssignments>()
.init_resource::<PipelineCompiler>() .init_resource::<PipelineCompiler>()

View file

@ -1,8 +1,9 @@
use crate::math::Vec3; use crate::math::Vec3;
use shrinkwraprs::Shrinkwrap; use shrinkwraprs::Shrinkwrap;
use std::fmt; use std::fmt;
use bevy_property::Properties;
#[derive(Shrinkwrap, Debug, PartialEq, Clone, Copy)] #[derive(Shrinkwrap, Debug, PartialEq, Clone, Copy, Properties)]
#[shrinkwrap(mutable)] #[shrinkwrap(mutable)]
pub struct NonUniformScale(pub Vec3); pub struct NonUniformScale(pub Vec3);
@ -12,6 +13,12 @@ impl NonUniformScale {
} }
} }
impl Default for NonUniformScale {
fn default() -> Self {
NonUniformScale(Vec3::new(1.0, 1.0, 1.0))
}
}
impl From<Vec3> for NonUniformScale { impl From<Vec3> for NonUniformScale {
fn from(scale: Vec3) -> Self { fn from(scale: Vec3) -> Self {
Self(scale) Self(scale)

View file

@ -1,7 +1,8 @@
use crate::ecs::prelude::*; use crate::ecs::prelude::*;
use shrinkwraprs::Shrinkwrap; use shrinkwraprs::Shrinkwrap;
use bevy_property::Properties;
#[derive(Shrinkwrap, Debug, Copy, Clone, Eq, PartialEq)] #[derive(Shrinkwrap, Debug, Copy, Clone, Eq, PartialEq, Properties)]
#[shrinkwrap(mutable)] #[shrinkwrap(mutable)]
pub struct Parent(pub Entity); pub struct Parent(pub Entity);

View file

@ -1,7 +1,8 @@
use crate::math::Quat; use crate::math::Quat;
use shrinkwraprs::Shrinkwrap; use shrinkwraprs::Shrinkwrap;
use bevy_property::Properties;
#[derive(Shrinkwrap, Debug, PartialEq, Clone, Copy)] #[derive(Shrinkwrap, Debug, PartialEq, Clone, Copy, Properties)]
#[shrinkwrap(mutable)] #[shrinkwrap(mutable)]
pub struct Rotation(pub Quat); pub struct Rotation(pub Quat);
impl Rotation { impl Rotation {

View file

@ -1,7 +1,8 @@
use shrinkwraprs::Shrinkwrap; use shrinkwraprs::Shrinkwrap;
use std::fmt; use std::fmt;
use bevy_property::Properties;
#[derive(Shrinkwrap, Debug, PartialEq, Clone, Copy)] #[derive(Shrinkwrap, Debug, PartialEq, Clone, Copy, Properties)]
#[shrinkwrap(mutable)] #[shrinkwrap(mutable)]
pub struct Scale(pub f32); pub struct Scale(pub f32);

View file

@ -1,7 +1,8 @@
use crate::math::Vec3; use crate::math::Vec3;
use shrinkwraprs::Shrinkwrap; use shrinkwraprs::Shrinkwrap;
use bevy_property::Properties;
#[derive(Shrinkwrap, Debug, PartialEq, Clone, Copy)] #[derive(Shrinkwrap, Debug, PartialEq, Clone, Copy, Properties)]
#[shrinkwrap(mutable)] #[shrinkwrap(mutable)]
pub struct Translation(pub Vec3); pub struct Translation(pub Vec3);

View file

@ -6,15 +6,15 @@ pub trait AddDefaultPlugins {
impl AddDefaultPlugins for AppBuilder { impl AddDefaultPlugins for AppBuilder {
fn add_default_plugins(&mut self) -> &mut Self { fn add_default_plugins(&mut self) -> &mut Self {
#[cfg(feature = "component_registry")]
self.add_plugin(bevy_component_registry::ComponentRegistryPlugin::default());
#[cfg(feature = "core")] #[cfg(feature = "core")]
self.add_plugin(bevy_core::CorePlugin::default()); self.add_plugin(bevy_core::CorePlugin::default());
#[cfg(feature = "diagnostic")] #[cfg(feature = "diagnostic")]
self.add_plugin(bevy_diagnostic::DiagnosticsPlugin::default()); self.add_plugin(bevy_diagnostic::DiagnosticsPlugin::default());
#[cfg(feature = "scene")]
self.add_plugin(bevy_component_registry::ComponentRegistryPlugin::default());
#[cfg(feature = "input")] #[cfg(feature = "input")]
self.add_plugin(bevy_input::InputPlugin::default()); self.add_plugin(bevy_input::InputPlugin::default());