use full path in macro references

This commit is contained in:
Carter Anderson 2020-02-17 19:53:48 -08:00
parent c96183cf1c
commit 6cf981c610
8 changed files with 52 additions and 53 deletions

View file

@ -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<Vec<u8>> {
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.

View file

@ -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::<MyMaterial>::new())
.add_resource_provider(Box::new(UniformResourceProvider::<MyMaterial>::new()))
.add_pipeline_to_pass(
resource_name::pass::MAIN,
pipeline_storage,

View file

@ -1,5 +1,4 @@
use bevy::prelude::*;
use bevy::plugin::AppPlugin;
use bevy_derive::RegisterAppPlugin;
#[derive(RegisterAppPlugin)]

29
src/core/bytes.rs Normal file
View file

@ -0,0 +1,29 @@
use zerocopy::AsBytes;
use crate::math::Vec4;
pub trait GetBytes {
fn get_bytes(&self) -> Vec<u8>;
fn get_bytes_ref(&self) -> Option<&[u8]>;
}
// TODO: might need to add zerocopy to this crate to impl AsBytes for external crates
// impl<T> GetBytes for T where T : AsBytes {
// fn get_bytes(&self) -> Vec<u8> {
// self.as_bytes().into()
// }
// fn get_bytes_ref(&self) -> Option<&[u8]> {
// Some(self.as_bytes())
// }
// }
impl GetBytes for Vec4 {
fn get_bytes(&self) -> Vec<u8> {
let vec4_array: [f32; 4] = (*self).into();
vec4_array.as_bytes().into()
}
fn get_bytes_ref(&self) -> Option<&[u8]> {
None
}
}

View file

@ -1,2 +1,5 @@
mod time;
pub mod time;
pub mod bytes;
pub use time::Time;
pub use bytes::GetBytes;

View file

@ -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)]

View file

@ -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<u8>;
fn get_bytes_ref(&self) -> Option<&[u8]>;
}
// TODO: might need to add zerocopy to this crate to impl AsBytes for external crates
// impl<T> GetBytes for T where T : AsBytes {
// fn get_bytes(&self) -> Vec<u8> {
// self.as_bytes().into()
// }
// fn get_bytes_ref(&self) -> Option<&[u8]> {
// Some(self.as_bytes())
// }
// }
impl GetBytes for Vec4 {
fn get_bytes(&self) -> Vec<u8> {
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 {

View file

@ -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)]