mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
upgrade legion (breaks plugins)
This commit is contained in:
parent
6055bf677b
commit
9355a53980
35 changed files with 270 additions and 157 deletions
|
@ -6,7 +6,8 @@ edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Modified to use std::any::type_name instead of std::any::TypeId
|
# Modified to use std::any::type_name instead of std::any::TypeId
|
||||||
legion = { path = "bevy_legion", features = ["serde-1"] }
|
# legion = { path = "bevy_legion", features = ["serde-1"] }
|
||||||
|
legion = { git = "https://github.com/TomGillen/legion", rev = "c5b9628630d4f9fc54b6843b5ce02d0669434a61", features = ["serialize"] }
|
||||||
wgpu = { git = "https://github.com/gfx-rs/wgpu-rs.git", rev = "a7b0d5ae5bc0934439ef559ed145e93f0117c39a"}
|
wgpu = { git = "https://github.com/gfx-rs/wgpu-rs.git", rev = "a7b0d5ae5bc0934439ef559ed145e93f0117c39a"}
|
||||||
glam = "0.8.4"
|
glam = "0.8.4"
|
||||||
winit = "0.21.0"
|
winit = "0.21.0"
|
||||||
|
|
|
@ -7,7 +7,8 @@ edition = "2018"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
legion = { path = "../bevy_legion" }
|
# legion = { path = "../bevy_legion" }
|
||||||
|
legion = { git = "https://github.com/TomGillen/legion", rev = "c5b9628630d4f9fc54b6843b5ce02d0669434a61", features = ["serialize"] }
|
||||||
glam = "0.8.3"
|
glam = "0.8.3"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
rayon = "1.2"
|
rayon = "1.2"
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
use crate::{
|
use crate::{components::*, ecs::{prelude::*, systems::SubWorld}};
|
||||||
components::*,
|
|
||||||
ecs::{prelude::*, system::SubWorld},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn build(_: &mut World) -> Box<dyn Schedulable> {
|
pub fn build(_: &mut World) -> Box<dyn Schedulable> {
|
||||||
SystemBuilder::<()>::new("LocalToWorldPropagateSystem")
|
SystemBuilder::<()>::new("LocalToWorldPropagateSystem")
|
||||||
|
@ -59,7 +56,7 @@ mod test {
|
||||||
use crate::{
|
use crate::{
|
||||||
hierarchy_maintenance_system, local_to_parent_system, local_to_world_propagate_system,
|
hierarchy_maintenance_system, local_to_parent_system, local_to_world_propagate_system,
|
||||||
local_to_world_system,
|
local_to_world_system,
|
||||||
math::{Vec3, Mat4}
|
math::{Mat4, Vec3},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -73,9 +73,9 @@ fn main() {
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(world: &mut World) {
|
fn setup(world: &mut World, resources: &mut Resources) {
|
||||||
let cube_handle = {
|
let cube_handle = {
|
||||||
let mut mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||||
mesh_storage.add(Mesh::load(MeshType::Cube))
|
mesh_storage.add(Mesh::load(MeshType::Cube))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -160,12 +160,12 @@ fn create_entities_builder_archetype(
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(world: &mut World) {
|
fn setup(world: &mut World, resources: &mut Resources) {
|
||||||
let cube = Mesh::load(MeshType::Cube);
|
let cube = Mesh::load(MeshType::Cube);
|
||||||
let plane = Mesh::load(MeshType::Plane { size: 10.0 });
|
let plane = Mesh::load(MeshType::Plane { size: 10.0 });
|
||||||
|
|
||||||
let (cube_handle, plane_handle) = {
|
let (cube_handle, plane_handle) = {
|
||||||
let mut mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||||
(mesh_storage.add(cube), mesh_storage.add(plane))
|
(mesh_storage.add(cube), mesh_storage.add(plane))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,10 @@ fn main() {
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(world: &mut World) {
|
fn setup(world: &mut World, resources: &mut Resources) {
|
||||||
let cube = Mesh::load(MeshType::Cube);
|
let cube = Mesh::load(MeshType::Cube);
|
||||||
let cube_handle = {
|
let cube_handle = {
|
||||||
let mut mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||||
mesh_storage.add(cube)
|
mesh_storage.add(cube)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,12 +21,12 @@ fn build_rotator_system() -> Box<dyn Schedulable> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(world: &mut World) {
|
fn setup(world: &mut World, resources: &mut Resources) {
|
||||||
let cube = Mesh::load(MeshType::Cube);
|
let cube = Mesh::load(MeshType::Cube);
|
||||||
let plane = Mesh::load(MeshType::Plane { size: 10.0 });
|
let plane = Mesh::load(MeshType::Plane { size: 10.0 });
|
||||||
|
|
||||||
let (cube_handle, plane_handle) = {
|
let (cube_handle, plane_handle) = {
|
||||||
let mut mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||||
(mesh_storage.add(cube), mesh_storage.add(plane))
|
(mesh_storage.add(cube), mesh_storage.add(plane))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use bevy::prelude::*;
|
use bevy::{prelude::*, plugin::AppPlugin};
|
||||||
use bevy_derive::RegisterAppPlugin;
|
use bevy_derive::RegisterAppPlugin;
|
||||||
|
|
||||||
#[derive(RegisterAppPlugin)]
|
#[derive(RegisterAppPlugin)]
|
||||||
|
@ -14,29 +14,32 @@ impl AppPlugin for ExamplePlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup(world: &mut World) {
|
pub fn setup(world: &mut World, resources: &mut Resources) {
|
||||||
let cube = Mesh::load(MeshType::Cube);
|
let cube = Mesh::load(MeshType::Cube);
|
||||||
let plane = Mesh::load(MeshType::Plane { size: 10.0 });
|
let plane = Mesh::load(MeshType::Plane { size: 10.0 });
|
||||||
|
|
||||||
let (cube_handle, plane_handle) = {
|
let (cube_handle, plane_handle) = {
|
||||||
let mut mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||||
(mesh_storage.add(cube), mesh_storage.add(plane))
|
(mesh_storage.add(cube), mesh_storage.add(plane))
|
||||||
};
|
};
|
||||||
|
|
||||||
world.build()
|
world.build()
|
||||||
// plane
|
// plane
|
||||||
.add_archetype(NewMeshEntity {
|
.add_archetype(MeshEntity {
|
||||||
mesh: plane_handle,
|
mesh: plane_handle,
|
||||||
material: Material::new(Albedo::Color(math::vec4(0.1, 0.2, 0.1, 1.0))),
|
material: StandardMaterial {
|
||||||
local_to_world: LocalToWorld::identity(),
|
albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(),
|
||||||
translation: Translation::new(0.0, 0.0, 0.0),
|
},
|
||||||
|
..Default::default()
|
||||||
})
|
})
|
||||||
// cube
|
// cube
|
||||||
.add_archetype(NewMeshEntity {
|
.add_archetype(MeshEntity {
|
||||||
mesh: cube_handle,
|
mesh: cube_handle,
|
||||||
material: Material::new(Albedo::Color(math::vec4(0.5, 0.3, 0.3, 1.0))),
|
material: StandardMaterial {
|
||||||
local_to_world: LocalToWorld::identity(),
|
albedo: math::vec4(0.5, 0.4, 0.3, 1.0).into(),
|
||||||
|
},
|
||||||
translation: Translation::new(0.0, 0.0, 1.0),
|
translation: Translation::new(0.0, 0.0, 1.0),
|
||||||
|
..Default::default()
|
||||||
})
|
})
|
||||||
// light
|
// light
|
||||||
// .add_archetype(LightEntity {
|
// .add_archetype(LightEntity {
|
||||||
|
|
|
@ -3,6 +3,9 @@ use bevy::prelude::*;
|
||||||
fn main() {
|
fn main() {
|
||||||
AppBuilder::new()
|
AppBuilder::new()
|
||||||
.add_defaults()
|
.add_defaults()
|
||||||
.load_plugin("examples/plugin_loading/example_plugin/target/release/libexample_plugin.so")
|
.load_plugin(concat!(
|
||||||
|
env!("CARGO_MANIFEST_DIR"),
|
||||||
|
"/examples/plugin_loading/example_plugin/target/release/libexample_plugin.so"
|
||||||
|
))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ fn main() {
|
||||||
let tag_registrations = [];
|
let tag_registrations = [];
|
||||||
|
|
||||||
let ser_helper = SerializeImpl::new(&comp_registrations, &tag_registrations);
|
let ser_helper = SerializeImpl::new(&comp_registrations, &tag_registrations);
|
||||||
let serializable = legion::ser::serializable_world(&app.world, &ser_helper);
|
let serializable = legion::serialize::ser::serializable_world(&app.world, &ser_helper);
|
||||||
let serialized_data = serde_json::to_string(&serializable).unwrap();
|
let serialized_data = serde_json::to_string(&serializable).unwrap();
|
||||||
println!("{}", serialized_data);
|
println!("{}", serialized_data);
|
||||||
let de_helper = DeserializeImpl::new(
|
let de_helper = DeserializeImpl::new(
|
||||||
|
@ -20,13 +20,13 @@ fn main() {
|
||||||
|
|
||||||
let mut new_world = app.universe.create_world();
|
let mut new_world = app.universe.create_world();
|
||||||
let mut deserializer = serde_json::Deserializer::from_str(&serialized_data);
|
let mut deserializer = serde_json::Deserializer::from_str(&serialized_data);
|
||||||
legion::de::deserialize(&mut new_world, &de_helper, &mut deserializer).unwrap();
|
legion::serialize::de::deserialize(&mut new_world, &de_helper, &mut deserializer).unwrap();
|
||||||
let ser_helper = SerializeImpl::new_with_map(
|
let ser_helper = SerializeImpl::new_with_map(
|
||||||
&comp_registrations,
|
&comp_registrations,
|
||||||
&tag_registrations,
|
&tag_registrations,
|
||||||
de_helper.entity_map.into_inner(),
|
de_helper.entity_map.into_inner(),
|
||||||
);
|
);
|
||||||
let serializable = legion::ser::serializable_world(&new_world, &ser_helper);
|
let serializable = legion::serialize::ser::serializable_world(&new_world, &ser_helper);
|
||||||
let roundtrip_data = serde_json::to_string(&serializable).unwrap();
|
let roundtrip_data = serde_json::to_string(&serializable).unwrap();
|
||||||
println!("{}", roundtrip_data);
|
println!("{}", roundtrip_data);
|
||||||
assert_eq!(roundtrip_data, serialized_data);
|
assert_eq!(roundtrip_data, serialized_data);
|
||||||
|
@ -39,7 +39,7 @@ pub struct Test {
|
||||||
pub y: f32,
|
pub y: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(world: &mut World) {
|
fn setup(world: &mut World, _resources: &mut Resources) {
|
||||||
// plane
|
// plane
|
||||||
world.insert((), vec![(Test { x: 3.0, y: 4.0 },)]);
|
world.insert((), vec![(Test { x: 3.0, y: 4.0 },)]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,12 @@ fn main() {
|
||||||
AppBuilder::new().add_defaults().setup_world(setup).run();
|
AppBuilder::new().add_defaults().setup_world(setup).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(world: &mut World) {
|
fn setup(world: &mut World, resources: &mut Resources) {
|
||||||
let cube = Mesh::load(MeshType::Cube);
|
let cube = Mesh::load(MeshType::Cube);
|
||||||
let plane = Mesh::load(MeshType::Plane { size: 10.0 });
|
let plane = Mesh::load(MeshType::Plane { size: 10.0 });
|
||||||
|
|
||||||
let (cube_handle, plane_handle) = {
|
let (cube_handle, plane_handle) = {
|
||||||
let mut mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||||
(mesh_storage.add(cube), mesh_storage.add(plane))
|
(mesh_storage.add(cube), mesh_storage.add(plane))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -61,12 +61,12 @@ fn build_print_status_system() -> Box<dyn Schedulable> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(world: &mut World) {
|
fn setup(world: &mut World, resources: &mut Resources) {
|
||||||
let cube = Mesh::load(MeshType::Cube);
|
let cube = Mesh::load(MeshType::Cube);
|
||||||
let plane = Mesh::load(MeshType::Plane { size: 10.0 });
|
let plane = Mesh::load(MeshType::Plane { size: 10.0 });
|
||||||
|
|
||||||
let (cube_handle, plane_handle) = {
|
let (cube_handle, plane_handle) = {
|
||||||
let mut mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||||
(mesh_storage.add(cube), mesh_storage.add(plane))
|
(mesh_storage.add(cube), mesh_storage.add(plane))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,14 +4,14 @@ fn main() {
|
||||||
AppBuilder::new().add_defaults().setup_world(setup).run();
|
AppBuilder::new().add_defaults().setup_world(setup).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(world: &mut World) {
|
fn setup(world: &mut World, resources: &mut Resources) {
|
||||||
let cube_handle = {
|
let cube_handle = {
|
||||||
let mut mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||||
mesh_storage.add(Mesh::load(MeshType::Cube))
|
mesh_storage.add(Mesh::load(MeshType::Cube))
|
||||||
};
|
};
|
||||||
|
|
||||||
let texture_handle = {
|
let texture_handle = {
|
||||||
let mut texture_storage = world.resources.get_mut::<AssetStorage<Texture>>().unwrap();
|
let mut texture_storage = resources.get_mut::<AssetStorage<Texture>>().unwrap();
|
||||||
let texture = Texture::load(TextureType::Png(
|
let texture = Texture::load(TextureType::Png(
|
||||||
concat!(env!("CARGO_MANIFEST_DIR"), "/assets/temp_bevy_logo.png").to_string(),
|
concat!(env!("CARGO_MANIFEST_DIR"), "/assets/temp_bevy_logo.png").to_string(),
|
||||||
));
|
));
|
||||||
|
|
|
@ -4,10 +4,10 @@ fn main() {
|
||||||
AppBuilder::new().add_defaults().setup_world(setup).run();
|
AppBuilder::new().add_defaults().setup_world(setup).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(world: &mut World) {
|
fn setup(world: &mut World, resources: &mut Resources) {
|
||||||
let cube = Mesh::load(MeshType::Cube);
|
let cube = Mesh::load(MeshType::Cube);
|
||||||
let cube_handle = {
|
let cube_handle = {
|
||||||
let mut mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||||
mesh_storage.add(cube)
|
mesh_storage.add(cube)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ use crate::{
|
||||||
pub struct App {
|
pub struct App {
|
||||||
pub universe: Universe,
|
pub universe: Universe,
|
||||||
pub world: World,
|
pub world: World,
|
||||||
|
pub resources: Resources,
|
||||||
pub renderer: Option<Box<dyn Renderer>>,
|
pub renderer: Option<Box<dyn Renderer>>,
|
||||||
pub render_graph: RenderGraph,
|
pub render_graph: RenderGraph,
|
||||||
pub schedule: Schedule,
|
pub schedule: Schedule,
|
||||||
|
@ -25,6 +26,7 @@ impl App {
|
||||||
universe: Universe,
|
universe: Universe,
|
||||||
world: World,
|
world: World,
|
||||||
schedule: Schedule,
|
schedule: Schedule,
|
||||||
|
resources: Resources,
|
||||||
renderer: Option<Box<dyn Renderer>>,
|
renderer: Option<Box<dyn Renderer>>,
|
||||||
render_graph: RenderGraph,
|
render_graph: RenderGraph,
|
||||||
) -> App {
|
) -> App {
|
||||||
|
@ -33,6 +35,7 @@ impl App {
|
||||||
world,
|
world,
|
||||||
schedule,
|
schedule,
|
||||||
renderer,
|
renderer,
|
||||||
|
resources,
|
||||||
render_graph,
|
render_graph,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,16 +45,20 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self) {
|
fn update(&mut self) {
|
||||||
if let Some(mut time) = self.world.resources.get_mut::<Time>() {
|
if let Some(mut time) = self.resources.get_mut::<Time>() {
|
||||||
time.start();
|
time.start();
|
||||||
}
|
}
|
||||||
self.schedule.execute(&mut self.world);
|
self.schedule.execute(&mut self.world, &mut self.resources);
|
||||||
|
|
||||||
if let Some(ref mut renderer) = self.renderer {
|
if let Some(ref mut renderer) = self.renderer {
|
||||||
renderer.process_render_graph(&mut self.render_graph, &mut self.world);
|
renderer.process_render_graph(
|
||||||
|
&mut self.render_graph,
|
||||||
|
&mut self.world,
|
||||||
|
&mut self.resources,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(mut time) = self.world.resources.get_mut::<Time>() {
|
if let Some(mut time) = self.resources.get_mut::<Time>() {
|
||||||
time.stop();
|
time.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,12 +74,12 @@ impl App {
|
||||||
window.set_title("bevy");
|
window.set_title("bevy");
|
||||||
window.set_inner_size(winit::dpi::LogicalSize::new(1280, 720));
|
window.set_inner_size(winit::dpi::LogicalSize::new(1280, 720));
|
||||||
|
|
||||||
self.world.resources.insert(window);
|
self.resources.insert(window);
|
||||||
|
|
||||||
log::info!("Initializing the example...");
|
log::info!("Initializing the example...");
|
||||||
|
|
||||||
if let Some(ref mut renderer) = self.renderer {
|
if let Some(ref mut renderer) = self.renderer {
|
||||||
renderer.initialize(&mut self.world, &mut self.render_graph);
|
renderer.initialize(&mut self.world, &mut self.resources, &mut self.render_graph);
|
||||||
}
|
}
|
||||||
|
|
||||||
log::info!("Entering render loop...");
|
log::info!("Entering render loop...");
|
||||||
|
@ -90,6 +97,7 @@ impl App {
|
||||||
if let Some(ref mut renderer) = self.renderer {
|
if let Some(ref mut renderer) = self.renderer {
|
||||||
renderer.resize(
|
renderer.resize(
|
||||||
&mut self.world,
|
&mut self.world,
|
||||||
|
&mut self.resources,
|
||||||
&mut self.render_graph,
|
&mut self.render_graph,
|
||||||
size.width,
|
size.width,
|
||||||
size.height,
|
size.height,
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::{
|
||||||
app::{system_stage, App},
|
app::{system_stage, App},
|
||||||
asset::*,
|
asset::*,
|
||||||
core::Time,
|
core::Time,
|
||||||
legion::prelude::{Runnable, Schedulable, Schedule, Universe, World},
|
legion::prelude::{Resources, Runnable, Schedulable, Schedule, Universe, World},
|
||||||
plugin::load_plugin,
|
plugin::load_plugin,
|
||||||
render::{
|
render::{
|
||||||
render_graph::{
|
render_graph::{
|
||||||
|
@ -20,6 +20,7 @@ use std::collections::HashMap;
|
||||||
|
|
||||||
pub struct AppBuilder {
|
pub struct AppBuilder {
|
||||||
pub world: World,
|
pub world: World,
|
||||||
|
pub resources: Resources,
|
||||||
pub universe: Universe,
|
pub universe: Universe,
|
||||||
pub renderer: Option<Box<dyn Renderer>>,
|
pub renderer: Option<Box<dyn Renderer>>,
|
||||||
pub render_graph_builder: RenderGraphBuilder,
|
pub render_graph_builder: RenderGraphBuilder,
|
||||||
|
@ -32,9 +33,11 @@ impl AppBuilder {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let universe = Universe::new();
|
let universe = Universe::new();
|
||||||
let world = universe.create_world();
|
let world = universe.create_world();
|
||||||
|
let resources = Resources::default();
|
||||||
AppBuilder {
|
AppBuilder {
|
||||||
universe,
|
universe,
|
||||||
world,
|
world,
|
||||||
|
resources,
|
||||||
render_graph_builder: RenderGraphBuilder::new(),
|
render_graph_builder: RenderGraphBuilder::new(),
|
||||||
renderer: None,
|
renderer: None,
|
||||||
system_stages: HashMap::new(),
|
system_stages: HashMap::new(),
|
||||||
|
@ -67,6 +70,7 @@ impl AppBuilder {
|
||||||
self.universe,
|
self.universe,
|
||||||
self.world,
|
self.world,
|
||||||
schedule_builder.build(),
|
schedule_builder.build(),
|
||||||
|
self.resources,
|
||||||
self.renderer,
|
self.renderer,
|
||||||
self.render_graph_builder.build(),
|
self.render_graph_builder.build(),
|
||||||
)
|
)
|
||||||
|
@ -81,8 +85,8 @@ impl AppBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup_world(mut self, setup: impl Fn(&mut World)) -> Self {
|
pub fn setup_world(mut self, setup: impl Fn(&mut World, &mut Resources)) -> Self {
|
||||||
setup(&mut self.world);
|
setup(&mut self.world, &mut self.resources);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,14 +121,14 @@ impl AppBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_default_resources(mut self) -> Self {
|
pub fn add_default_resources(mut self) -> Self {
|
||||||
let resources = &mut self.world.resources;
|
self.resources.insert(Time::new());
|
||||||
resources.insert(Time::new());
|
self.resources.insert(AssetStorage::<Mesh>::new());
|
||||||
resources.insert(AssetStorage::<Mesh>::new());
|
self.resources.insert(AssetStorage::<Texture>::new());
|
||||||
resources.insert(AssetStorage::<Texture>::new());
|
self.resources.insert(AssetStorage::<Shader>::new());
|
||||||
resources.insert(AssetStorage::<Shader>::new());
|
self.resources
|
||||||
resources.insert(AssetStorage::<PipelineDescriptor>::new());
|
.insert(AssetStorage::<PipelineDescriptor>::new());
|
||||||
resources.insert(ShaderPipelineAssignments::new());
|
self.resources.insert(ShaderPipelineAssignments::new());
|
||||||
resources.insert(CompiledShaderMap::new());
|
self.resources.insert(CompiledShaderMap::new());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,15 +170,10 @@ impl AppBuilder {
|
||||||
) -> Self {
|
) -> Self {
|
||||||
{
|
{
|
||||||
let mut pipeline_storage = self
|
let mut pipeline_storage = self
|
||||||
.world
|
|
||||||
.resources
|
.resources
|
||||||
.get_mut::<AssetStorage<PipelineDescriptor>>()
|
.get_mut::<AssetStorage<PipelineDescriptor>>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut shader_storage = self
|
let mut shader_storage = self.resources.get_mut::<AssetStorage<Shader>>().unwrap();
|
||||||
.world
|
|
||||||
.resources
|
|
||||||
.get_mut::<AssetStorage<Shader>>()
|
|
||||||
.unwrap();
|
|
||||||
self.render_graph_builder = setup(
|
self.render_graph_builder = setup(
|
||||||
self.render_graph_builder,
|
self.render_graph_builder,
|
||||||
&mut pipeline_storage,
|
&mut pipeline_storage,
|
||||||
|
|
|
@ -8,7 +8,7 @@ pub use world_builder::*;
|
||||||
use bevy_transform::prelude::Children;
|
use bevy_transform::prelude::Children;
|
||||||
use legion::{
|
use legion::{
|
||||||
prelude::{Entity, World},
|
prelude::{Entity, World},
|
||||||
system::SubWorld,
|
systems::SubWorld,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn run_on_hierarchy<T>(
|
pub fn run_on_hierarchy<T>(
|
||||||
|
|
|
@ -14,7 +14,9 @@ pub use bevy_transform::prelude::*;
|
||||||
pub use glam as math;
|
pub use glam as math;
|
||||||
pub use legion::{
|
pub use legion::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
|
systems::{
|
||||||
schedule::{Builder, Schedulable},
|
schedule::{Builder, Schedulable},
|
||||||
system::{SubWorld, SystemBuilder},
|
SubWorld, SystemBuilder,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
pub use math::{Mat3, Mat4, Quat, Vec2, Vec3, Vec4};
|
pub use math::{Mat3, Mat4, Quat, Vec2, Vec3, Vec4};
|
||||||
|
|
|
@ -3,19 +3,21 @@ use crate::{
|
||||||
asset::Handle,
|
asset::Handle,
|
||||||
render::render_graph::{pipeline::PipelineDescriptor, RenderPass},
|
render::render_graph::{pipeline::PipelineDescriptor, RenderPass},
|
||||||
};
|
};
|
||||||
use legion::prelude::World;
|
use legion::prelude::{Resources, World};
|
||||||
|
|
||||||
// A set of draw calls. ex: get + draw meshes, get + draw instanced meshes, draw ui meshes, etc
|
// A set of draw calls. ex: get + draw meshes, get + draw instanced meshes, draw ui meshes, etc
|
||||||
pub trait DrawTarget {
|
pub trait DrawTarget {
|
||||||
fn draw(
|
fn draw(
|
||||||
&self,
|
&self,
|
||||||
world: &World,
|
world: &World,
|
||||||
|
resources: &Resources,
|
||||||
render_pass: &mut dyn RenderPass,
|
render_pass: &mut dyn RenderPass,
|
||||||
pipeline_handle: Handle<PipelineDescriptor>,
|
pipeline_handle: Handle<PipelineDescriptor>,
|
||||||
);
|
);
|
||||||
fn setup(
|
fn setup(
|
||||||
&mut self,
|
&mut self,
|
||||||
world: &World,
|
world: &World,
|
||||||
|
world: &Resources,
|
||||||
renderer: &mut dyn Renderer,
|
renderer: &mut dyn Renderer,
|
||||||
pipeline_handle: Handle<PipelineDescriptor>,
|
pipeline_handle: Handle<PipelineDescriptor>,
|
||||||
);
|
);
|
||||||
|
|
|
@ -14,11 +14,11 @@ impl DrawTarget for AssignedMeshesDrawTarget {
|
||||||
fn draw(
|
fn draw(
|
||||||
&self,
|
&self,
|
||||||
world: &World,
|
world: &World,
|
||||||
|
resources: &Resources,
|
||||||
render_pass: &mut dyn RenderPass,
|
render_pass: &mut dyn RenderPass,
|
||||||
pipeline_handle: Handle<PipelineDescriptor>,
|
pipeline_handle: Handle<PipelineDescriptor>,
|
||||||
) {
|
) {
|
||||||
let shader_pipeline_assignments =
|
let shader_pipeline_assignments = resources.get::<ShaderPipelineAssignments>().unwrap();
|
||||||
world.resources.get::<ShaderPipelineAssignments>().unwrap();
|
|
||||||
let mut current_mesh_handle = None;
|
let mut current_mesh_handle = None;
|
||||||
let mut current_mesh_index_len = 0;
|
let mut current_mesh_index_len = 0;
|
||||||
|
|
||||||
|
@ -66,18 +66,15 @@ impl DrawTarget for AssignedMeshesDrawTarget {
|
||||||
fn setup(
|
fn setup(
|
||||||
&mut self,
|
&mut self,
|
||||||
world: &World,
|
world: &World,
|
||||||
|
resources: &Resources,
|
||||||
renderer: &mut dyn crate::render::render_graph::Renderer,
|
renderer: &mut dyn crate::render::render_graph::Renderer,
|
||||||
pipeline_handle: Handle<PipelineDescriptor>,
|
pipeline_handle: Handle<PipelineDescriptor>,
|
||||||
) {
|
) {
|
||||||
let shader_pipeline_assignments =
|
let shader_pipeline_assignments = resources.get::<ShaderPipelineAssignments>().unwrap();
|
||||||
world.resources.get::<ShaderPipelineAssignments>().unwrap();
|
|
||||||
let assigned_entities = shader_pipeline_assignments
|
let assigned_entities = shader_pipeline_assignments
|
||||||
.assignments
|
.assignments
|
||||||
.get(&pipeline_handle);
|
.get(&pipeline_handle);
|
||||||
let pipeline_storage = world
|
let pipeline_storage = resources.get::<AssetStorage<PipelineDescriptor>>().unwrap();
|
||||||
.resources
|
|
||||||
.get::<AssetStorage<PipelineDescriptor>>()
|
|
||||||
.unwrap();
|
|
||||||
let pipeline_descriptor = pipeline_storage.get(&pipeline_handle).unwrap();
|
let pipeline_descriptor = pipeline_storage.get(&pipeline_handle).unwrap();
|
||||||
if let Some(assigned_entities) = assigned_entities {
|
if let Some(assigned_entities) = assigned_entities {
|
||||||
for entity in assigned_entities.iter() {
|
for entity in assigned_entities.iter() {
|
||||||
|
|
|
@ -16,6 +16,7 @@ impl DrawTarget for MeshesDrawTarget {
|
||||||
fn draw(
|
fn draw(
|
||||||
&self,
|
&self,
|
||||||
world: &World,
|
world: &World,
|
||||||
|
_resources: &Resources,
|
||||||
render_pass: &mut dyn RenderPass,
|
render_pass: &mut dyn RenderPass,
|
||||||
_pipeline_handle: Handle<PipelineDescriptor>,
|
_pipeline_handle: Handle<PipelineDescriptor>,
|
||||||
) {
|
) {
|
||||||
|
@ -59,6 +60,7 @@ impl DrawTarget for MeshesDrawTarget {
|
||||||
fn setup(
|
fn setup(
|
||||||
&mut self,
|
&mut self,
|
||||||
_world: &World,
|
_world: &World,
|
||||||
|
_resources: &Resources,
|
||||||
_renderer: &mut dyn crate::render::render_graph::Renderer,
|
_renderer: &mut dyn crate::render::render_graph::Renderer,
|
||||||
_pipeline_handle: Handle<PipelineDescriptor>,
|
_pipeline_handle: Handle<PipelineDescriptor>,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ impl DrawTarget for UiDrawTarget {
|
||||||
fn draw(
|
fn draw(
|
||||||
&self,
|
&self,
|
||||||
_world: &World,
|
_world: &World,
|
||||||
|
_resources: &Resources,
|
||||||
render_pass: &mut dyn RenderPass,
|
render_pass: &mut dyn RenderPass,
|
||||||
_pipeline_handle: Handle<PipelineDescriptor>,
|
_pipeline_handle: Handle<PipelineDescriptor>,
|
||||||
) {
|
) {
|
||||||
|
@ -48,12 +49,16 @@ impl DrawTarget for UiDrawTarget {
|
||||||
render_pass.set_index_buffer(self.mesh_index_buffer.unwrap(), 0);
|
render_pass.set_index_buffer(self.mesh_index_buffer.unwrap(), 0);
|
||||||
render_pass.set_vertex_buffer(0, self.mesh_vertex_buffer.unwrap(), 0);
|
render_pass.set_vertex_buffer(0, self.mesh_vertex_buffer.unwrap(), 0);
|
||||||
render_pass.set_vertex_buffer(1, ui_instances_buffer, 0);
|
render_pass.set_vertex_buffer(1, ui_instances_buffer, 0);
|
||||||
render_pass.draw_indexed(0..self.mesh_index_length as u32, 0, 0..(index_count.unwrap() as u32));
|
render_pass.draw_indexed(
|
||||||
|
0..self.mesh_index_length as u32,
|
||||||
|
0,
|
||||||
|
0..(index_count.unwrap() as u32),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
fn setup(
|
fn setup(
|
||||||
&mut self,
|
&mut self,
|
||||||
world: &World,
|
_world: &World,
|
||||||
|
resources: &Resources,
|
||||||
renderer: &mut dyn crate::render::render_graph::Renderer,
|
renderer: &mut dyn crate::render::render_graph::Renderer,
|
||||||
_pipeline_handle: Handle<PipelineDescriptor>,
|
_pipeline_handle: Handle<PipelineDescriptor>,
|
||||||
) {
|
) {
|
||||||
|
@ -75,7 +80,7 @@ impl DrawTarget for UiDrawTarget {
|
||||||
if let ResourceInfo::InstanceBuffer { mesh_id, .. } =
|
if let ResourceInfo::InstanceBuffer { mesh_id, .. } =
|
||||||
renderer.get_resource_info(ui_instances_buffer).unwrap()
|
renderer.get_resource_info(ui_instances_buffer).unwrap()
|
||||||
{
|
{
|
||||||
let mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
let mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||||
if let Some(mesh_asset) = mesh_storage.get_id(*mesh_id) {
|
if let Some(mesh_asset) = mesh_storage.get_id(*mesh_id) {
|
||||||
self.mesh_vertex_buffer = Some(renderer.create_buffer_with_data(
|
self.mesh_vertex_buffer = Some(renderer.create_buffer_with_data(
|
||||||
mesh_asset.vertices.as_bytes(),
|
mesh_asset.vertices.as_bytes(),
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
use super::{
|
use super::{DrawTarget, PassDescriptor, PipelineDescriptor, ResourceProvider, TextureDescriptor};
|
||||||
DrawTarget, PassDescriptor, PipelineDescriptor, ResourceProvider, TextureDescriptor,
|
|
||||||
};
|
|
||||||
use crate::asset::{AssetStorage, Handle};
|
use crate::asset::{AssetStorage, Handle};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
|
|
|
@ -95,18 +95,19 @@ fn try_compiling_shader_with_macros(
|
||||||
Some(compiled_shader_handle)
|
Some(compiled_shader_handle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn update_shader_assignments(world: &mut World, render_graph: &mut RenderGraph) {
|
pub fn update_shader_assignments(
|
||||||
|
world: &mut World,
|
||||||
|
resources: &mut Resources,
|
||||||
|
render_graph: &mut RenderGraph,
|
||||||
|
) {
|
||||||
// PERF: this seems like a lot of work for things that don't change that often.
|
// PERF: this seems like a lot of work for things that don't change that often.
|
||||||
// lots of string + hashset allocations. sees uniform_resource_provider for more context
|
// lots of string + hashset allocations. sees uniform_resource_provider for more context
|
||||||
{
|
{
|
||||||
let mut shader_pipeline_assignments = world
|
let mut shader_pipeline_assignments =
|
||||||
.resources
|
resources.get_mut::<ShaderPipelineAssignments>().unwrap();
|
||||||
.get_mut::<ShaderPipelineAssignments>()
|
let mut compiled_shader_map = resources.get_mut::<CompiledShaderMap>().unwrap();
|
||||||
.unwrap();
|
let mut shader_storage = resources.get_mut::<AssetStorage<Shader>>().unwrap();
|
||||||
let mut compiled_shader_map = world.resources.get_mut::<CompiledShaderMap>().unwrap();
|
let mut pipeline_descriptor_storage = resources
|
||||||
let mut shader_storage = world.resources.get_mut::<AssetStorage<Shader>>().unwrap();
|
|
||||||
let mut pipeline_descriptor_storage = world
|
|
||||||
.resources
|
|
||||||
.get_mut::<AssetStorage<PipelineDescriptor>>()
|
.get_mut::<AssetStorage<PipelineDescriptor>>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -9,15 +9,26 @@ use crate::{
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|
||||||
pub trait Renderer {
|
pub trait Renderer {
|
||||||
fn initialize(&mut self, world: &mut World, render_graph: &mut RenderGraph);
|
fn initialize(
|
||||||
|
&mut self,
|
||||||
|
world: &mut World,
|
||||||
|
resources: &mut Resources,
|
||||||
|
render_graph: &mut RenderGraph,
|
||||||
|
);
|
||||||
fn resize(
|
fn resize(
|
||||||
&mut self,
|
&mut self,
|
||||||
world: &mut World,
|
world: &mut World,
|
||||||
|
resources: &mut Resources,
|
||||||
render_graph: &mut RenderGraph,
|
render_graph: &mut RenderGraph,
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
);
|
);
|
||||||
fn process_render_graph(&mut self, render_graph: &mut RenderGraph, world: &mut World);
|
fn process_render_graph(
|
||||||
|
&mut self,
|
||||||
|
render_graph: &mut RenderGraph,
|
||||||
|
world: &mut World,
|
||||||
|
resources: &mut Resources,
|
||||||
|
);
|
||||||
// TODO: swap out wgpu::BufferUsage for non-wgpu type
|
// TODO: swap out wgpu::BufferUsage for non-wgpu type
|
||||||
fn create_buffer_with_data(
|
fn create_buffer_with_data(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
@ -295,6 +295,7 @@ impl WgpuRenderer {
|
||||||
pub fn initialize_resource_providers(
|
pub fn initialize_resource_providers(
|
||||||
&mut self,
|
&mut self,
|
||||||
world: &mut World,
|
world: &mut World,
|
||||||
|
resources: &mut Resources,
|
||||||
render_graph: &mut RenderGraph,
|
render_graph: &mut RenderGraph,
|
||||||
) {
|
) {
|
||||||
self.encoder = Some(
|
self.encoder = Some(
|
||||||
|
@ -302,7 +303,7 @@ impl WgpuRenderer {
|
||||||
.create_command_encoder(&wgpu::CommandEncoderDescriptor { todo: 0 }),
|
.create_command_encoder(&wgpu::CommandEncoderDescriptor { todo: 0 }),
|
||||||
);
|
);
|
||||||
for resource_provider in render_graph.resource_providers.iter_mut() {
|
for resource_provider in render_graph.resource_providers.iter_mut() {
|
||||||
resource_provider.initialize(self, world);
|
resource_provider.initialize(self, world, resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
// consume current encoder
|
// consume current encoder
|
||||||
|
@ -312,9 +313,14 @@ impl WgpuRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Renderer for WgpuRenderer {
|
impl Renderer for WgpuRenderer {
|
||||||
fn initialize(&mut self, world: &mut World, render_graph: &mut RenderGraph) {
|
fn initialize(
|
||||||
|
&mut self,
|
||||||
|
world: &mut World,
|
||||||
|
resources: &mut Resources,
|
||||||
|
render_graph: &mut RenderGraph,
|
||||||
|
) {
|
||||||
let (surface, window_size) = {
|
let (surface, window_size) = {
|
||||||
let window = world.resources.get::<winit::window::Window>().unwrap();
|
let window = resources.get::<winit::window::Window>().unwrap();
|
||||||
let surface = wgpu::Surface::create(window.deref());
|
let surface = wgpu::Surface::create(window.deref());
|
||||||
let window_size = window.inner_size();
|
let window_size = window.inner_size();
|
||||||
(surface, window_size)
|
(surface, window_size)
|
||||||
|
@ -322,14 +328,21 @@ impl Renderer for WgpuRenderer {
|
||||||
|
|
||||||
self.surface = Some(surface);
|
self.surface = Some(surface);
|
||||||
|
|
||||||
self.initialize_resource_providers(world, render_graph);
|
self.initialize_resource_providers(world, resources, render_graph);
|
||||||
|
|
||||||
self.resize(world, render_graph, window_size.width, window_size.height);
|
self.resize(
|
||||||
|
world,
|
||||||
|
resources,
|
||||||
|
render_graph,
|
||||||
|
window_size.width,
|
||||||
|
window_size.height,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resize(
|
fn resize(
|
||||||
&mut self,
|
&mut self,
|
||||||
world: &mut World,
|
world: &mut World,
|
||||||
|
resources: &mut Resources,
|
||||||
render_graph: &mut RenderGraph,
|
render_graph: &mut RenderGraph,
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
|
@ -345,9 +358,9 @@ impl Renderer for WgpuRenderer {
|
||||||
.create_swap_chain(self.surface.as_ref().unwrap(), &self.swap_chain_descriptor);
|
.create_swap_chain(self.surface.as_ref().unwrap(), &self.swap_chain_descriptor);
|
||||||
|
|
||||||
// WgpuRenderer can't own swap_chain without creating lifetime ergonomics issues, so lets just store it in World.
|
// WgpuRenderer can't own swap_chain without creating lifetime ergonomics issues, so lets just store it in World.
|
||||||
world.resources.insert(swap_chain);
|
resources.insert(swap_chain);
|
||||||
for resource_provider in render_graph.resource_providers.iter_mut() {
|
for resource_provider in render_graph.resource_providers.iter_mut() {
|
||||||
resource_provider.resize(self, world, width, height);
|
resource_provider.resize(self, world, resources, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
// consume current encoder
|
// consume current encoder
|
||||||
|
@ -355,7 +368,12 @@ impl Renderer for WgpuRenderer {
|
||||||
self.queue.submit(&[command_buffer]);
|
self.queue.submit(&[command_buffer]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_render_graph(&mut self, render_graph: &mut RenderGraph, world: &mut World) {
|
fn process_render_graph(
|
||||||
|
&mut self,
|
||||||
|
render_graph: &mut RenderGraph,
|
||||||
|
world: &mut World,
|
||||||
|
resources: &mut Resources,
|
||||||
|
) {
|
||||||
// TODO: this self.encoder handoff is a bit gross, but its here to give resource providers access to buffer copies without
|
// TODO: this self.encoder handoff is a bit gross, but its here to give resource providers access to buffer copies without
|
||||||
// exposing the wgpu renderer internals to ResourceProvider traits. if this can be made cleaner that would be pretty cool.
|
// exposing the wgpu renderer internals to ResourceProvider traits. if this can be made cleaner that would be pretty cool.
|
||||||
self.encoder = Some(
|
self.encoder = Some(
|
||||||
|
@ -364,10 +382,10 @@ impl Renderer for WgpuRenderer {
|
||||||
);
|
);
|
||||||
|
|
||||||
for resource_provider in render_graph.resource_providers.iter_mut() {
|
for resource_provider in render_graph.resource_providers.iter_mut() {
|
||||||
resource_provider.update(self, world);
|
resource_provider.update(self, world, resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
update_shader_assignments(world, render_graph);
|
update_shader_assignments(world, resources, render_graph);
|
||||||
|
|
||||||
for (name, texture_descriptor) in render_graph.queued_textures.drain(..) {
|
for (name, texture_descriptor) in render_graph.queued_textures.drain(..) {
|
||||||
let resource = self.create_texture(&texture_descriptor, None);
|
let resource = self.create_texture(&texture_descriptor, None);
|
||||||
|
@ -378,7 +396,7 @@ impl Renderer for WgpuRenderer {
|
||||||
|
|
||||||
let mut encoder = self.encoder.take().unwrap();
|
let mut encoder = self.encoder.take().unwrap();
|
||||||
|
|
||||||
let mut swap_chain = world.resources.get_mut::<wgpu::SwapChain>().unwrap();
|
let mut swap_chain = resources.get_mut::<wgpu::SwapChain>().unwrap();
|
||||||
let frame = swap_chain
|
let frame = swap_chain
|
||||||
.get_next_texture()
|
.get_next_texture()
|
||||||
.expect("Timeout when acquiring next swap chain texture");
|
.expect("Timeout when acquiring next swap chain texture");
|
||||||
|
@ -386,11 +404,10 @@ impl Renderer for WgpuRenderer {
|
||||||
// self.setup_dynamic_entity_shader_uniforms(world, render_graph, &mut encoder);
|
// self.setup_dynamic_entity_shader_uniforms(world, render_graph, &mut encoder);
|
||||||
|
|
||||||
// setup, pipelines, bind groups, and resources
|
// setup, pipelines, bind groups, and resources
|
||||||
let mut pipeline_storage = world
|
let mut pipeline_storage = resources
|
||||||
.resources
|
|
||||||
.get_mut::<AssetStorage<PipelineDescriptor>>()
|
.get_mut::<AssetStorage<PipelineDescriptor>>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let shader_storage = world.resources.get::<AssetStorage<Shader>>().unwrap();
|
let shader_storage = resources.get::<AssetStorage<Shader>>().unwrap();
|
||||||
|
|
||||||
for pipeline_descriptor_handle in render_graph.pipeline_descriptors.iter() {
|
for pipeline_descriptor_handle in render_graph.pipeline_descriptors.iter() {
|
||||||
let pipeline_descriptor = pipeline_storage
|
let pipeline_descriptor = pipeline_storage
|
||||||
|
@ -438,7 +455,7 @@ impl Renderer for WgpuRenderer {
|
||||||
for draw_target_name in pipeline_descriptor.draw_targets.iter() {
|
for draw_target_name in pipeline_descriptor.draw_targets.iter() {
|
||||||
let draw_target =
|
let draw_target =
|
||||||
render_graph.draw_targets.get_mut(draw_target_name).unwrap();
|
render_graph.draw_targets.get_mut(draw_target_name).unwrap();
|
||||||
draw_target.setup(world, self, *pass_pipeline);
|
draw_target.setup(world, resources, self, *pass_pipeline);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -467,7 +484,7 @@ impl Renderer for WgpuRenderer {
|
||||||
|
|
||||||
for draw_target_name in pipeline_descriptor.draw_targets.iter() {
|
for draw_target_name in pipeline_descriptor.draw_targets.iter() {
|
||||||
let draw_target = render_graph.draw_targets.get(draw_target_name).unwrap();
|
let draw_target = render_graph.draw_targets.get(draw_target_name).unwrap();
|
||||||
draw_target.draw(world, &mut wgpu_render_pass, *pass_pipeline);
|
draw_target.draw(world, resources, &mut wgpu_render_pass, *pass_pipeline);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,14 @@ use crate::render::render_graph::Renderer;
|
||||||
use legion::prelude::*;
|
use legion::prelude::*;
|
||||||
|
|
||||||
pub trait ResourceProvider {
|
pub trait ResourceProvider {
|
||||||
fn initialize(&mut self, renderer: &mut dyn Renderer, world: &mut World);
|
fn initialize(&mut self, renderer: &mut dyn Renderer, world: &mut World, resources: &Resources);
|
||||||
fn update(&mut self, renderer: &mut dyn Renderer, world: &mut World);
|
fn update(&mut self, renderer: &mut dyn Renderer, world: &mut World, resources: &Resources);
|
||||||
fn resize(&mut self, renderer: &mut dyn Renderer, world: &mut World, width: u32, height: u32);
|
fn resize(
|
||||||
|
&mut self,
|
||||||
|
renderer: &mut dyn Renderer,
|
||||||
|
world: &mut World,
|
||||||
|
resources: &Resources,
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,12 @@ pub struct Camera2dResourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResourceProvider for Camera2dResourceProvider {
|
impl ResourceProvider for Camera2dResourceProvider {
|
||||||
fn initialize(&mut self, renderer: &mut dyn Renderer, _world: &mut World) {
|
fn initialize(
|
||||||
|
&mut self,
|
||||||
|
renderer: &mut dyn Renderer,
|
||||||
|
_world: &mut World,
|
||||||
|
_resources: &Resources,
|
||||||
|
) {
|
||||||
let buffer = renderer.create_buffer(
|
let buffer = renderer.create_buffer(
|
||||||
std::mem::size_of::<[[f32; 4]; 4]>() as u64,
|
std::mem::size_of::<[[f32; 4]; 4]>() as u64,
|
||||||
wgpu::BufferUsage::COPY_DST | wgpu::BufferUsage::UNIFORM,
|
wgpu::BufferUsage::COPY_DST | wgpu::BufferUsage::UNIFORM,
|
||||||
|
@ -24,8 +29,16 @@ impl ResourceProvider for Camera2dResourceProvider {
|
||||||
self.camera_buffer = Some(buffer);
|
self.camera_buffer = Some(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, _renderer: &mut dyn Renderer, _world: &mut World) {}
|
fn update(&mut self, _renderer: &mut dyn Renderer, _world: &mut World, _resources: &Resources) {
|
||||||
fn resize(&mut self, renderer: &mut dyn Renderer, world: &mut World, width: u32, height: u32) {
|
}
|
||||||
|
fn resize(
|
||||||
|
&mut self,
|
||||||
|
renderer: &mut dyn Renderer,
|
||||||
|
world: &mut World,
|
||||||
|
_resources: &Resources,
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
) {
|
||||||
let matrix_size = std::mem::size_of::<[[f32; 4]; 4]>();
|
let matrix_size = std::mem::size_of::<[[f32; 4]; 4]>();
|
||||||
for (mut camera, _) in <(Write<Camera>, Read<ActiveCamera2d>)>::query().iter_mut(world) {
|
for (mut camera, _) in <(Write<Camera>, Read<ActiveCamera2d>)>::query().iter_mut(world) {
|
||||||
camera.update(width, height);
|
camera.update(width, height);
|
||||||
|
|
|
@ -13,7 +13,12 @@ pub struct CameraResourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResourceProvider for CameraResourceProvider {
|
impl ResourceProvider for CameraResourceProvider {
|
||||||
fn initialize(&mut self, renderer: &mut dyn Renderer, _world: &mut World) {
|
fn initialize(
|
||||||
|
&mut self,
|
||||||
|
renderer: &mut dyn Renderer,
|
||||||
|
_world: &mut World,
|
||||||
|
_resources: &Resources,
|
||||||
|
) {
|
||||||
let buffer = renderer.create_buffer(
|
let buffer = renderer.create_buffer(
|
||||||
std::mem::size_of::<[[f32; 4]; 4]>() as u64,
|
std::mem::size_of::<[[f32; 4]; 4]>() as u64,
|
||||||
wgpu::BufferUsage::COPY_DST | wgpu::BufferUsage::UNIFORM,
|
wgpu::BufferUsage::COPY_DST | wgpu::BufferUsage::UNIFORM,
|
||||||
|
@ -25,8 +30,16 @@ impl ResourceProvider for CameraResourceProvider {
|
||||||
self.camera_buffer = Some(buffer);
|
self.camera_buffer = Some(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, _renderer: &mut dyn Renderer, _world: &mut World) {}
|
fn update(&mut self, _renderer: &mut dyn Renderer, _world: &mut World, _resources: &Resources) {
|
||||||
fn resize(&mut self, renderer: &mut dyn Renderer, world: &mut World, width: u32, height: u32) {
|
}
|
||||||
|
fn resize(
|
||||||
|
&mut self,
|
||||||
|
renderer: &mut dyn Renderer,
|
||||||
|
world: &mut World,
|
||||||
|
_resources: &Resources,
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
) {
|
||||||
let matrix_size = std::mem::size_of::<[[f32; 4]; 4]>();
|
let matrix_size = std::mem::size_of::<[[f32; 4]; 4]>();
|
||||||
for (mut camera, local_to_world, _) in
|
for (mut camera, local_to_world, _) in
|
||||||
<(Write<Camera>, Read<LocalToWorld>, Read<ActiveCamera>)>::query().iter_mut(world)
|
<(Write<Camera>, Read<LocalToWorld>, Read<ActiveCamera>)>::query().iter_mut(world)
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::{
|
||||||
prelude::World,
|
prelude::World,
|
||||||
render::render_graph::{Renderer, ResourceProvider, TextureDescriptor},
|
render::render_graph::{Renderer, ResourceProvider, TextureDescriptor},
|
||||||
};
|
};
|
||||||
|
use legion::prelude::Resources;
|
||||||
|
|
||||||
pub struct FrameTextureResourceProvider {
|
pub struct FrameTextureResourceProvider {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
@ -16,8 +17,8 @@ impl FrameTextureResourceProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, renderer: &mut dyn Renderer, world: &World) {
|
pub fn update(&mut self, renderer: &mut dyn Renderer, _world: &World, resources: &Resources) {
|
||||||
let window = world.resources.get::<winit::window::Window>().unwrap();
|
let window = resources.get::<winit::window::Window>().unwrap();
|
||||||
let window_size = window.inner_size();
|
let window_size = window.inner_size();
|
||||||
self.descriptor.size.width = window_size.width;
|
self.descriptor.size.width = window_size.width;
|
||||||
self.descriptor.size.height = window_size.height;
|
self.descriptor.size.height = window_size.height;
|
||||||
|
@ -37,19 +38,26 @@ impl FrameTextureResourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResourceProvider for FrameTextureResourceProvider {
|
impl ResourceProvider for FrameTextureResourceProvider {
|
||||||
fn initialize(&mut self, renderer: &mut dyn Renderer, world: &mut World) {
|
fn initialize(
|
||||||
self.update(renderer, world);
|
&mut self,
|
||||||
|
renderer: &mut dyn Renderer,
|
||||||
|
world: &mut World,
|
||||||
|
resources: &Resources,
|
||||||
|
) {
|
||||||
|
self.update(renderer, world, resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, _renderer: &mut dyn Renderer, _world: &mut World) {}
|
fn update(&mut self, _renderer: &mut dyn Renderer, _world: &mut World, _resources: &Resources) {
|
||||||
|
}
|
||||||
|
|
||||||
fn resize(
|
fn resize(
|
||||||
&mut self,
|
&mut self,
|
||||||
renderer: &mut dyn Renderer,
|
renderer: &mut dyn Renderer,
|
||||||
world: &mut World,
|
world: &mut World,
|
||||||
|
resources: &Resources,
|
||||||
_width: u32,
|
_width: u32,
|
||||||
_height: u32,
|
_height: u32,
|
||||||
) {
|
) {
|
||||||
self.update(renderer, world);
|
self.update(renderer, world, resources);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,12 @@ impl LightResourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResourceProvider for LightResourceProvider {
|
impl ResourceProvider for LightResourceProvider {
|
||||||
fn initialize(&mut self, renderer: &mut dyn Renderer, _world: &mut World) {
|
fn initialize(
|
||||||
|
&mut self,
|
||||||
|
renderer: &mut dyn Renderer,
|
||||||
|
_world: &mut World,
|
||||||
|
_resources: &Resources,
|
||||||
|
) {
|
||||||
let light_uniform_size = (std::mem::size_of::<LightCount>()
|
let light_uniform_size = (std::mem::size_of::<LightCount>()
|
||||||
+ self.max_lights * std::mem::size_of::<LightRaw>())
|
+ self.max_lights * std::mem::size_of::<LightRaw>())
|
||||||
as wgpu::BufferAddress;
|
as wgpu::BufferAddress;
|
||||||
|
@ -48,7 +53,7 @@ impl ResourceProvider for LightResourceProvider {
|
||||||
self.light_buffer = Some(buffer);
|
self.light_buffer = Some(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, renderer: &mut dyn Renderer, world: &mut World) {
|
fn update(&mut self, renderer: &mut dyn Renderer, world: &mut World, _resources: &Resources) {
|
||||||
if self.lights_are_dirty {
|
if self.lights_are_dirty {
|
||||||
let light_query = <(Read<Light>, Read<LocalToWorld>, Read<Translation>)>::query();
|
let light_query = <(Read<Light>, Read<LocalToWorld>, Read<Translation>)>::query();
|
||||||
let light_count = light_query.iter(world).count();
|
let light_count = light_query.iter(world).count();
|
||||||
|
@ -113,6 +118,7 @@ impl ResourceProvider for LightResourceProvider {
|
||||||
&mut self,
|
&mut self,
|
||||||
_renderer: &mut dyn Renderer,
|
_renderer: &mut dyn Renderer,
|
||||||
_world: &mut World,
|
_world: &mut World,
|
||||||
|
_resources: &Resources,
|
||||||
_width: u32,
|
_width: u32,
|
||||||
_height: u32,
|
_height: u32,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -35,10 +35,16 @@ impl MeshResourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResourceProvider for MeshResourceProvider {
|
impl ResourceProvider for MeshResourceProvider {
|
||||||
fn initialize(&mut self, _renderer: &mut dyn Renderer, _world: &mut World) {}
|
fn initialize(
|
||||||
|
&mut self,
|
||||||
|
_renderer: &mut dyn Renderer,
|
||||||
|
_world: &mut World,
|
||||||
|
_resources: &Resources,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
fn update(&mut self, renderer: &mut dyn Renderer, world: &mut World) {
|
fn update(&mut self, renderer: &mut dyn Renderer, world: &mut World, resources: &Resources) {
|
||||||
let mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
let mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||||
for (mesh_handle, _renderable) in self.mesh_query.iter(world) {
|
for (mesh_handle, _renderable) in self.mesh_query.iter(world) {
|
||||||
if let None = renderer
|
if let None = renderer
|
||||||
.get_render_resources()
|
.get_render_resources()
|
||||||
|
@ -65,6 +71,7 @@ impl ResourceProvider for MeshResourceProvider {
|
||||||
&mut self,
|
&mut self,
|
||||||
_renderer: &mut dyn Renderer,
|
_renderer: &mut dyn Renderer,
|
||||||
_world: &mut World,
|
_world: &mut World,
|
||||||
|
_resources: &Resources,
|
||||||
_width: u32,
|
_width: u32,
|
||||||
_height: u32,
|
_height: u32,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -90,9 +90,14 @@ impl UiResourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResourceProvider for UiResourceProvider {
|
impl ResourceProvider for UiResourceProvider {
|
||||||
fn initialize(&mut self, _renderer: &mut dyn Renderer, world: &mut World) {
|
fn initialize(
|
||||||
|
&mut self,
|
||||||
|
_renderer: &mut dyn Renderer,
|
||||||
|
_world: &mut World,
|
||||||
|
resources: &Resources,
|
||||||
|
) {
|
||||||
// self.update(renderer, world);
|
// self.update(renderer, world);
|
||||||
let mut mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||||
let quad = Mesh::load(MeshType::Quad {
|
let quad = Mesh::load(MeshType::Quad {
|
||||||
north_west: math::vec2(-0.5, 0.5),
|
north_west: math::vec2(-0.5, 0.5),
|
||||||
north_east: math::vec2(0.5, 0.5),
|
north_east: math::vec2(0.5, 0.5),
|
||||||
|
@ -102,7 +107,7 @@ impl ResourceProvider for UiResourceProvider {
|
||||||
self.quad = Some(mesh_storage.add(quad));
|
self.quad = Some(mesh_storage.add(quad));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, renderer: &mut dyn Renderer, world: &mut World) {
|
fn update(&mut self, renderer: &mut dyn Renderer, world: &mut World, _resources: &Resources) {
|
||||||
self.update(renderer, world);
|
self.update(renderer, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,6 +115,7 @@ impl ResourceProvider for UiResourceProvider {
|
||||||
&mut self,
|
&mut self,
|
||||||
_renderer: &mut dyn Renderer,
|
_renderer: &mut dyn Renderer,
|
||||||
_world: &mut World,
|
_world: &mut World,
|
||||||
|
_resources: &Resources,
|
||||||
_width: u32,
|
_width: u32,
|
||||||
_height: u32,
|
_height: u32,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -39,11 +39,16 @@ impl<T> ResourceProvider for UniformResourceProvider<T>
|
||||||
where
|
where
|
||||||
T: AsUniforms + Send + Sync + 'static,
|
T: AsUniforms + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
fn initialize(&mut self, renderer: &mut dyn Renderer, world: &mut World) {
|
fn initialize(
|
||||||
self.update(renderer, world);
|
&mut self,
|
||||||
|
renderer: &mut dyn Renderer,
|
||||||
|
world: &mut World,
|
||||||
|
resources: &Resources,
|
||||||
|
) {
|
||||||
|
self.update(renderer, world, resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, renderer: &mut dyn Renderer, world: &mut World) {
|
fn update(&mut self, renderer: &mut dyn Renderer, world: &mut World, resources: &Resources) {
|
||||||
let query = <(Read<T>, Read<Renderable>)>::query();
|
let query = <(Read<T>, Read<Renderable>)>::query();
|
||||||
// TODO: this breaks down in multiple ways:
|
// TODO: this breaks down in multiple ways:
|
||||||
// (SOLVED 1) resource_info will be set after the first run so this won't update.
|
// (SOLVED 1) resource_info will be set after the first run so this won't update.
|
||||||
|
@ -79,7 +84,7 @@ where
|
||||||
BindType::SampledTexture { .. } => {
|
BindType::SampledTexture { .. } => {
|
||||||
let texture_handle =
|
let texture_handle =
|
||||||
uniforms.get_uniform_texture(&uniform_info.name).unwrap();
|
uniforms.get_uniform_texture(&uniform_info.name).unwrap();
|
||||||
let storage = world.resources.get::<AssetStorage<Texture>>().unwrap();
|
let storage = resources.get::<AssetStorage<Texture>>().unwrap();
|
||||||
let texture = storage.get(&texture_handle).unwrap();
|
let texture = storage.get(&texture_handle).unwrap();
|
||||||
let resource = match renderer
|
let resource = match renderer
|
||||||
.get_render_resources()
|
.get_render_resources()
|
||||||
|
@ -102,7 +107,7 @@ where
|
||||||
BindType::Sampler { .. } => {
|
BindType::Sampler { .. } => {
|
||||||
let texture_handle =
|
let texture_handle =
|
||||||
uniforms.get_uniform_texture(&uniform_info.name).unwrap();
|
uniforms.get_uniform_texture(&uniform_info.name).unwrap();
|
||||||
let storage = world.resources.get::<AssetStorage<Texture>>().unwrap();
|
let storage = resources.get::<AssetStorage<Texture>>().unwrap();
|
||||||
let texture = storage.get(&texture_handle).unwrap();
|
let texture = storage.get(&texture_handle).unwrap();
|
||||||
let resource = match renderer
|
let resource = match renderer
|
||||||
.get_render_resources()
|
.get_render_resources()
|
||||||
|
@ -225,6 +230,7 @@ where
|
||||||
&mut self,
|
&mut self,
|
||||||
_renderer: &mut dyn Renderer,
|
_renderer: &mut dyn Renderer,
|
||||||
_world: &mut World,
|
_world: &mut World,
|
||||||
|
_resources: &Resources,
|
||||||
_width: u32,
|
_width: u32,
|
||||||
_height: u32,
|
_height: u32,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -13,7 +13,7 @@ use serde::{
|
||||||
Deserialize, Deserializer, Serialize, Serializer,
|
Deserialize, Deserializer, Serialize, Serializer,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
any::type_name, cell::RefCell, collections::HashMap, iter::FromIterator, marker::PhantomData,
|
any::TypeId, cell::RefCell, collections::HashMap, iter::FromIterator, marker::PhantomData,
|
||||||
ptr::NonNull,
|
ptr::NonNull,
|
||||||
};
|
};
|
||||||
use type_uuid::TypeUuid;
|
use type_uuid::TypeUuid;
|
||||||
|
@ -101,7 +101,7 @@ impl<'de, 'a, T: for<'b> Deserialize<'b> + 'static> Visitor<'de>
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct TagRegistration {
|
pub struct TagRegistration {
|
||||||
uuid: type_uuid::Bytes,
|
uuid: type_uuid::Bytes,
|
||||||
ty: String,
|
ty: TypeId,
|
||||||
tag_serialize_fn: fn(&TagStorage, &mut dyn FnMut(&dyn erased_serde::Serialize)),
|
tag_serialize_fn: fn(&TagStorage, &mut dyn FnMut(&dyn erased_serde::Serialize)),
|
||||||
tag_deserialize_fn: fn(
|
tag_deserialize_fn: fn(
|
||||||
deserializer: &mut dyn erased_serde::Deserializer,
|
deserializer: &mut dyn erased_serde::Deserializer,
|
||||||
|
@ -123,7 +123,7 @@ impl TagRegistration {
|
||||||
>() -> Self {
|
>() -> Self {
|
||||||
Self {
|
Self {
|
||||||
uuid: T::UUID,
|
uuid: T::UUID,
|
||||||
ty: type_name::<T>().to_string(),
|
ty: TypeId::of::<T>(),
|
||||||
tag_serialize_fn: |tag_storage, serialize_fn| {
|
tag_serialize_fn: |tag_storage, serialize_fn| {
|
||||||
// it's safe because we know this is the correct type due to lookup
|
// it's safe because we know this is the correct type due to lookup
|
||||||
let slice = unsafe { tag_storage.data_slice::<T>() };
|
let slice = unsafe { tag_storage.data_slice::<T>() };
|
||||||
|
@ -150,7 +150,7 @@ impl TagRegistration {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ComponentRegistration {
|
pub struct ComponentRegistration {
|
||||||
uuid: type_uuid::Bytes,
|
uuid: type_uuid::Bytes,
|
||||||
ty: String,
|
ty: TypeId,
|
||||||
comp_serialize_fn: fn(&ComponentResourceSet, &mut dyn FnMut(&dyn erased_serde::Serialize)),
|
comp_serialize_fn: fn(&ComponentResourceSet, &mut dyn FnMut(&dyn erased_serde::Serialize)),
|
||||||
comp_deserialize_fn: fn(
|
comp_deserialize_fn: fn(
|
||||||
deserializer: &mut dyn erased_serde::Deserializer,
|
deserializer: &mut dyn erased_serde::Deserializer,
|
||||||
|
@ -164,7 +164,7 @@ impl ComponentRegistration {
|
||||||
{
|
{
|
||||||
Self {
|
Self {
|
||||||
uuid: T::UUID,
|
uuid: T::UUID,
|
||||||
ty: type_name::<T>().to_string(),
|
ty: TypeId::of::<T>(),
|
||||||
comp_serialize_fn: |comp_storage, serialize_fn| {
|
comp_serialize_fn: |comp_storage, serialize_fn| {
|
||||||
// it's safe because we know this is the correct type due to lookup
|
// it's safe because we know this is the correct type due to lookup
|
||||||
let slice = unsafe { comp_storage.data_slice::<T>() };
|
let slice = unsafe { comp_storage.data_slice::<T>() };
|
||||||
|
@ -192,8 +192,8 @@ struct SerializedArchetypeDescription {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SerializeImpl {
|
pub struct SerializeImpl {
|
||||||
pub tag_types: HashMap<String, TagRegistration>,
|
pub tag_types: HashMap<TypeId, TagRegistration>,
|
||||||
pub comp_types: HashMap<String, ComponentRegistration>,
|
pub comp_types: HashMap<TypeId, ComponentRegistration>,
|
||||||
pub entity_map: RefCell<HashMap<Entity, uuid::Bytes>>,
|
pub entity_map: RefCell<HashMap<Entity, uuid::Bytes>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,12 +240,12 @@ impl SerializeImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl legion::ser::WorldSerializer for SerializeImpl {
|
impl legion::serialize::ser::WorldSerializer for SerializeImpl {
|
||||||
fn can_serialize_tag(&self, ty: &TagTypeId, _meta: &TagMeta) -> bool {
|
fn can_serialize_tag(&self, ty: &TagTypeId, _meta: &TagMeta) -> bool {
|
||||||
self.tag_types.get(ty.0).is_some()
|
self.tag_types.get(&ty.0).is_some()
|
||||||
}
|
}
|
||||||
fn can_serialize_component(&self, ty: &ComponentTypeId, _meta: &ComponentMeta) -> bool {
|
fn can_serialize_component(&self, ty: &ComponentTypeId, _meta: &ComponentMeta) -> bool {
|
||||||
self.comp_types.get(ty.0).is_some()
|
self.comp_types.get(&ty.0).is_some()
|
||||||
}
|
}
|
||||||
fn serialize_archetype_description<S: Serializer>(
|
fn serialize_archetype_description<S: Serializer>(
|
||||||
&self,
|
&self,
|
||||||
|
@ -255,13 +255,13 @@ impl legion::ser::WorldSerializer for SerializeImpl {
|
||||||
let tags_to_serialize = archetype_desc
|
let tags_to_serialize = archetype_desc
|
||||||
.tags()
|
.tags()
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(ty, _)| self.tag_types.get(ty.0))
|
.filter_map(|(ty, _)| self.tag_types.get(&ty.0))
|
||||||
.map(|reg| reg.uuid)
|
.map(|reg| reg.uuid)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let components_to_serialize = archetype_desc
|
let components_to_serialize = archetype_desc
|
||||||
.components()
|
.components()
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(ty, _)| self.comp_types.get(ty.0))
|
.filter_map(|(ty, _)| self.comp_types.get(&ty.0))
|
||||||
.map(|reg| reg.uuid)
|
.map(|reg| reg.uuid)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
SerializedArchetypeDescription {
|
SerializedArchetypeDescription {
|
||||||
|
@ -277,7 +277,7 @@ impl legion::ser::WorldSerializer for SerializeImpl {
|
||||||
_component_meta: &ComponentMeta,
|
_component_meta: &ComponentMeta,
|
||||||
components: &ComponentResourceSet,
|
components: &ComponentResourceSet,
|
||||||
) -> Result<S::Ok, S::Error> {
|
) -> Result<S::Ok, S::Error> {
|
||||||
if let Some(reg) = self.comp_types.get(component_type.0) {
|
if let Some(reg) = self.comp_types.get(&component_type.0) {
|
||||||
let result = RefCell::new(None);
|
let result = RefCell::new(None);
|
||||||
let serializer = RefCell::new(Some(serializer));
|
let serializer = RefCell::new(Some(serializer));
|
||||||
{
|
{
|
||||||
|
@ -303,7 +303,7 @@ impl legion::ser::WorldSerializer for SerializeImpl {
|
||||||
_tag_meta: &TagMeta,
|
_tag_meta: &TagMeta,
|
||||||
tags: &TagStorage,
|
tags: &TagStorage,
|
||||||
) -> Result<S::Ok, S::Error> {
|
) -> Result<S::Ok, S::Error> {
|
||||||
if let Some(reg) = self.tag_types.get(tag_type.0) {
|
if let Some(reg) = self.tag_types.get(&tag_type.0) {
|
||||||
let result = RefCell::new(None);
|
let result = RefCell::new(None);
|
||||||
let serializer = RefCell::new(Some(serializer));
|
let serializer = RefCell::new(Some(serializer));
|
||||||
{
|
{
|
||||||
|
@ -337,8 +337,8 @@ impl legion::ser::WorldSerializer for SerializeImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DeserializeImpl {
|
pub struct DeserializeImpl {
|
||||||
pub tag_types: HashMap<String, TagRegistration>,
|
pub tag_types: HashMap<TypeId, TagRegistration>,
|
||||||
pub comp_types: HashMap<String, ComponentRegistration>,
|
pub comp_types: HashMap<TypeId, ComponentRegistration>,
|
||||||
pub tag_types_by_uuid: HashMap<type_uuid::Bytes, TagRegistration>,
|
pub tag_types_by_uuid: HashMap<type_uuid::Bytes, TagRegistration>,
|
||||||
pub comp_types_by_uuid: HashMap<type_uuid::Bytes, ComponentRegistration>,
|
pub comp_types_by_uuid: HashMap<type_uuid::Bytes, ComponentRegistration>,
|
||||||
pub entity_map: RefCell<HashMap<uuid::Bytes, Entity>>,
|
pub entity_map: RefCell<HashMap<uuid::Bytes, Entity>>,
|
||||||
|
@ -346,8 +346,8 @@ pub struct DeserializeImpl {
|
||||||
|
|
||||||
impl DeserializeImpl {
|
impl DeserializeImpl {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
component_types: HashMap<String, ComponentRegistration>,
|
component_types: HashMap<TypeId, ComponentRegistration>,
|
||||||
tag_types: HashMap<String, TagRegistration>,
|
tag_types: HashMap<TypeId, TagRegistration>,
|
||||||
entity_map: RefCell<HashMap<Entity, uuid::Bytes>>,
|
entity_map: RefCell<HashMap<Entity, uuid::Bytes>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
DeserializeImpl {
|
DeserializeImpl {
|
||||||
|
@ -372,7 +372,7 @@ impl DeserializeImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl legion::de::WorldDeserializer for DeserializeImpl {
|
impl legion::serialize::de::WorldDeserializer for DeserializeImpl {
|
||||||
fn deserialize_archetype_description<'de, D: Deserializer<'de>>(
|
fn deserialize_archetype_description<'de, D: Deserializer<'de>>(
|
||||||
&self,
|
&self,
|
||||||
deserializer: D,
|
deserializer: D,
|
||||||
|
@ -399,7 +399,7 @@ impl legion::de::WorldDeserializer for DeserializeImpl {
|
||||||
_component_meta: &ComponentMeta,
|
_component_meta: &ComponentMeta,
|
||||||
get_next_storage_fn: &mut dyn FnMut() -> Option<(NonNull<u8>, usize)>,
|
get_next_storage_fn: &mut dyn FnMut() -> Option<(NonNull<u8>, usize)>,
|
||||||
) -> Result<(), <D as Deserializer<'de>>::Error> {
|
) -> Result<(), <D as Deserializer<'de>>::Error> {
|
||||||
if let Some(reg) = self.comp_types.get(component_type.0) {
|
if let Some(reg) = self.comp_types.get(&component_type.0) {
|
||||||
let mut erased = erased_serde::Deserializer::erase(deserializer);
|
let mut erased = erased_serde::Deserializer::erase(deserializer);
|
||||||
(reg.comp_deserialize_fn)(&mut erased, get_next_storage_fn)
|
(reg.comp_deserialize_fn)(&mut erased, get_next_storage_fn)
|
||||||
.map_err(<<D as serde::Deserializer<'de>>::Error as serde::de::Error>::custom)?;
|
.map_err(<<D as serde::Deserializer<'de>>::Error as serde::de::Error>::custom)?;
|
||||||
|
@ -415,7 +415,7 @@ impl legion::de::WorldDeserializer for DeserializeImpl {
|
||||||
_tag_meta: &TagMeta,
|
_tag_meta: &TagMeta,
|
||||||
tags: &mut TagStorage,
|
tags: &mut TagStorage,
|
||||||
) -> Result<(), <D as Deserializer<'de>>::Error> {
|
) -> Result<(), <D as Deserializer<'de>>::Error> {
|
||||||
if let Some(reg) = self.tag_types.get(tag_type.0) {
|
if let Some(reg) = self.tag_types.get(&tag_type.0) {
|
||||||
let mut erased = erased_serde::Deserializer::erase(deserializer);
|
let mut erased = erased_serde::Deserializer::erase(deserializer);
|
||||||
(reg.tag_deserialize_fn)(&mut erased, tags)
|
(reg.tag_deserialize_fn)(&mut erased, tags)
|
||||||
.map_err(<<D as serde::Deserializer<'de>>::Error as serde::de::Error>::custom)?;
|
.map_err(<<D as serde::Deserializer<'de>>::Error as serde::de::Error>::custom)?;
|
||||||
|
|
Loading…
Reference in a new issue