mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
implement Copy for Handle
This commit is contained in:
parent
1a4bd98434
commit
9e5f4aeefc
13 changed files with 27 additions and 27 deletions
|
@ -83,7 +83,7 @@ fn setup(world: &mut World) {
|
||||||
.build()
|
.build()
|
||||||
// cube
|
// cube
|
||||||
.add_archetype(MeshMaterialEntity::<MyMaterial> {
|
.add_archetype(MeshMaterialEntity::<MyMaterial> {
|
||||||
mesh: cube_handle.clone(),
|
mesh: cube_handle,
|
||||||
renderable: Renderable {
|
renderable: Renderable {
|
||||||
pipelines: vec![Handle::new(2)], // TODO: make this pipeline assignment cleaner
|
pipelines: vec![Handle::new(2)], // TODO: make this pipeline assignment cleaner
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
|
@ -14,7 +14,7 @@ fn create_entities_insert_vec(
|
||||||
world.insert(
|
world.insert(
|
||||||
(),
|
(),
|
||||||
vec![(
|
vec![(
|
||||||
plane_handle.clone(),
|
plane_handle,
|
||||||
StandardMaterial {
|
StandardMaterial {
|
||||||
albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(),
|
albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(),
|
||||||
},
|
},
|
||||||
|
@ -77,7 +77,7 @@ fn create_entities_builder_add_component(
|
||||||
.build()
|
.build()
|
||||||
// plane
|
// plane
|
||||||
.build_entity()
|
.build_entity()
|
||||||
.add(plane_handle.clone())
|
.add(plane_handle)
|
||||||
.add(StandardMaterial {
|
.add(StandardMaterial {
|
||||||
albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(),
|
albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(),
|
||||||
})
|
})
|
||||||
|
@ -123,7 +123,7 @@ fn create_entities_builder_archetype(
|
||||||
.build()
|
.build()
|
||||||
// plane
|
// plane
|
||||||
.add_archetype(MeshEntity {
|
.add_archetype(MeshEntity {
|
||||||
mesh: plane_handle.clone(),
|
mesh: plane_handle,
|
||||||
material: StandardMaterial {
|
material: StandardMaterial {
|
||||||
albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(),
|
albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(),
|
||||||
},
|
},
|
||||||
|
|
|
@ -74,7 +74,7 @@ fn setup(world: &mut World) {
|
||||||
for _ in 0..70000 {
|
for _ in 0..70000 {
|
||||||
create_person(
|
create_person(
|
||||||
world,
|
world,
|
||||||
cube_handle.clone(),
|
cube_handle,
|
||||||
Translation::new(rng.gen_range(-50.0, 50.0), 0.0, rng.gen_range(-50.0, 50.0)),
|
Translation::new(rng.gen_range(-50.0, 50.0), 0.0, rng.gen_range(-50.0, 50.0)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ fn setup(world: &mut World) {
|
||||||
world.insert(
|
world.insert(
|
||||||
(),
|
(),
|
||||||
vec![(
|
vec![(
|
||||||
plane_handle.clone(),
|
plane_handle,
|
||||||
StandardMaterial {
|
StandardMaterial {
|
||||||
albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(),
|
albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(),
|
||||||
},
|
},
|
||||||
|
@ -48,7 +48,7 @@ fn setup(world: &mut World) {
|
||||||
.insert(
|
.insert(
|
||||||
(),
|
(),
|
||||||
vec![(
|
vec![(
|
||||||
cube_handle.clone(),
|
cube_handle,
|
||||||
StandardMaterial {
|
StandardMaterial {
|
||||||
albedo: math::vec4(0.5, 0.3, 0.3, 1.0).into(),
|
albedo: math::vec4(0.5, 0.3, 0.3, 1.0).into(),
|
||||||
},
|
},
|
||||||
|
|
|
@ -26,7 +26,7 @@ pub fn setup(world: &mut World) {
|
||||||
world.build()
|
world.build()
|
||||||
// plane
|
// plane
|
||||||
.add_archetype(NewMeshEntity {
|
.add_archetype(NewMeshEntity {
|
||||||
mesh: plane_handle.clone(),
|
mesh: plane_handle,
|
||||||
material: Material::new(Albedo::Color(math::vec4(0.1, 0.2, 0.1, 1.0))),
|
material: Material::new(Albedo::Color(math::vec4(0.1, 0.2, 0.1, 1.0))),
|
||||||
local_to_world: LocalToWorld::identity(),
|
local_to_world: LocalToWorld::identity(),
|
||||||
translation: Translation::new(0.0, 0.0, 0.0),
|
translation: Translation::new(0.0, 0.0, 0.0),
|
||||||
|
|
|
@ -17,7 +17,7 @@ fn setup(world: &mut World) {
|
||||||
.build()
|
.build()
|
||||||
// plane
|
// plane
|
||||||
.add_archetype(MeshEntity {
|
.add_archetype(MeshEntity {
|
||||||
mesh: plane_handle.clone(),
|
mesh: plane_handle,
|
||||||
material: StandardMaterial {
|
material: StandardMaterial {
|
||||||
albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(),
|
albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(),
|
||||||
},
|
},
|
||||||
|
@ -25,7 +25,7 @@ fn setup(world: &mut World) {
|
||||||
})
|
})
|
||||||
// cube
|
// cube
|
||||||
.add_archetype(MeshEntity {
|
.add_archetype(MeshEntity {
|
||||||
mesh: cube_handle.clone(),
|
mesh: cube_handle,
|
||||||
material: StandardMaterial {
|
material: StandardMaterial {
|
||||||
albedo: math::vec4(0.5, 0.4, 0.3, 1.0).into(),
|
albedo: math::vec4(0.5, 0.4, 0.3, 1.0).into(),
|
||||||
},
|
},
|
||||||
|
|
|
@ -74,7 +74,7 @@ fn setup(world: &mut World) {
|
||||||
.build()
|
.build()
|
||||||
// plane
|
// plane
|
||||||
.add_archetype(MeshEntity {
|
.add_archetype(MeshEntity {
|
||||||
mesh: plane_handle.clone(),
|
mesh: plane_handle,
|
||||||
material: StandardMaterial {
|
material: StandardMaterial {
|
||||||
albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(),
|
albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(),
|
||||||
},
|
},
|
||||||
|
@ -82,7 +82,7 @@ fn setup(world: &mut World) {
|
||||||
})
|
})
|
||||||
// cube
|
// cube
|
||||||
.add_archetype(MeshEntity {
|
.add_archetype(MeshEntity {
|
||||||
mesh: cube_handle.clone(),
|
mesh: cube_handle,
|
||||||
material: StandardMaterial {
|
material: StandardMaterial {
|
||||||
albedo: math::vec4(1.0, 1.0, 1.0, 1.0).into(),
|
albedo: math::vec4(1.0, 1.0, 1.0, 1.0).into(),
|
||||||
},
|
},
|
||||||
|
@ -90,7 +90,7 @@ fn setup(world: &mut World) {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.add_archetype(MeshEntity {
|
.add_archetype(MeshEntity {
|
||||||
mesh: cube_handle.clone(),
|
mesh: cube_handle,
|
||||||
material: StandardMaterial {
|
material: StandardMaterial {
|
||||||
albedo: math::vec4(0.0, 1.0, 0.0, 1.0).into(),
|
albedo: math::vec4(0.0, 1.0, 0.0, 1.0).into(),
|
||||||
},
|
},
|
||||||
|
@ -121,7 +121,7 @@ fn setup(world: &mut World) {
|
||||||
let mut rng = StdRng::from_entropy();
|
let mut rng = StdRng::from_entropy();
|
||||||
for _ in 0..10000 {
|
for _ in 0..10000 {
|
||||||
builder = builder.add_archetype(MeshEntity {
|
builder = builder.add_archetype(MeshEntity {
|
||||||
mesh: cube_handle.clone(),
|
mesh: cube_handle,
|
||||||
material: StandardMaterial {
|
material: StandardMaterial {
|
||||||
albedo: math::vec4(
|
albedo: math::vec4(
|
||||||
rng.gen_range(0.0, 1.0),
|
rng.gen_range(0.0, 1.0),
|
||||||
|
|
|
@ -20,7 +20,7 @@ fn setup(world: &mut World) {
|
||||||
.build()
|
.build()
|
||||||
// cube
|
// cube
|
||||||
.add_archetype(MeshEntity {
|
.add_archetype(MeshEntity {
|
||||||
mesh: cube_handle.clone(),
|
mesh: cube_handle,
|
||||||
material: StandardMaterial {
|
material: StandardMaterial {
|
||||||
albedo: texture_handle.into(),
|
albedo: texture_handle.into(),
|
||||||
},
|
},
|
||||||
|
|
|
@ -15,7 +15,7 @@ fn setup(world: &mut World) {
|
||||||
.build()
|
.build()
|
||||||
// cube
|
// cube
|
||||||
.add_archetype(MeshEntity {
|
.add_archetype(MeshEntity {
|
||||||
mesh: cube_handle.clone(),
|
mesh: cube_handle,
|
||||||
material: StandardMaterial {
|
material: StandardMaterial {
|
||||||
albedo: math::vec4(0.5, 0.3, 0.3, 1.0).into(),
|
albedo: math::vec4(0.5, 0.3, 0.3, 1.0).into(),
|
||||||
},
|
},
|
||||||
|
|
|
@ -12,7 +12,6 @@ pub use texture::*;
|
||||||
|
|
||||||
use std::{collections::HashMap, marker::PhantomData};
|
use std::{collections::HashMap, marker::PhantomData};
|
||||||
|
|
||||||
#[derive(Copy)]
|
|
||||||
pub struct Handle<T> {
|
pub struct Handle<T> {
|
||||||
pub id: usize,
|
pub id: usize,
|
||||||
marker: PhantomData<T>,
|
marker: PhantomData<T>,
|
||||||
|
@ -58,6 +57,7 @@ impl<T> Default for Handle<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> Copy for Handle<T> {}
|
||||||
impl<T> Clone for Handle<T> {
|
impl<T> Clone for Handle<T> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Handle {
|
Handle {
|
||||||
|
|
|
@ -64,7 +64,7 @@ fn try_compiling_shader_with_macros(
|
||||||
if let None = compiled_shader_map.source_to_compiled.get(shader_handle) {
|
if let None = compiled_shader_map.source_to_compiled.get(shader_handle) {
|
||||||
compiled_shader_map
|
compiled_shader_map
|
||||||
.source_to_compiled
|
.source_to_compiled
|
||||||
.insert(shader_handle.clone(), Vec::new());
|
.insert(*shader_handle, Vec::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
let compiled_shaders = compiled_shader_map
|
let compiled_shaders = compiled_shader_map
|
||||||
|
@ -90,7 +90,7 @@ fn try_compiling_shader_with_macros(
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect::<Vec<String>>();
|
.collect::<Vec<String>>();
|
||||||
let compiled_shader = shader.get_spirv_shader(Some(&shader_def_vec));
|
let compiled_shader = shader.get_spirv_shader(Some(&shader_def_vec));
|
||||||
compiled_shaders.push((renderable.shader_defs.clone(), shader_handle.clone()));
|
compiled_shaders.push((renderable.shader_defs.clone(), *shader_handle));
|
||||||
let compiled_shader_handle = shader_storage.add(compiled_shader);
|
let compiled_shader_handle = shader_storage.add(compiled_shader);
|
||||||
Some(compiled_shader_handle)
|
Some(compiled_shader_handle)
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ pub fn update_shader_assignments(world: &mut World, render_graph: &mut RenderGra
|
||||||
{
|
{
|
||||||
compiled_shader_map
|
compiled_shader_map
|
||||||
.pipeline_to_macro_pipelines
|
.pipeline_to_macro_pipelines
|
||||||
.insert(pipeline_handle.clone(), Vec::new());
|
.insert(*pipeline_handle, Vec::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
let final_handle = if let Some((_shader_defs, macroed_pipeline_handle)) =
|
let final_handle = if let Some((_shader_defs, macroed_pipeline_handle)) =
|
||||||
|
@ -133,7 +133,7 @@ pub fn update_shader_assignments(world: &mut World, render_graph: &mut RenderGra
|
||||||
.find(|(shader_defs, _macroed_pipeline_handle)| {
|
.find(|(shader_defs, _macroed_pipeline_handle)| {
|
||||||
*shader_defs == renderable.shader_defs
|
*shader_defs == renderable.shader_defs
|
||||||
}) {
|
}) {
|
||||||
macroed_pipeline_handle.clone()
|
*macroed_pipeline_handle
|
||||||
} else {
|
} else {
|
||||||
let pipeline_descriptor =
|
let pipeline_descriptor =
|
||||||
pipeline_descriptor_storage.get(pipeline_handle).unwrap();
|
pipeline_descriptor_storage.get(pipeline_handle).unwrap();
|
||||||
|
@ -172,11 +172,11 @@ pub fn update_shader_assignments(world: &mut World, render_graph: &mut RenderGra
|
||||||
// TODO: get correct pass name
|
// TODO: get correct pass name
|
||||||
render_graph.add_pipeline(
|
render_graph.add_pipeline(
|
||||||
resource_name::pass::MAIN,
|
resource_name::pass::MAIN,
|
||||||
macroed_pipeline_handle.clone(),
|
macroed_pipeline_handle,
|
||||||
);
|
);
|
||||||
macroed_pipeline_handle
|
macroed_pipeline_handle
|
||||||
} else {
|
} else {
|
||||||
pipeline_handle.clone()
|
*pipeline_handle
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ pub fn update_shader_assignments(world: &mut World, render_graph: &mut RenderGra
|
||||||
.unwrap();
|
.unwrap();
|
||||||
macro_pipelines.push((
|
macro_pipelines.push((
|
||||||
renderable.shader_defs.clone(),
|
renderable.shader_defs.clone(),
|
||||||
macroed_pipeline_handle.clone(),
|
macroed_pipeline_handle,
|
||||||
));
|
));
|
||||||
macroed_pipeline_handle
|
macroed_pipeline_handle
|
||||||
};
|
};
|
||||||
|
@ -195,7 +195,7 @@ pub fn update_shader_assignments(world: &mut World, render_graph: &mut RenderGra
|
||||||
if let None = shader_pipeline_assignments.assignments.get(&final_handle) {
|
if let None = shader_pipeline_assignments.assignments.get(&final_handle) {
|
||||||
shader_pipeline_assignments
|
shader_pipeline_assignments
|
||||||
.assignments
|
.assignments
|
||||||
.insert(final_handle.clone(), Vec::new());
|
.insert(final_handle, Vec::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
let assignments = shader_pipeline_assignments
|
let assignments = shader_pipeline_assignments
|
||||||
|
|
|
@ -529,7 +529,7 @@ impl Renderer for WgpuRenderer {
|
||||||
fragment_shader,
|
fragment_shader,
|
||||||
);
|
);
|
||||||
self.render_pipelines
|
self.render_pipelines
|
||||||
.insert(pipeline_descriptor_handle.clone(), render_pipeline);
|
.insert(*pipeline_descriptor_handle, render_pipeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create bind groups
|
// create bind groups
|
||||||
|
|
|
@ -75,7 +75,7 @@ where
|
||||||
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 = world.resources.get::<AssetStorage<Texture>>().unwrap();
|
||||||
let texture = storage.get(&texture_handle).unwrap();
|
let texture = storage.get(&texture_handle).unwrap();
|
||||||
if let None = renderer.get_texture_resource(texture_handle.clone()) {
|
if let None = renderer.get_texture_resource(texture_handle) {
|
||||||
let descriptor: TextureDescriptor = texture.into();
|
let descriptor: TextureDescriptor = texture.into();
|
||||||
let resource =
|
let resource =
|
||||||
renderer.create_texture(&descriptor, Some(&texture.data));
|
renderer.create_texture(&descriptor, Some(&texture.data));
|
||||||
|
|
Loading…
Reference in a new issue