diff --git a/bevy_derive/src/lib.rs b/bevy_derive/src/lib.rs index 672ecc8b72..dc5ee617ed 100644 --- a/bevy_derive/src/lib.rs +++ b/bevy_derive/src/lib.rs @@ -21,8 +21,8 @@ pub fn derive_entity_archetype(input: TokenStream) -> TokenStream { let field_name = fields.iter().map(|field| &field.ident); TokenStream::from(quote! { - impl EntityArchetype for #struct_name { - fn insert(self, world: &mut World) -> Entity { + impl bevy::prelude::EntityArchetype for #struct_name { + fn insert(self, world: &mut bevy::prelude::World) -> Entity { *world.insert((), vec![( #(self.#field_name,)* )]).first().unwrap() @@ -115,10 +115,10 @@ pub fn derive_uniforms(input: TokenStream) -> TokenStream { (0..active_uniform_fields.len()).map(|i| quote!(&#info_ident[#i])); TokenStream::from(quote! { - const #info_ident: &[UniformInfo] = &[ - #(UniformInfo { + const #info_ident: &[bevy::render::render_graph::UniformInfo] = &[ + #(bevy::render::render_graph::UniformInfo { name: #uniform_name_uniform_info, - bind_type: BindType::Uniform { + bind_type: bevy::render::render_graph::BindType::Uniform { dynamic: false, // TODO: fill this in with properties properties: Vec::new(), @@ -126,26 +126,27 @@ pub fn derive_uniforms(input: TokenStream) -> TokenStream { },)* ]; - const #layout_ident: &[&[UniformPropertyType]] = &[ + const #layout_ident: &[&[bevy::render::render_graph::UniformPropertyType]] = &[ #(#layout_arrays,)* ]; - impl AsUniforms for #struct_name { - fn get_uniform_infos(&self) -> &[UniformInfo] { + impl bevy::render::render_graph::AsUniforms for #struct_name { + fn get_uniform_infos(&self) -> &[bevy::render::render_graph::UniformInfo] { #info_ident } - fn get_uniform_layouts(&self) -> &[&[UniformPropertyType]] { + fn get_uniform_layouts(&self) -> &[&[bevy::render::render_graph::UniformPropertyType]] { #layout_ident } fn get_uniform_bytes(&self, name: &str) -> Option> { + use bevy::core::bytes::GetBytes; match name { #(#get_uniform_bytes_uniform_name => Some(self.#get_uniform_bytes_field_name.get_bytes()),)* _ => None, } } - fn get_uniform_info(&self, name: &str) -> Option<&UniformInfo> { + fn get_uniform_info(&self, name: &str) -> Option<&bevy::render::render_graph::UniformInfo> { match name { #(#get_uniform_info_uniform_name => Some(#get_uniform_info_array_refs),)* _ => None, @@ -175,7 +176,7 @@ pub fn derive_app_plugin(input: TokenStream) -> TokenStream { TokenStream::from(quote! { #[no_mangle] - pub extern "C" fn _create_plugin() -> *mut AppPlugin { + pub extern "C" fn _create_plugin() -> *mut bevy::plugin::AppPlugin { // TODO: without this the assembly does nothing. why is that the case? print!(""); // make sure the constructor is the correct type. diff --git a/examples/custom_shader.rs b/examples/custom_shader.rs index 8c97c83a5e..b88fc52396 100644 --- a/examples/custom_shader.rs +++ b/examples/custom_shader.rs @@ -1,14 +1,14 @@ use bevy::{ prelude::*, render::{ - render_graph::{PipelineDescriptor, resource_name}, + render_graph::{PipelineDescriptor, resource_name, resource_providers::UniformResourceProvider}, Shader, ShaderStage, Vertex, }, }; use bevy_derive::Uniforms; -// #[derive(Uniforms)] +#[derive(Uniforms)] struct MyMaterial { pub color: Vec4 } @@ -19,7 +19,7 @@ fn main() { .setup_world(setup) .setup_render_graph(|builder, pipeline_storage, shader_storage| { builder - // .add_resource_provider(UniformResourceProvider::::new()) + .add_resource_provider(Box::new(UniformResourceProvider::::new())) .add_pipeline_to_pass( resource_name::pass::MAIN, pipeline_storage, diff --git a/examples/plugin_loading/example_plugin/src/lib.rs b/examples/plugin_loading/example_plugin/src/lib.rs index 4df9d2d3f4..f1bcff70c6 100644 --- a/examples/plugin_loading/example_plugin/src/lib.rs +++ b/examples/plugin_loading/example_plugin/src/lib.rs @@ -1,5 +1,4 @@ use bevy::prelude::*; -use bevy::plugin::AppPlugin; use bevy_derive::RegisterAppPlugin; #[derive(RegisterAppPlugin)] diff --git a/src/core/bytes.rs b/src/core/bytes.rs new file mode 100644 index 0000000000..b3d041624f --- /dev/null +++ b/src/core/bytes.rs @@ -0,0 +1,29 @@ +use zerocopy::AsBytes; +use crate::math::Vec4; + +pub trait GetBytes { + fn get_bytes(&self) -> Vec; + fn get_bytes_ref(&self) -> Option<&[u8]>; +} + +// TODO: might need to add zerocopy to this crate to impl AsBytes for external crates +// impl GetBytes for T where T : AsBytes { +// fn get_bytes(&self) -> Vec { +// self.as_bytes().into() +// } + +// fn get_bytes_ref(&self) -> Option<&[u8]> { +// Some(self.as_bytes()) +// } +// } + +impl GetBytes for Vec4 { + fn get_bytes(&self) -> Vec { + let vec4_array: [f32; 4] = (*self).into(); + vec4_array.as_bytes().into() + } + + fn get_bytes_ref(&self) -> Option<&[u8]> { + None + } +} diff --git a/src/core/mod.rs b/src/core/mod.rs index b7af057908..0c106616fb 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -1,2 +1,5 @@ -mod time; +pub mod time; +pub mod bytes; + pub use time::Time; +pub use bytes::GetBytes; diff --git a/src/ecs/default_archetypes.rs b/src/ecs/default_archetypes.rs index 22e6aaa3b7..d9d46833cb 100644 --- a/src/ecs/default_archetypes.rs +++ b/src/ecs/default_archetypes.rs @@ -2,6 +2,8 @@ use crate::{ prelude::*, render::render_graph::{Renderable, StandardMaterial}, }; + +use crate as bevy; // for macro imports use bevy_derive::EntityArchetype; #[derive(EntityArchetype, Default)] diff --git a/src/render/render_graph/uniform.rs b/src/render/render_graph/uniform.rs index 78539065c3..8e4208b53d 100644 --- a/src/render/render_graph/uniform.rs +++ b/src/render/render_graph/uniform.rs @@ -1,37 +1,8 @@ use crate::{ - math::Vec4, render::render_graph::{BindType, UniformPropertyType}, }; use legion::prelude::Entity; use std::collections::HashMap; -use zerocopy::AsBytes; - -pub trait GetBytes { - fn get_bytes(&self) -> Vec; - fn get_bytes_ref(&self) -> Option<&[u8]>; -} - -// TODO: might need to add zerocopy to this crate to impl AsBytes for external crates -// impl GetBytes for T where T : AsBytes { -// fn get_bytes(&self) -> Vec { -// self.as_bytes().into() -// } - -// fn get_bytes_ref(&self) -> Option<&[u8]> { -// Some(self.as_bytes()) -// } -// } - -impl GetBytes for Vec4 { - fn get_bytes(&self) -> Vec { - let vec4_array: [f32; 4] = (*self).into(); - vec4_array.as_bytes().into() - } - - fn get_bytes_ref(&self) -> Option<&[u8]> { - None - } -} // TODO: add ability to specify specific pipeline for uniforms pub trait AsUniforms { diff --git a/src/render/render_graph/uniforms/standard_material.rs b/src/render/render_graph/uniforms/standard_material.rs index 9a03d43cee..3ee65b3e50 100644 --- a/src/render/render_graph/uniforms/standard_material.rs +++ b/src/render/render_graph/uniforms/standard_material.rs @@ -1,12 +1,6 @@ -use crate::{ - math, - math::Vec4, - render::render_graph::{ - uniform::{AsUniforms, GetBytes, UniformInfo}, - BindType, ShaderDefSuffixProvider, UniformPropertyType, - }, -}; +use crate::{math, math::Vec4, render::render_graph::ShaderDefSuffixProvider}; +use crate as bevy; // for macro imports use bevy_derive::Uniforms; #[derive(Uniforms)]