cargo fmt
This commit is contained in:
		
							parent
							
								
									68676bf6fa
								
							
						
					
					
						commit
						7037c8c494
					
				@ -205,7 +205,9 @@ fn create_person(world: &mut World, mesh_handle: Handle<Mesh>, translation: Tran
 | 
			
		||||
                value: math::vec3(0.0, 0.0, 0.0),
 | 
			
		||||
            },
 | 
			
		||||
            Instanced,
 | 
			
		||||
            Material::new(Albedo::Color(math::vec4(0.5, 0.3, 0.3, 1.0) * random::<f32>())),
 | 
			
		||||
            Material::new(Albedo::Color(
 | 
			
		||||
                math::vec4(0.5, 0.3, 0.3, 1.0) * random::<f32>(),
 | 
			
		||||
            )),
 | 
			
		||||
            mesh_handle,
 | 
			
		||||
            LocalToWorld::identity(),
 | 
			
		||||
            translation,
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
use bevy::{prelude::*, asset};
 | 
			
		||||
use bevy::{asset, prelude::*};
 | 
			
		||||
 | 
			
		||||
fn main() {
 | 
			
		||||
    asset::load_gltf("examples/assets/Box.gltf").unwrap();
 | 
			
		||||
 | 
			
		||||
@ -1,12 +1,10 @@
 | 
			
		||||
use bevy::{prelude::*, serialization::*};
 | 
			
		||||
use serde::{Serialize, Deserialize};
 | 
			
		||||
use serde::{Deserialize, Serialize};
 | 
			
		||||
use type_uuid::TypeUuid;
 | 
			
		||||
fn main() {
 | 
			
		||||
    let app = AppBuilder::new().add_defaults().setup_world(setup).build();
 | 
			
		||||
 | 
			
		||||
    let comp_registrations = [
 | 
			
		||||
        ComponentRegistration::of::<Test>(),
 | 
			
		||||
    ];
 | 
			
		||||
    let comp_registrations = [ComponentRegistration::of::<Test>()];
 | 
			
		||||
 | 
			
		||||
    let tag_registrations = [];
 | 
			
		||||
 | 
			
		||||
@ -14,12 +12,20 @@ fn main() {
 | 
			
		||||
    let serializable = legion::ser::serializable_world(&app.world, &ser_helper);
 | 
			
		||||
    let serialized_data = serde_json::to_string(&serializable).unwrap();
 | 
			
		||||
    println!("{}", serialized_data);
 | 
			
		||||
    let de_helper = DeserializeImpl::new(ser_helper.comp_types, ser_helper.tag_types, ser_helper.entity_map);
 | 
			
		||||
    let de_helper = DeserializeImpl::new(
 | 
			
		||||
        ser_helper.comp_types,
 | 
			
		||||
        ser_helper.tag_types,
 | 
			
		||||
        ser_helper.entity_map,
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    let mut new_world = app.universe.create_world();
 | 
			
		||||
    let mut deserializer = serde_json::Deserializer::from_str(&serialized_data);
 | 
			
		||||
    legion::de::deserialize(&mut new_world, &de_helper, &mut deserializer).unwrap();
 | 
			
		||||
    let ser_helper = SerializeImpl::new_with_map(&comp_registrations, &tag_registrations, de_helper.entity_map.into_inner());
 | 
			
		||||
    let ser_helper = SerializeImpl::new_with_map(
 | 
			
		||||
        &comp_registrations,
 | 
			
		||||
        &tag_registrations,
 | 
			
		||||
        de_helper.entity_map.into_inner(),
 | 
			
		||||
    );
 | 
			
		||||
    let serializable = legion::ser::serializable_world(&new_world, &ser_helper);
 | 
			
		||||
    let roundtrip_data = serde_json::to_string(&serializable).unwrap();
 | 
			
		||||
    println!("{}", roundtrip_data);
 | 
			
		||||
@ -35,10 +41,5 @@ pub struct Test {
 | 
			
		||||
 | 
			
		||||
fn setup(world: &mut World) {
 | 
			
		||||
    // plane
 | 
			
		||||
    world.insert(
 | 
			
		||||
        (),
 | 
			
		||||
        vec![(
 | 
			
		||||
            Test {x: 3.0, y: 4.0},
 | 
			
		||||
        )],
 | 
			
		||||
    );
 | 
			
		||||
    world.insert((), vec![(Test { x: 3.0, y: 4.0 },)]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -6,7 +6,7 @@ use winit::{
 | 
			
		||||
 | 
			
		||||
use legion::prelude::*;
 | 
			
		||||
 | 
			
		||||
use crate::{render::*, core::Time};
 | 
			
		||||
use crate::{core::Time, render::*};
 | 
			
		||||
 | 
			
		||||
pub struct App {
 | 
			
		||||
    pub universe: Universe,
 | 
			
		||||
@ -16,7 +16,12 @@ pub struct App {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl App {
 | 
			
		||||
    pub fn new(universe: Universe, world: World, schedule: Schedule, render_graph: RenderGraph) -> App {
 | 
			
		||||
    pub fn new(
 | 
			
		||||
        universe: Universe,
 | 
			
		||||
        world: World,
 | 
			
		||||
        schedule: Schedule,
 | 
			
		||||
        render_graph: RenderGraph,
 | 
			
		||||
    ) -> App {
 | 
			
		||||
        App {
 | 
			
		||||
            universe,
 | 
			
		||||
            world,
 | 
			
		||||
@ -50,9 +55,7 @@ impl App {
 | 
			
		||||
        self.world.resources.insert(window);
 | 
			
		||||
 | 
			
		||||
        log::info!("Initializing the example...");
 | 
			
		||||
        self.render_graph.initialize(
 | 
			
		||||
            &mut self.world,
 | 
			
		||||
        );
 | 
			
		||||
        self.render_graph.initialize(&mut self.world);
 | 
			
		||||
 | 
			
		||||
        log::info!("Entering render loop...");
 | 
			
		||||
        event_loop.run(move |event, _, control_flow| {
 | 
			
		||||
@ -66,7 +69,8 @@ impl App {
 | 
			
		||||
                    event: WindowEvent::Resized(size),
 | 
			
		||||
                    ..
 | 
			
		||||
                } => {
 | 
			
		||||
                    self.render_graph.resize(size.width, size.height, &mut self.world);
 | 
			
		||||
                    self.render_graph
 | 
			
		||||
                        .resize(size.width, size.height, &mut self.world);
 | 
			
		||||
                }
 | 
			
		||||
                event::Event::WindowEvent { event, .. } => match event {
 | 
			
		||||
                    WindowEvent::KeyboardInput {
 | 
			
		||||
 | 
			
		||||
@ -1,10 +1,11 @@
 | 
			
		||||
use crate::{
 | 
			
		||||
    app::App,
 | 
			
		||||
    asset::*,
 | 
			
		||||
    legion::{
 | 
			
		||||
        prelude::{Schedule, Schedulable, World, Universe, Runnable},
 | 
			
		||||
    },
 | 
			
		||||
    core::Time,
 | 
			
		||||
    legion::prelude::{Runnable, Schedulable, Schedule, Universe, World},
 | 
			
		||||
    legion_transform::transform_system_bundle,
 | 
			
		||||
    render::{passes::*, *},
 | 
			
		||||
    legion_transform::transform_system_bundle, ui, app::App, core::Time,
 | 
			
		||||
    ui,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
use std::collections::HashMap;
 | 
			
		||||
@ -54,7 +55,12 @@ impl AppBuilder {
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        App::new(self.universe, self.world, schedule_builder.build(), self.render_graph)
 | 
			
		||||
        App::new(
 | 
			
		||||
            self.universe,
 | 
			
		||||
            self.world,
 | 
			
		||||
            schedule_builder.build(),
 | 
			
		||||
            self.render_graph,
 | 
			
		||||
        )
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn run(self) {
 | 
			
		||||
@ -77,7 +83,8 @@ impl AppBuilder {
 | 
			
		||||
 | 
			
		||||
    pub fn add_system_to_stage(mut self, stage_name: &str, system: Box<dyn Schedulable>) -> Self {
 | 
			
		||||
        if let None = self.system_stages.get(stage_name) {
 | 
			
		||||
            self.system_stages.insert(stage_name.to_string(), Vec::new());
 | 
			
		||||
            self.system_stages
 | 
			
		||||
                .insert(stage_name.to_string(), Vec::new());
 | 
			
		||||
            self.stage_order.push(stage_name.to_string());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -89,7 +96,8 @@ impl AppBuilder {
 | 
			
		||||
 | 
			
		||||
    pub fn add_runnable_to_stage(mut self, stage_name: &str, system: Box<dyn Runnable>) -> Self {
 | 
			
		||||
        if let None = self.runnable_stages.get(stage_name) {
 | 
			
		||||
            self.runnable_stages.insert(stage_name.to_string(), Vec::new());
 | 
			
		||||
            self.runnable_stages
 | 
			
		||||
                .insert(stage_name.to_string(), Vec::new());
 | 
			
		||||
            self.stage_order.push(stage_name.to_string());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -111,8 +119,15 @@ impl AppBuilder {
 | 
			
		||||
            .add_render_resource_manager(Box::new(render_resources::Global2dResourceManager));
 | 
			
		||||
 | 
			
		||||
        let depth_format = wgpu::TextureFormat::Depth32Float;
 | 
			
		||||
        render_graph.set_pass("forward", Box::new(ForwardPass::new(depth_format, msaa_samples)));
 | 
			
		||||
        render_graph.set_pipeline("forward", "forward", Box::new(ForwardPipeline::new(msaa_samples)));
 | 
			
		||||
        render_graph.set_pass(
 | 
			
		||||
            "forward",
 | 
			
		||||
            Box::new(ForwardPass::new(depth_format, msaa_samples)),
 | 
			
		||||
        );
 | 
			
		||||
        render_graph.set_pipeline(
 | 
			
		||||
            "forward",
 | 
			
		||||
            "forward",
 | 
			
		||||
            Box::new(ForwardPipeline::new(msaa_samples)),
 | 
			
		||||
        );
 | 
			
		||||
        render_graph.set_pipeline(
 | 
			
		||||
            "forward",
 | 
			
		||||
            "forward_instanced",
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,5 @@
 | 
			
		||||
mod app_builder;
 | 
			
		||||
mod app;
 | 
			
		||||
mod app_builder;
 | 
			
		||||
 | 
			
		||||
pub use app_builder::AppBuilder;
 | 
			
		||||
pub use app::App;
 | 
			
		||||
pub use app_builder::AppBuilder;
 | 
			
		||||
 | 
			
		||||
@ -67,10 +67,26 @@ pub fn create_quad(
 | 
			
		||||
    south_east: Vec2,
 | 
			
		||||
) -> (Vec<Vertex>, Vec<u16>) {
 | 
			
		||||
    let vertex_data = [
 | 
			
		||||
        Vertex::from(([south_west.x(), south_west.y(), 0.0], [0.0, 0.0, 1.0], [0.0, 0.0])),
 | 
			
		||||
        Vertex::from(([north_west.x(), north_west.y(), 0.0], [0.0, 0.0, 1.0], [0.0, 1.0])),
 | 
			
		||||
        Vertex::from(([north_east.x(), north_east.y(), 0.0], [0.0, 0.0, 1.0], [1.0, 1.0])),
 | 
			
		||||
        Vertex::from(([south_east.x(), south_east.y(), 0.0], [0.0, 0.0, 1.0], [1.0, 0.0])),
 | 
			
		||||
        Vertex::from((
 | 
			
		||||
            [south_west.x(), south_west.y(), 0.0],
 | 
			
		||||
            [0.0, 0.0, 1.0],
 | 
			
		||||
            [0.0, 0.0],
 | 
			
		||||
        )),
 | 
			
		||||
        Vertex::from((
 | 
			
		||||
            [north_west.x(), north_west.y(), 0.0],
 | 
			
		||||
            [0.0, 0.0, 1.0],
 | 
			
		||||
            [0.0, 1.0],
 | 
			
		||||
        )),
 | 
			
		||||
        Vertex::from((
 | 
			
		||||
            [north_east.x(), north_east.y(), 0.0],
 | 
			
		||||
            [0.0, 0.0, 1.0],
 | 
			
		||||
            [1.0, 1.0],
 | 
			
		||||
        )),
 | 
			
		||||
        Vertex::from((
 | 
			
		||||
            [south_east.x(), south_east.y(), 0.0],
 | 
			
		||||
            [0.0, 0.0, 1.0],
 | 
			
		||||
            [1.0, 0.0],
 | 
			
		||||
        )),
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    let index_data: &[u16] = &[0, 2, 1, 0, 3, 2];
 | 
			
		||||
 | 
			
		||||
@ -14,16 +14,14 @@ impl Asset<TextureType> for Texture {
 | 
			
		||||
            TextureType::Data(data) => data.clone(),
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        Texture {
 | 
			
		||||
            data: data,
 | 
			
		||||
        }
 | 
			
		||||
        Texture { data: data }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn create_texels(size: usize) -> Vec<u8> {
 | 
			
		||||
    use std::iter;
 | 
			
		||||
 | 
			
		||||
    (0 .. size * size)
 | 
			
		||||
    (0..size * size)
 | 
			
		||||
        .flat_map(|id| {
 | 
			
		||||
            // get high five for recognizing this ;)
 | 
			
		||||
            let cx = 3.0 * (id % size) as f32 / (size - 1) as f32 - 2.0;
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,5 @@
 | 
			
		||||
use crate::prelude::{Children, Entity, World, SubWorld};
 | 
			
		||||
use crate::prelude::{Children, Entity, SubWorld, World};
 | 
			
		||||
 | 
			
		||||
pub fn run_on_hierarchy<T>(
 | 
			
		||||
    world: &mut World,
 | 
			
		||||
    entity: Entity,
 | 
			
		||||
 | 
			
		||||
@ -2,12 +2,12 @@ pub mod app;
 | 
			
		||||
pub mod asset;
 | 
			
		||||
pub mod core;
 | 
			
		||||
pub mod ecs;
 | 
			
		||||
pub mod render;
 | 
			
		||||
pub mod ui;
 | 
			
		||||
pub mod prelude;
 | 
			
		||||
pub mod render;
 | 
			
		||||
pub mod serialization;
 | 
			
		||||
pub mod ui;
 | 
			
		||||
 | 
			
		||||
pub use wgpu;
 | 
			
		||||
pub use glam as math;
 | 
			
		||||
pub use legion;
 | 
			
		||||
pub use legion_transform;
 | 
			
		||||
pub use wgpu;
 | 
			
		||||
 | 
			
		||||
@ -3,8 +3,10 @@ pub use crate::{
 | 
			
		||||
    asset::{Asset, AssetStorage, Handle, Mesh, MeshType, Texture, TextureType},
 | 
			
		||||
    core::Time,
 | 
			
		||||
    ecs,
 | 
			
		||||
    render::{Albedo, Camera, CameraType, ActiveCamera, ActiveCamera2d, Instanced, Light, Material},
 | 
			
		||||
    ui::{Node, Anchors, Margins},
 | 
			
		||||
    render::{
 | 
			
		||||
        ActiveCamera, ActiveCamera2d, Albedo, Camera, CameraType, Instanced, Light, Material,
 | 
			
		||||
    },
 | 
			
		||||
    ui::{Anchors, Margins, Node},
 | 
			
		||||
};
 | 
			
		||||
pub use glam as math;
 | 
			
		||||
pub use legion::{
 | 
			
		||||
@ -14,4 +16,4 @@ pub use legion::{
 | 
			
		||||
    system::SystemBuilder,
 | 
			
		||||
};
 | 
			
		||||
pub use legion_transform::prelude::*;
 | 
			
		||||
pub use math::{Mat3, Mat4, Vec2, Vec3, Vec4, Quat};
 | 
			
		||||
pub use math::{Mat3, Mat4, Quat, Vec2, Vec3, Vec4};
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,7 @@
 | 
			
		||||
use crate::{asset::{Handle, Texture}, math};
 | 
			
		||||
use crate::{
 | 
			
		||||
    asset::{Handle, Texture},
 | 
			
		||||
    math,
 | 
			
		||||
};
 | 
			
		||||
use zerocopy::{AsBytes, FromBytes};
 | 
			
		||||
 | 
			
		||||
pub enum Albedo {
 | 
			
		||||
 | 
			
		||||
@ -86,7 +86,10 @@ impl Pass for ForwardPass {
 | 
			
		||||
                &render_graph.swap_chain_descriptor,
 | 
			
		||||
                self.msaa_samples,
 | 
			
		||||
            );
 | 
			
		||||
            render_graph.set_texture(MULTISAMPLED_FRAMEBUFFER_TEXTURE_NAME, multisampled_framebuffer);
 | 
			
		||||
            render_graph.set_texture(
 | 
			
		||||
                MULTISAMPLED_FRAMEBUFFER_TEXTURE_NAME,
 | 
			
		||||
                multisampled_framebuffer,
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -112,7 +115,9 @@ impl Pass for ForwardPass {
 | 
			
		||||
                },
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            let multisampled_framebuffer = render_graph.get_texture(MULTISAMPLED_FRAMEBUFFER_TEXTURE_NAME).unwrap();
 | 
			
		||||
            let multisampled_framebuffer = render_graph
 | 
			
		||||
                .get_texture(MULTISAMPLED_FRAMEBUFFER_TEXTURE_NAME)
 | 
			
		||||
                .unwrap();
 | 
			
		||||
            wgpu::RenderPassColorAttachmentDescriptor {
 | 
			
		||||
                attachment: multisampled_framebuffer,
 | 
			
		||||
                resolve_target: Some(&frame.view),
 | 
			
		||||
@ -151,7 +156,10 @@ impl Pass for ForwardPass {
 | 
			
		||||
                &render_graph.swap_chain_descriptor,
 | 
			
		||||
                self.msaa_samples,
 | 
			
		||||
            );
 | 
			
		||||
            render_graph.set_texture(MULTISAMPLED_FRAMEBUFFER_TEXTURE_NAME, multisampled_framebuffer);
 | 
			
		||||
            render_graph.set_texture(
 | 
			
		||||
                MULTISAMPLED_FRAMEBUFFER_TEXTURE_NAME,
 | 
			
		||||
                multisampled_framebuffer,
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
use crate::{
 | 
			
		||||
    asset::*,
 | 
			
		||||
    render::{instancing::InstanceBufferInfo, *},
 | 
			
		||||
    prelude::LocalToWorld,
 | 
			
		||||
    render::{instancing::InstanceBufferInfo, *},
 | 
			
		||||
};
 | 
			
		||||
use legion::prelude::*;
 | 
			
		||||
use std::{collections::HashMap, mem};
 | 
			
		||||
 | 
			
		||||
@ -1,9 +1,9 @@
 | 
			
		||||
use crate::{
 | 
			
		||||
    asset::*,
 | 
			
		||||
    ecs, math,
 | 
			
		||||
    prelude::Parent,
 | 
			
		||||
    render::{instancing::InstanceBufferInfo, *},
 | 
			
		||||
    ui::Node,
 | 
			
		||||
    prelude::Parent,
 | 
			
		||||
};
 | 
			
		||||
use legion::prelude::*;
 | 
			
		||||
use wgpu::SwapChainOutput;
 | 
			
		||||
 | 
			
		||||
@ -29,6 +29,7 @@ pub struct RenderGraphData {
 | 
			
		||||
    uniform_buffers: HashMap<String, UniformBuffer>,
 | 
			
		||||
    bind_group_layouts: HashMap<String, wgpu::BindGroupLayout>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl RenderGraphData {
 | 
			
		||||
    pub fn new(
 | 
			
		||||
        device: wgpu::Device,
 | 
			
		||||
@ -152,7 +153,8 @@ impl RenderGraph {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn render(&mut self, world: &mut World) {
 | 
			
		||||
        let frame = self.swap_chain
 | 
			
		||||
        let frame = self
 | 
			
		||||
            .swap_chain
 | 
			
		||||
            .as_mut()
 | 
			
		||||
            .unwrap()
 | 
			
		||||
            .get_next_texture()
 | 
			
		||||
 | 
			
		||||
@ -22,14 +22,9 @@ impl From<([f32; 4], [f32; 4], [f32; 2])> for Vertex {
 | 
			
		||||
impl From<([f32; 3], [f32; 3], [f32; 2])> for Vertex {
 | 
			
		||||
    fn from((position, normal, uv): ([f32; 3], [f32; 3], [f32; 2])) -> Self {
 | 
			
		||||
        Vertex {
 | 
			
		||||
            position: [
 | 
			
		||||
                position[0],
 | 
			
		||||
                position[1],
 | 
			
		||||
                position[2],
 | 
			
		||||
                1.0,
 | 
			
		||||
            ],
 | 
			
		||||
            position: [position[0], position[1], position[2], 1.0],
 | 
			
		||||
            normal: [normal[0], normal[1], normal[2], 0.0],
 | 
			
		||||
            uv: uv
 | 
			
		||||
            uv: uv,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -49,10 +44,7 @@ impl From<([i8; 4], [i8; 4], [i8; 2])> for Vertex {
 | 
			
		||||
                normal[2] as f32,
 | 
			
		||||
                normal[3] as f32,
 | 
			
		||||
            ],
 | 
			
		||||
            uv: [
 | 
			
		||||
                uv[0] as f32,
 | 
			
		||||
                uv[1] as f32,
 | 
			
		||||
            ],
 | 
			
		||||
            uv: [uv[0] as f32, uv[1] as f32],
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user