From 9e5f4aeefc11908ca971e60a4d4777003a5fb4a2 Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Sun, 23 Feb 2020 23:50:44 -0800 Subject: [PATCH] implement Copy for Handle --- examples/custom_shader.rs | 2 +- examples/entity_builder_comparison.rs | 6 +++--- examples/instancing.rs | 2 +- examples/parenting.rs | 4 ++-- .../plugin_loading/example_plugin/src/lib.rs | 2 +- examples/simple.rs | 4 ++-- examples/spawner.rs | 8 ++++---- examples/texture.rs | 2 +- examples/ui.rs | 2 +- src/asset/mod.rs | 2 +- src/render/render_graph/renderable.rs | 16 ++++++++-------- .../render_graph/renderers/wgpu_renderer.rs | 2 +- .../uniform_resource_provider.rs | 2 +- 13 files changed, 27 insertions(+), 27 deletions(-) diff --git a/examples/custom_shader.rs b/examples/custom_shader.rs index cfaab23c1c..cf829d60ef 100644 --- a/examples/custom_shader.rs +++ b/examples/custom_shader.rs @@ -83,7 +83,7 @@ fn setup(world: &mut World) { .build() // cube .add_archetype(MeshMaterialEntity:: { - mesh: cube_handle.clone(), + mesh: cube_handle, renderable: Renderable { pipelines: vec![Handle::new(2)], // TODO: make this pipeline assignment cleaner ..Default::default() diff --git a/examples/entity_builder_comparison.rs b/examples/entity_builder_comparison.rs index 8226eafafe..5697a6a6dd 100644 --- a/examples/entity_builder_comparison.rs +++ b/examples/entity_builder_comparison.rs @@ -14,7 +14,7 @@ fn create_entities_insert_vec( world.insert( (), vec![( - plane_handle.clone(), + plane_handle, StandardMaterial { albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(), }, @@ -77,7 +77,7 @@ fn create_entities_builder_add_component( .build() // plane .build_entity() - .add(plane_handle.clone()) + .add(plane_handle) .add(StandardMaterial { albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(), }) @@ -123,7 +123,7 @@ fn create_entities_builder_archetype( .build() // plane .add_archetype(MeshEntity { - mesh: plane_handle.clone(), + mesh: plane_handle, material: StandardMaterial { albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(), }, diff --git a/examples/instancing.rs b/examples/instancing.rs index 9e74418be8..935c7723a7 100644 --- a/examples/instancing.rs +++ b/examples/instancing.rs @@ -74,7 +74,7 @@ fn setup(world: &mut World) { for _ in 0..70000 { create_person( world, - cube_handle.clone(), + cube_handle, Translation::new(rng.gen_range(-50.0, 50.0), 0.0, rng.gen_range(-50.0, 50.0)), ); } diff --git a/examples/parenting.rs b/examples/parenting.rs index d515e72771..d9d9d0e808 100644 --- a/examples/parenting.rs +++ b/examples/parenting.rs @@ -34,7 +34,7 @@ fn setup(world: &mut World) { world.insert( (), vec![( - plane_handle.clone(), + plane_handle, StandardMaterial { albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(), }, @@ -48,7 +48,7 @@ fn setup(world: &mut World) { .insert( (), vec![( - cube_handle.clone(), + cube_handle, StandardMaterial { albedo: math::vec4(0.5, 0.3, 0.3, 1.0).into(), }, diff --git a/examples/plugin_loading/example_plugin/src/lib.rs b/examples/plugin_loading/example_plugin/src/lib.rs index f1bcff70c6..21246ef1a3 100644 --- a/examples/plugin_loading/example_plugin/src/lib.rs +++ b/examples/plugin_loading/example_plugin/src/lib.rs @@ -26,7 +26,7 @@ pub fn setup(world: &mut World) { world.build() // plane .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))), local_to_world: LocalToWorld::identity(), translation: Translation::new(0.0, 0.0, 0.0), diff --git a/examples/simple.rs b/examples/simple.rs index 71f1cd93e5..a331910146 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -17,7 +17,7 @@ fn setup(world: &mut World) { .build() // plane .add_archetype(MeshEntity { - mesh: plane_handle.clone(), + mesh: plane_handle, material: StandardMaterial { albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(), }, @@ -25,7 +25,7 @@ fn setup(world: &mut World) { }) // cube .add_archetype(MeshEntity { - mesh: cube_handle.clone(), + mesh: cube_handle, material: StandardMaterial { albedo: math::vec4(0.5, 0.4, 0.3, 1.0).into(), }, diff --git a/examples/spawner.rs b/examples/spawner.rs index 7f5f1aa7c7..36bf641de6 100644 --- a/examples/spawner.rs +++ b/examples/spawner.rs @@ -74,7 +74,7 @@ fn setup(world: &mut World) { .build() // plane .add_archetype(MeshEntity { - mesh: plane_handle.clone(), + mesh: plane_handle, material: StandardMaterial { albedo: math::vec4(0.1, 0.2, 0.1, 1.0).into(), }, @@ -82,7 +82,7 @@ fn setup(world: &mut World) { }) // cube .add_archetype(MeshEntity { - mesh: cube_handle.clone(), + mesh: cube_handle, material: StandardMaterial { albedo: math::vec4(1.0, 1.0, 1.0, 1.0).into(), }, @@ -90,7 +90,7 @@ fn setup(world: &mut World) { ..Default::default() }) .add_archetype(MeshEntity { - mesh: cube_handle.clone(), + mesh: cube_handle, material: StandardMaterial { 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(); for _ in 0..10000 { builder = builder.add_archetype(MeshEntity { - mesh: cube_handle.clone(), + mesh: cube_handle, material: StandardMaterial { albedo: math::vec4( rng.gen_range(0.0, 1.0), diff --git a/examples/texture.rs b/examples/texture.rs index 892f6e8654..1cb253fb7c 100644 --- a/examples/texture.rs +++ b/examples/texture.rs @@ -20,7 +20,7 @@ fn setup(world: &mut World) { .build() // cube .add_archetype(MeshEntity { - mesh: cube_handle.clone(), + mesh: cube_handle, material: StandardMaterial { albedo: texture_handle.into(), }, diff --git a/examples/ui.rs b/examples/ui.rs index 5439638475..62743947a7 100644 --- a/examples/ui.rs +++ b/examples/ui.rs @@ -15,7 +15,7 @@ fn setup(world: &mut World) { .build() // cube .add_archetype(MeshEntity { - mesh: cube_handle.clone(), + mesh: cube_handle, material: StandardMaterial { albedo: math::vec4(0.5, 0.3, 0.3, 1.0).into(), }, diff --git a/src/asset/mod.rs b/src/asset/mod.rs index 8004ad6443..7ba20c9883 100644 --- a/src/asset/mod.rs +++ b/src/asset/mod.rs @@ -12,7 +12,6 @@ pub use texture::*; use std::{collections::HashMap, marker::PhantomData}; -#[derive(Copy)] pub struct Handle { pub id: usize, marker: PhantomData, @@ -58,6 +57,7 @@ impl Default for Handle { } } +impl Copy for Handle {} impl Clone for Handle { fn clone(&self) -> Self { Handle { diff --git a/src/render/render_graph/renderable.rs b/src/render/render_graph/renderable.rs index 29d74011c5..95eeef32f5 100644 --- a/src/render/render_graph/renderable.rs +++ b/src/render/render_graph/renderable.rs @@ -64,7 +64,7 @@ fn try_compiling_shader_with_macros( if let None = compiled_shader_map.source_to_compiled.get(shader_handle) { compiled_shader_map .source_to_compiled - .insert(shader_handle.clone(), Vec::new()); + .insert(*shader_handle, Vec::new()); } let compiled_shaders = compiled_shader_map @@ -90,7 +90,7 @@ fn try_compiling_shader_with_macros( .cloned() .collect::>(); 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); Some(compiled_shader_handle) } @@ -121,7 +121,7 @@ pub fn update_shader_assignments(world: &mut World, render_graph: &mut RenderGra { compiled_shader_map .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)) = @@ -133,7 +133,7 @@ pub fn update_shader_assignments(world: &mut World, render_graph: &mut RenderGra .find(|(shader_defs, _macroed_pipeline_handle)| { *shader_defs == renderable.shader_defs }) { - macroed_pipeline_handle.clone() + *macroed_pipeline_handle } else { let pipeline_descriptor = 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 render_graph.add_pipeline( resource_name::pass::MAIN, - macroed_pipeline_handle.clone(), + macroed_pipeline_handle, ); macroed_pipeline_handle } else { - pipeline_handle.clone() + *pipeline_handle } }; @@ -186,7 +186,7 @@ pub fn update_shader_assignments(world: &mut World, render_graph: &mut RenderGra .unwrap(); macro_pipelines.push(( renderable.shader_defs.clone(), - macroed_pipeline_handle.clone(), + 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) { shader_pipeline_assignments .assignments - .insert(final_handle.clone(), Vec::new()); + .insert(final_handle, Vec::new()); } let assignments = shader_pipeline_assignments diff --git a/src/render/render_graph/renderers/wgpu_renderer.rs b/src/render/render_graph/renderers/wgpu_renderer.rs index cb1e9fed5f..21e9687316 100644 --- a/src/render/render_graph/renderers/wgpu_renderer.rs +++ b/src/render/render_graph/renderers/wgpu_renderer.rs @@ -529,7 +529,7 @@ impl Renderer for WgpuRenderer { fragment_shader, ); self.render_pipelines - .insert(pipeline_descriptor_handle.clone(), render_pipeline); + .insert(*pipeline_descriptor_handle, render_pipeline); } // create bind groups diff --git a/src/render/render_graph/resource_providers/uniform_resource_provider.rs b/src/render/render_graph/resource_providers/uniform_resource_provider.rs index 1944e0c512..28887e4e4f 100644 --- a/src/render/render_graph/resource_providers/uniform_resource_provider.rs +++ b/src/render/render_graph/resource_providers/uniform_resource_provider.rs @@ -75,7 +75,7 @@ where uniforms.get_uniform_texture(&uniform_info.name).unwrap(); let storage = world.resources.get::>().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 resource = renderer.create_texture(&descriptor, Some(&texture.data));