mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
Rename AssetStorage to Assets
This commit is contained in:
parent
b58db0749e
commit
70f122b92a
30 changed files with 138 additions and 138 deletions
|
@ -10,15 +10,15 @@ pub enum AssetEvent<T> {
|
|||
Created { handle: Handle<T> },
|
||||
}
|
||||
|
||||
pub struct AssetStorage<T> {
|
||||
pub struct Assets<T> {
|
||||
assets: HashMap<HandleId, T>,
|
||||
names: HashMap<String, Handle<T>>,
|
||||
events: Events<AssetEvent<T>>,
|
||||
}
|
||||
|
||||
impl<T> Default for AssetStorage<T> {
|
||||
impl<T> Default for Assets<T> {
|
||||
fn default() -> Self {
|
||||
AssetStorage {
|
||||
Assets {
|
||||
assets: HashMap::default(),
|
||||
names: HashMap::default(),
|
||||
events: Events::default(),
|
||||
|
@ -26,7 +26,7 @@ impl<T> Default for AssetStorage<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> AssetStorage<T> {
|
||||
impl<T> Assets<T> {
|
||||
pub fn get_named(&mut self, name: &str) -> Option<Handle<T>> {
|
||||
self.names.get(name).map(|handle| *handle)
|
||||
}
|
||||
|
@ -77,9 +77,9 @@ impl<T> AssetStorage<T> {
|
|||
|
||||
pub fn asset_event_system(
|
||||
mut events: ResourceMut<Events<AssetEvent<T>>>,
|
||||
mut storage: ResourceMut<AssetStorage<T>>,
|
||||
mut assets: ResourceMut<Assets<T>>,
|
||||
) {
|
||||
events.extend(storage.events.drain())
|
||||
events.extend(assets.events.drain())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,10 +104,10 @@ impl AddAsset for AppBuilder {
|
|||
where
|
||||
T: Send + Sync + 'static,
|
||||
{
|
||||
self.init_resource::<AssetStorage<T>>()
|
||||
self.init_resource::<Assets<T>>()
|
||||
.add_system_to_stage(
|
||||
stage::EVENT_UPDATE,
|
||||
AssetStorage::<T>::asset_event_system.system(),
|
||||
Assets::<T>::asset_event_system.system(),
|
||||
)
|
||||
.add_event::<AssetEvent<T>>()
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{material::StandardMaterial, nodes::LightsNode, pipelines::build_forward_pipeline};
|
||||
use bevy_asset::AssetStorage;
|
||||
use bevy_asset::Assets;
|
||||
use bevy_render::{
|
||||
base_render_graph,
|
||||
draw_target::AssignedMeshesDrawTarget,
|
||||
|
@ -36,9 +36,9 @@ impl ForwardPbrRenderGraphBuilder for RenderGraph {
|
|||
resources,
|
||||
);
|
||||
self.add_system_node_named(node::LIGHTS, LightsNode::new(10), resources);
|
||||
let mut shaders = resources.get_mut::<AssetStorage<Shader>>().unwrap();
|
||||
let mut shaders = resources.get_mut::<Assets<Shader>>().unwrap();
|
||||
let mut pipelines = resources
|
||||
.get_mut::<AssetStorage<PipelineDescriptor>>()
|
||||
.get_mut::<Assets<PipelineDescriptor>>()
|
||||
.unwrap();
|
||||
{
|
||||
let main_pass: &mut PassNode = self
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use bevy_asset::AssetStorage;
|
||||
use bevy_asset::Assets;
|
||||
use bevy_render::{
|
||||
pipeline::{
|
||||
state_descriptors::{
|
||||
|
@ -12,7 +12,7 @@ use bevy_render::{
|
|||
texture::TextureFormat,
|
||||
};
|
||||
|
||||
pub fn build_forward_pipeline(shaders: &mut AssetStorage<Shader>) -> PipelineDescriptor {
|
||||
pub fn build_forward_pipeline(shaders: &mut Assets<Shader>) -> PipelineDescriptor {
|
||||
PipelineDescriptor {
|
||||
rasterization_state: Some(RasterizationStateDescriptor {
|
||||
front_face: FrontFace::Ccw,
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
|||
shader::AsUniforms,
|
||||
Renderable, Vertex,
|
||||
};
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use bevy_asset::{Assets, Handle};
|
||||
use glam::*;
|
||||
use legion::prelude::*;
|
||||
use std::borrow::Cow;
|
||||
|
@ -312,7 +312,7 @@ pub mod shape {
|
|||
|
||||
pub fn mesh_specializer_system() -> Box<dyn Schedulable> {
|
||||
SystemBuilder::new("mesh_specializer")
|
||||
.read_resource::<AssetStorage<Mesh>>()
|
||||
.read_resource::<Assets<Mesh>>()
|
||||
.with_query(
|
||||
<(Read<Handle<Mesh>>, Write<Renderable>)>::query()
|
||||
.filter(changed::<Handle<Mesh>>() | changed::<Renderable>()),
|
||||
|
@ -333,7 +333,7 @@ fn setup_mesh_resource(
|
|||
render_resource_assignments: &mut RenderResourceAssignments,
|
||||
vertex_buffer_descriptor: &VertexBufferDescriptor,
|
||||
handle: Handle<Mesh>,
|
||||
meshes: &AssetStorage<Mesh>,
|
||||
meshes: &Assets<Mesh>,
|
||||
) {
|
||||
log::trace!("setup mesh for {:?}", render_resource_assignments.id);
|
||||
let index_format = IndexFormat::Uint16;
|
||||
|
@ -381,7 +381,7 @@ pub fn mesh_resource_provider_system(resources: &mut Resources) -> Box<dyn Sched
|
|||
vertex_buffer_descriptors.set(vertex_buffer_descriptor.clone());
|
||||
SystemBuilder::new("mesh_resource_provider")
|
||||
.read_resource::<RenderResources>()
|
||||
.read_resource::<AssetStorage<Mesh>>()
|
||||
.read_resource::<Assets<Mesh>>()
|
||||
.with_query(<(Read<Handle<Mesh>>, Write<Renderable>)>::query())
|
||||
.build(
|
||||
move |_, world, (render_resource_context, meshes /* asset_batchers*/), query| {
|
||||
|
|
|
@ -11,7 +11,7 @@ use crate::{
|
|||
shader::{Shader, ShaderStages},
|
||||
texture::TextureFormat,
|
||||
};
|
||||
use bevy_asset::AssetStorage;
|
||||
use bevy_asset::Assets;
|
||||
|
||||
// TODO: consider removing this in favor of Option<Layout>
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -145,7 +145,7 @@ impl PipelineDescriptor {
|
|||
/// render resource.
|
||||
pub fn reflect_layout(
|
||||
&mut self,
|
||||
shaders: &AssetStorage<Shader>,
|
||||
shaders: &Assets<Shader>,
|
||||
bevy_conventions: bool,
|
||||
vertex_buffer_descriptors: Option<&VertexBufferDescriptors>,
|
||||
render_resource_assignments: Option<&RenderResourceAssignments>,
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
|||
shader::{Shader, ShaderSource},
|
||||
Renderable,
|
||||
};
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use bevy_asset::{Assets, Handle};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use legion::prelude::*;
|
||||
|
@ -34,7 +34,7 @@ pub struct PipelineCompiler {
|
|||
impl PipelineCompiler {
|
||||
fn compile_shader(
|
||||
&mut self,
|
||||
shader_storage: &mut AssetStorage<Shader>,
|
||||
shaders: &mut Assets<Shader>,
|
||||
shader_handle: &Handle<Shader>,
|
||||
shader_specialization: &ShaderSpecialization,
|
||||
) -> Handle<Shader> {
|
||||
|
@ -43,7 +43,7 @@ impl PipelineCompiler {
|
|||
.entry(*shader_handle)
|
||||
.or_insert_with(|| Vec::new());
|
||||
|
||||
let shader = shader_storage.get(shader_handle).unwrap();
|
||||
let shader = shaders.get(shader_handle).unwrap();
|
||||
|
||||
// don't produce new shader if the input source is already spirv
|
||||
if let ShaderSource::Spirv(_) = shader.source {
|
||||
|
@ -67,7 +67,7 @@ impl PipelineCompiler {
|
|||
.cloned()
|
||||
.collect::<Vec<String>>();
|
||||
let compiled_shader = shader.get_spirv_shader(Some(&shader_def_vec));
|
||||
let compiled_handle = shader_storage.add(compiled_shader);
|
||||
let compiled_handle = shaders.add(compiled_shader);
|
||||
compiled_shaders.push((shader_specialization.clone(), compiled_handle));
|
||||
compiled_handle
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ impl PipelineCompiler {
|
|||
fn compile_pipeline(
|
||||
&mut self,
|
||||
vertex_buffer_descriptors: &VertexBufferDescriptors,
|
||||
shaders: &mut AssetStorage<Shader>,
|
||||
shaders: &mut Assets<Shader>,
|
||||
pipeline_descriptor: &PipelineDescriptor,
|
||||
render_resource_assignments: &RenderResourceAssignments,
|
||||
) -> PipelineDescriptor {
|
||||
|
@ -120,12 +120,12 @@ impl PipelineCompiler {
|
|||
&mut self,
|
||||
vertex_buffer_descriptors: &VertexBufferDescriptors,
|
||||
shader_pipeline_assignments: &mut PipelineAssignments,
|
||||
pipeline_storage: &mut AssetStorage<PipelineDescriptor>,
|
||||
shader_storage: &mut AssetStorage<Shader>,
|
||||
pipelines: &[Handle<PipelineDescriptor>],
|
||||
pipelines: &mut Assets<PipelineDescriptor>,
|
||||
shaders: &mut Assets<Shader>,
|
||||
pipeline_handles: &[Handle<PipelineDescriptor>],
|
||||
render_resource_assignments: &RenderResourceAssignments,
|
||||
) {
|
||||
for pipeline_handle in pipelines.iter() {
|
||||
for pipeline_handle in pipeline_handles.iter() {
|
||||
if let None = self.pipeline_source_to_compiled.get(pipeline_handle) {
|
||||
self.pipeline_source_to_compiled
|
||||
.insert(*pipeline_handle, Vec::new());
|
||||
|
@ -141,14 +141,14 @@ impl PipelineCompiler {
|
|||
}) {
|
||||
*macroed_pipeline_handle
|
||||
} else {
|
||||
let pipeline_descriptor = pipeline_storage.get(pipeline_handle).unwrap();
|
||||
let pipeline_descriptor = pipelines.get(pipeline_handle).unwrap();
|
||||
let compiled_pipeline = self.compile_pipeline(
|
||||
vertex_buffer_descriptors,
|
||||
shader_storage,
|
||||
shaders,
|
||||
pipeline_descriptor,
|
||||
render_resource_assignments,
|
||||
);
|
||||
let compiled_pipeline_handle = pipeline_storage.add(compiled_pipeline);
|
||||
let compiled_pipeline_handle = pipelines.add(compiled_pipeline);
|
||||
|
||||
let macro_pipelines = self
|
||||
.pipeline_source_to_compiled
|
||||
|
@ -211,10 +211,10 @@ pub fn update_shader_assignments(world: &mut World, resources: &Resources) {
|
|||
{
|
||||
let mut shader_pipeline_assignments = resources.get_mut::<PipelineAssignments>().unwrap();
|
||||
let mut pipeline_compiler = resources.get_mut::<PipelineCompiler>().unwrap();
|
||||
let mut shader_storage = resources.get_mut::<AssetStorage<Shader>>().unwrap();
|
||||
let mut shaders = resources.get_mut::<Assets<Shader>>().unwrap();
|
||||
let vertex_buffer_descriptors = resources.get::<VertexBufferDescriptors>().unwrap();
|
||||
let mut pipeline_descriptor_storage = resources
|
||||
.get_mut::<AssetStorage<PipelineDescriptor>>()
|
||||
.get_mut::<Assets<PipelineDescriptor>>()
|
||||
.unwrap();
|
||||
|
||||
// reset assignments so they are updated every frame
|
||||
|
@ -231,7 +231,7 @@ pub fn update_shader_assignments(world: &mut World, resources: &Resources) {
|
|||
&vertex_buffer_descriptors,
|
||||
&mut shader_pipeline_assignments,
|
||||
&mut pipeline_descriptor_storage,
|
||||
&mut shader_storage,
|
||||
&mut shaders,
|
||||
&renderable.pipelines,
|
||||
&renderable.render_resource_assignments,
|
||||
);
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
renderer::RenderContext,
|
||||
shader::{FieldBindType, Shader},
|
||||
};
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use bevy_asset::{Assets, Handle};
|
||||
use legion::prelude::*;
|
||||
|
||||
pub struct PassNode {
|
||||
|
@ -77,7 +77,7 @@ impl Node for PassNode {
|
|||
_output: &mut ResourceSlots,
|
||||
) {
|
||||
let pipeline_compiler = resources.get::<PipelineCompiler>().unwrap();
|
||||
let pipeline_storage = resources.get::<AssetStorage<PipelineDescriptor>>().unwrap();
|
||||
let pipelines = resources.get::<Assets<PipelineDescriptor>>().unwrap();
|
||||
|
||||
for (i, color_attachment) in self.descriptor.color_attachments.iter_mut().enumerate() {
|
||||
if let Some(input_index) = self.color_attachment_input_indices[i] {
|
||||
|
@ -94,14 +94,14 @@ impl Node for PassNode {
|
|||
.attachment = TextureAttachment::RenderResource(input.get(input_index).unwrap());
|
||||
}
|
||||
|
||||
let shader_storage = resources.get::<AssetStorage<Shader>>().unwrap();
|
||||
let shaders = resources.get::<Assets<Shader>>().unwrap();
|
||||
for (pipeline_handle, draw_targets) in self.pipelines.iter_mut() {
|
||||
if let Some(compiled_pipelines_iter) =
|
||||
pipeline_compiler.iter_compiled_pipelines(*pipeline_handle)
|
||||
{
|
||||
for compiled_pipeline_handle in compiled_pipelines_iter {
|
||||
let compiled_pipeline_descriptor =
|
||||
pipeline_storage.get(compiled_pipeline_handle).unwrap();
|
||||
pipelines.get(compiled_pipeline_handle).unwrap();
|
||||
|
||||
let pipeline_layout = compiled_pipeline_descriptor.get_layout().unwrap();
|
||||
{
|
||||
|
@ -117,7 +117,7 @@ impl Node for PassNode {
|
|||
render_context.resources().create_render_pipeline(
|
||||
*compiled_pipeline_handle,
|
||||
&compiled_pipeline_descriptor,
|
||||
&shader_storage,
|
||||
&shaders,
|
||||
);
|
||||
for draw_target in draw_targets.iter_mut() {
|
||||
draw_target.setup(
|
||||
|
@ -143,7 +143,7 @@ impl Node for PassNode {
|
|||
{
|
||||
for compiled_pipeline_handle in compiled_pipelines_iter {
|
||||
let compiled_pipeline_descriptor =
|
||||
pipeline_storage.get(compiled_pipeline_handle).unwrap();
|
||||
pipelines.get(compiled_pipeline_handle).unwrap();
|
||||
render_pass.set_pipeline(*compiled_pipeline_handle);
|
||||
for draw_target in draw_targets.iter() {
|
||||
draw_target.draw(
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::{
|
|||
texture, Renderable,
|
||||
};
|
||||
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use bevy_asset::{Assets, Handle};
|
||||
use legion::prelude::*;
|
||||
use std::{collections::HashMap, marker::PhantomData};
|
||||
use texture::{SamplerDescriptor, Texture, TextureDescriptor};
|
||||
|
@ -400,7 +400,7 @@ where
|
|||
"uniform_resource_provider::<{}>",
|
||||
std::any::type_name::<T>()
|
||||
))
|
||||
.read_resource::<AssetStorage<Texture>>()
|
||||
.read_resource::<Assets<Texture>>()
|
||||
.read_resource::<RenderResources>()
|
||||
// TODO: this write on RenderResourceAssignments will prevent this system from running in parallel with other systems that do the same
|
||||
.with_query(<(Read<T>, Read<Renderable>)>::query())
|
||||
|
@ -555,8 +555,8 @@ where
|
|||
initialize_vertex_buffer_descriptor::<T>(&mut vertex_buffer_descriptors);
|
||||
// TODO: maybe run "update" here
|
||||
SystemBuilder::new("uniform_resource_provider")
|
||||
.read_resource::<AssetStorage<T>>()
|
||||
.read_resource::<AssetStorage<Texture>>()
|
||||
.read_resource::<Assets<T>>()
|
||||
.read_resource::<Assets<Texture>>()
|
||||
.read_resource::<RenderResources>()
|
||||
// TODO: this write on RenderResourceAssignments will prevent this system from running in parallel with other systems that do the same
|
||||
.with_query(<(Read<Handle<T>>, Read<Renderable>)>::query())
|
||||
|
@ -689,7 +689,7 @@ where
|
|||
fn setup_uniform_texture_resources<T>(
|
||||
uniforms: &T,
|
||||
command_queue: &mut CommandQueue,
|
||||
texture_storage: &AssetStorage<Texture>,
|
||||
textures: &Assets<Texture>,
|
||||
render_resource_context: &dyn RenderResourceContext,
|
||||
render_resource_assignments: &mut RenderResourceAssignments,
|
||||
) where
|
||||
|
@ -712,7 +712,7 @@ fn setup_uniform_texture_resources<T>(
|
|||
.unwrap(),
|
||||
),
|
||||
None => {
|
||||
let texture = texture_storage.get(&texture_handle).unwrap();
|
||||
let texture = textures.get(&texture_handle).unwrap();
|
||||
|
||||
let texture_descriptor: TextureDescriptor = texture.into();
|
||||
let texture_resource =
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
shader::Shader,
|
||||
texture::{SamplerDescriptor, TextureDescriptor},
|
||||
};
|
||||
use bevy_asset::{AssetStorage, Handle, HandleUntyped};
|
||||
use bevy_asset::{Assets, Handle, HandleUntyped};
|
||||
use bevy_window::{Window, WindowId};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
|
@ -68,7 +68,7 @@ impl RenderResourceContext for HeadlessRenderResourceContext {
|
|||
fn create_shader_module(
|
||||
&self,
|
||||
_shader_handle: Handle<Shader>,
|
||||
_shader_storage: &AssetStorage<Shader>,
|
||||
_shaders: &Assets<Shader>,
|
||||
) {
|
||||
}
|
||||
fn remove_buffer(&self, resource: RenderResource) {
|
||||
|
@ -113,7 +113,7 @@ impl RenderResourceContext for HeadlessRenderResourceContext {
|
|||
&self,
|
||||
_pipeline_handle: Handle<PipelineDescriptor>,
|
||||
_pipeline_descriptor: &PipelineDescriptor,
|
||||
_shader_storage: &AssetStorage<Shader>,
|
||||
_shaders: &Assets<Shader>,
|
||||
) {
|
||||
}
|
||||
fn create_bind_group(
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
shader::Shader,
|
||||
texture::{SamplerDescriptor, TextureDescriptor},
|
||||
};
|
||||
use bevy_asset::{AssetStorage, Handle, HandleUntyped};
|
||||
use bevy_asset::{Assets, Handle, HandleUntyped};
|
||||
use bevy_window::{Window, WindowId};
|
||||
use downcast_rs::{impl_downcast, Downcast};
|
||||
|
||||
|
@ -43,7 +43,7 @@ pub trait RenderResourceContext: Downcast + Send + Sync + 'static {
|
|||
fn create_shader_module(
|
||||
&self,
|
||||
shader_handle: Handle<Shader>,
|
||||
shader_storage: &AssetStorage<Shader>,
|
||||
shaders: &Assets<Shader>,
|
||||
);
|
||||
fn create_shader_module_from_source(
|
||||
&self,
|
||||
|
@ -73,7 +73,7 @@ pub trait RenderResourceContext: Downcast + Send + Sync + 'static {
|
|||
&self,
|
||||
pipeline_handle: Handle<PipelineDescriptor>,
|
||||
pipeline_descriptor: &PipelineDescriptor,
|
||||
shader_storage: &AssetStorage<Shader>,
|
||||
shaders: &Assets<Shader>,
|
||||
);
|
||||
fn create_bind_group(
|
||||
&self,
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
Renderable,
|
||||
};
|
||||
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use bevy_asset::{Assets, Handle};
|
||||
use bevy_core::bytes::GetBytes;
|
||||
use legion::prelude::*;
|
||||
|
||||
|
@ -34,7 +34,7 @@ where
|
|||
}
|
||||
|
||||
pub fn asset_handle_shader_def_system<T>(
|
||||
asset_storage: Resource<AssetStorage<T>>,
|
||||
assets: Resource<Assets<T>>,
|
||||
asset_handle: Ref<Handle<T>>,
|
||||
mut renderable: RefMut<Renderable>,
|
||||
) where
|
||||
|
@ -44,7 +44,7 @@ pub fn asset_handle_shader_def_system<T>(
|
|||
return;
|
||||
}
|
||||
|
||||
let uniforms = asset_storage.get(&asset_handle).unwrap();
|
||||
let uniforms = assets.get(&asset_handle).unwrap();
|
||||
if let Some(shader_defs) = uniforms.get_shader_defs() {
|
||||
renderable
|
||||
.render_resource_assignments
|
||||
|
|
|
@ -18,7 +18,7 @@ pub use sprite::*;
|
|||
pub use ui_update_system::*;
|
||||
|
||||
use bevy_app::{stage, AppBuilder, AppPlugin};
|
||||
use bevy_asset::{AddAsset, AssetStorage, Handle};
|
||||
use bevy_asset::{AddAsset, Assets, Handle};
|
||||
use bevy_render::{
|
||||
mesh::{shape::Quad, Mesh},
|
||||
render_graph::RenderGraph,
|
||||
|
@ -47,7 +47,7 @@ impl AppPlugin for UiPlugin {
|
|||
let mut render_graph = resources.get_mut::<RenderGraph>().unwrap();
|
||||
render_graph.add_ui_graph(resources);
|
||||
|
||||
let mut meshes = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||
let mut meshes = resources.get_mut::<Assets<Mesh>>().unwrap();
|
||||
meshes.add_with_handle(
|
||||
QUAD_HANDLE,
|
||||
Mesh::from(Quad {
|
||||
|
@ -55,7 +55,7 @@ impl AppPlugin for UiPlugin {
|
|||
}),
|
||||
);
|
||||
|
||||
let mut color_materials = resources.get_mut::<AssetStorage<ColorMaterial>>().unwrap();
|
||||
let mut color_materials = resources.get_mut::<Assets<ColorMaterial>>().unwrap();
|
||||
color_materials.add_default(ColorMaterial::default());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{ColorMaterial, Rect};
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use bevy_asset::{Assets, Handle};
|
||||
use bevy_render::{
|
||||
base_render_graph,
|
||||
draw_target::AssignedMeshesDrawTarget,
|
||||
|
@ -16,7 +16,7 @@ use legion::prelude::Resources;
|
|||
pub const UI_PIPELINE_HANDLE: Handle<PipelineDescriptor> =
|
||||
Handle::from_u128(323432002226399387835192542539754486265);
|
||||
|
||||
pub fn build_ui_pipeline(shaders: &mut AssetStorage<Shader>) -> PipelineDescriptor {
|
||||
pub fn build_ui_pipeline(shaders: &mut Assets<Shader>) -> PipelineDescriptor {
|
||||
PipelineDescriptor {
|
||||
rasterization_state: Some(RasterizationStateDescriptor {
|
||||
front_face: FrontFace::Ccw,
|
||||
|
@ -78,9 +78,9 @@ impl UiRenderGraphBuilder for RenderGraph {
|
|||
self.add_node_edge("rect", base_render_graph::node::MAIN_PASS)
|
||||
.unwrap();
|
||||
let mut pipelines = resources
|
||||
.get_mut::<AssetStorage<PipelineDescriptor>>()
|
||||
.get_mut::<Assets<PipelineDescriptor>>()
|
||||
.unwrap();
|
||||
let mut shaders = resources.get_mut::<AssetStorage<Shader>>().unwrap();
|
||||
let mut shaders = resources.get_mut::<Assets<Shader>>().unwrap();
|
||||
pipelines.add_with_handle(UI_PIPELINE_HANDLE, build_ui_pipeline(&mut shaders));
|
||||
let main_pass: &mut PassNode = self
|
||||
.get_node_mut(base_render_graph::node::MAIN_PASS)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{ColorMaterial, Rect};
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use bevy_asset::{Assets, Handle};
|
||||
use bevy_render::texture::Texture;
|
||||
pub use legion::prelude::*;
|
||||
pub struct Sprite {
|
||||
|
@ -14,8 +14,8 @@ impl Default for Sprite {
|
|||
|
||||
pub fn sprite_system() -> Box<dyn Schedulable> {
|
||||
SystemBuilder::new("sprite_system")
|
||||
.read_resource::<AssetStorage<ColorMaterial>>()
|
||||
.read_resource::<AssetStorage<Texture>>()
|
||||
.read_resource::<Assets<ColorMaterial>>()
|
||||
.read_resource::<Assets<Texture>>()
|
||||
.with_query(
|
||||
<(Read<Sprite>, Read<Handle<ColorMaterial>>, Write<Rect>)>::query().filter(
|
||||
changed::<Sprite>() | changed::<Rect>() | changed::<Handle<ColorMaterial>>(),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use bevy_asset::AssetStorage;
|
||||
use bevy_asset::Assets;
|
||||
use bevy_render::{
|
||||
pipeline::{PipelineAssignments, PipelineCompiler, PipelineDescriptor},
|
||||
render_resource::EntityRenderResourceAssignments,
|
||||
|
@ -8,7 +8,7 @@ use legion::prelude::*;
|
|||
|
||||
pub fn render_resource_sets_system() -> Box<dyn Schedulable> {
|
||||
SystemBuilder::new("update_render_resource_sets")
|
||||
.read_resource::<AssetStorage<PipelineDescriptor>>()
|
||||
.read_resource::<Assets<PipelineDescriptor>>()
|
||||
.read_resource::<PipelineCompiler>()
|
||||
.read_resource::<PipelineAssignments>()
|
||||
.read_resource::<EntityRenderResourceAssignments>()
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
|||
WgpuBindGroupInfo, WgpuResources,
|
||||
};
|
||||
|
||||
use bevy_asset::{AssetStorage, Handle, HandleUntyped};
|
||||
use bevy_asset::{Assets, Handle, HandleUntyped};
|
||||
use bevy_render::{
|
||||
pipeline::{BindGroupDescriptor, PipelineDescriptor},
|
||||
render_resource::{
|
||||
|
@ -297,7 +297,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
|
|||
fn create_shader_module(
|
||||
&self,
|
||||
shader_handle: Handle<Shader>,
|
||||
shader_storage: &AssetStorage<Shader>,
|
||||
shaders: &Assets<Shader>,
|
||||
) {
|
||||
if self
|
||||
.resources
|
||||
|
@ -309,7 +309,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
|
|||
{
|
||||
return;
|
||||
}
|
||||
let shader = shader_storage.get(&shader_handle).unwrap();
|
||||
let shader = shaders.get(&shader_handle).unwrap();
|
||||
self.create_shader_module_from_source(shader_handle, shader);
|
||||
}
|
||||
|
||||
|
@ -374,7 +374,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
|
|||
&self,
|
||||
pipeline_handle: Handle<PipelineDescriptor>,
|
||||
pipeline_descriptor: &PipelineDescriptor,
|
||||
shaders: &AssetStorage<Shader>,
|
||||
shaders: &Assets<Shader>,
|
||||
) {
|
||||
if self
|
||||
.resources
|
||||
|
|
|
@ -8,11 +8,11 @@ fn main() {
|
|||
}
|
||||
|
||||
fn setup(world: &mut World, resources: &mut Resources) {
|
||||
let mut texture_storage = resources.get_mut::<AssetStorage<Texture>>().unwrap();
|
||||
let mut textures = resources.get_mut::<Assets<Texture>>().unwrap();
|
||||
let texture_path = concat!(env!("CARGO_MANIFEST_DIR"), "/assets/branding/icon.png");
|
||||
let texture = Texture::load(TextureType::Png(texture_path.to_string()));
|
||||
let texture_handle = texture_storage.add(texture);
|
||||
let mut color_materials = resources.get_mut::<AssetStorage<ColorMaterial>>().unwrap();
|
||||
let texture_handle = textures.add(texture);
|
||||
let mut color_materials = resources.get_mut::<Assets<ColorMaterial>>().unwrap();
|
||||
|
||||
world
|
||||
.build()
|
||||
|
|
|
@ -11,14 +11,14 @@ fn setup(world: &mut World, resources: &mut Resources) {
|
|||
// load the mesh
|
||||
let model_path = concat!(env!("CARGO_MANIFEST_DIR"), "/assets/models/Monkey.gltf");
|
||||
let mesh = gltf::load_gltf(&model_path).unwrap().unwrap();
|
||||
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||
let mesh_handle = mesh_storage.add(mesh);
|
||||
let mut meshes = resources.get_mut::<Assets<Mesh>>().unwrap();
|
||||
let mesh_handle = meshes.add(mesh);
|
||||
|
||||
// create a material for the mesh
|
||||
let mut material_storage = resources
|
||||
.get_mut::<AssetStorage<StandardMaterial>>()
|
||||
let mut materials = resources
|
||||
.get_mut::<Assets<StandardMaterial>>()
|
||||
.unwrap();
|
||||
let material_handle = material_storage.add(StandardMaterial {
|
||||
let material_handle = materials.add(StandardMaterial {
|
||||
albedo: Color::rgb(0.5, 0.4, 0.3),
|
||||
..Default::default()
|
||||
});
|
||||
|
|
|
@ -17,12 +17,12 @@ fn rotator_system(time: Resource<Time>, _rotator: RefMut<Rotator>, mut rotation:
|
|||
|
||||
/// set up a simple scene with a "parent" cube and a "child" cube
|
||||
fn setup(world: &mut World, resources: &mut Resources) {
|
||||
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||
let mut meshes = resources.get_mut::<Assets<Mesh>>().unwrap();
|
||||
let mut material_storage = resources
|
||||
.get_mut::<AssetStorage<StandardMaterial>>()
|
||||
.get_mut::<Assets<StandardMaterial>>()
|
||||
.unwrap();
|
||||
|
||||
let cube_handle = mesh_storage.add(Mesh::from(shape::Cube));
|
||||
let cube_handle = meshes.add(Mesh::from(shape::Cube));
|
||||
let cube_material_handle = material_storage.add(StandardMaterial {
|
||||
albedo: Color::rgb(0.5, 0.4, 0.3),
|
||||
..Default::default()
|
||||
|
|
|
@ -10,19 +10,19 @@ fn main() {
|
|||
/// set up a simple scene
|
||||
fn setup(world: &mut World, resources: &mut Resources) {
|
||||
// create a cube and a plane mesh
|
||||
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||
let cube_handle = mesh_storage.add(Mesh::from(shape::Cube));
|
||||
let plane_handle = mesh_storage.add(Mesh::from(shape::Plane { size: 10.0 }));
|
||||
let mut meshes = resources.get_mut::<Assets<Mesh>>().unwrap();
|
||||
let cube_handle = meshes.add(Mesh::from(shape::Cube));
|
||||
let plane_handle = meshes.add(Mesh::from(shape::Plane { size: 10.0 }));
|
||||
|
||||
// create materials for our cube and plane
|
||||
let mut material_storage = resources
|
||||
.get_mut::<AssetStorage<StandardMaterial>>()
|
||||
let mut materials = resources
|
||||
.get_mut::<Assets<StandardMaterial>>()
|
||||
.unwrap();
|
||||
let cube_material_handle = material_storage.add(StandardMaterial {
|
||||
let cube_material_handle = materials.add(StandardMaterial {
|
||||
albedo: Color::rgb(0.5, 0.4, 0.3),
|
||||
..Default::default()
|
||||
});
|
||||
let plane_material_handle = material_storage.add(StandardMaterial {
|
||||
let plane_material_handle = materials.add(StandardMaterial {
|
||||
albedo: Color::rgb(0.1, 0.2, 0.1),
|
||||
..Default::default()
|
||||
});
|
||||
|
|
|
@ -16,7 +16,7 @@ fn main() {
|
|||
|
||||
fn move_system(
|
||||
time: Resource<Time>,
|
||||
mut materials: ResourceMut<AssetStorage<StandardMaterial>>,
|
||||
mut materials: ResourceMut<Assets<StandardMaterial>>,
|
||||
mut translation: RefMut<Translation>,
|
||||
material_handle: Ref<Handle<StandardMaterial>>,
|
||||
) {
|
||||
|
@ -26,17 +26,17 @@ fn move_system(
|
|||
}
|
||||
|
||||
fn setup(world: &mut World, resources: &mut Resources) {
|
||||
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||
let mut material_storage = resources
|
||||
.get_mut::<AssetStorage<StandardMaterial>>()
|
||||
let mut meshes = resources.get_mut::<Assets<Mesh>>().unwrap();
|
||||
let mut materials = resources
|
||||
.get_mut::<Assets<StandardMaterial>>()
|
||||
.unwrap();
|
||||
let cube_handle = mesh_storage.add(Mesh::from(shape::Cube));
|
||||
let plane_handle = mesh_storage.add(Mesh::from(shape::Plane { size: 10.0 }));
|
||||
let cube_material_handle = material_storage.add(StandardMaterial {
|
||||
let cube_handle = meshes.add(Mesh::from(shape::Cube));
|
||||
let plane_handle = meshes.add(Mesh::from(shape::Plane { size: 10.0 }));
|
||||
let cube_material_handle = materials.add(StandardMaterial {
|
||||
albedo: Color::rgb(0.5, 0.4, 0.3),
|
||||
..Default::default()
|
||||
});
|
||||
let plane_material_handle = material_storage.add(StandardMaterial {
|
||||
let plane_material_handle = materials.add(StandardMaterial {
|
||||
albedo: Color::rgb(0.1, 0.2, 0.1),
|
||||
..Default::default()
|
||||
});
|
||||
|
@ -73,7 +73,7 @@ fn setup(world: &mut World, resources: &mut Resources) {
|
|||
|
||||
let mut rng = StdRng::from_entropy();
|
||||
for _ in 0..10000 {
|
||||
let spawned_material_handle = material_storage.add(StandardMaterial {
|
||||
let spawned_material_handle = materials.add(StandardMaterial {
|
||||
albedo: Color::rgb(
|
||||
rng.gen_range(0.0, 1.0),
|
||||
rng.gen_range(0.0, 1.0),
|
||||
|
|
|
@ -10,35 +10,35 @@ fn main() {
|
|||
/// sets up a scene with textured entities
|
||||
fn setup(world: &mut World, resources: &mut Resources) {
|
||||
// load a texture
|
||||
let mut texture_storage = resources.get_mut::<AssetStorage<Texture>>().unwrap();
|
||||
let mut textures = resources.get_mut::<Assets<Texture>>().unwrap();
|
||||
let texture_path = concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/assets/branding/bevy_logo_dark_big.png"
|
||||
);
|
||||
let texture = Texture::load(TextureType::Png(texture_path.to_string()));
|
||||
let aspect = texture.aspect();
|
||||
let texture_handle = texture_storage.add(texture);
|
||||
let texture_handle = textures.add(texture);
|
||||
|
||||
// create a new quad mesh. this is what we will apply the texture to
|
||||
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||
let mut meshes = resources.get_mut::<Assets<Mesh>>().unwrap();
|
||||
let quad_width = 8.0;
|
||||
let quad_handle = mesh_storage.add(Mesh::from(shape::Quad {
|
||||
let quad_handle = meshes.add(Mesh::from(shape::Quad {
|
||||
size: Vec2::new(quad_width, quad_width * aspect),
|
||||
}));
|
||||
|
||||
// create materials that use our new texture
|
||||
let mut material_storage = resources
|
||||
.get_mut::<AssetStorage<StandardMaterial>>()
|
||||
let mut materials = resources
|
||||
.get_mut::<Assets<StandardMaterial>>()
|
||||
.unwrap();
|
||||
|
||||
// this material renders the texture normally
|
||||
let material_handle = material_storage.add(StandardMaterial {
|
||||
let material_handle = materials.add(StandardMaterial {
|
||||
albedo_texture: Some(texture_handle),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
// this material modulates the texture to make it red
|
||||
let modulated_material_handle = material_storage.add(StandardMaterial {
|
||||
let modulated_material_handle = materials.add(StandardMaterial {
|
||||
albedo: Color::rgba(1.0, 0.0, 0.0, 0.5),
|
||||
albedo_texture: Some(texture_handle),
|
||||
..Default::default()
|
||||
|
|
|
@ -10,12 +10,12 @@ impl AppPlugin for ExamplePlugin {
|
|||
}
|
||||
|
||||
pub fn setup(world: &mut World, resources: &mut Resources) {
|
||||
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||
let mut material_storage = resources
|
||||
.get_mut::<AssetStorage<StandardMaterial>>()
|
||||
let mut meshes = resources.get_mut::<Assets<Mesh>>().unwrap();
|
||||
let mut materials = resources
|
||||
.get_mut::<Assets<StandardMaterial>>()
|
||||
.unwrap();
|
||||
let cube_handle = mesh_storage.add(Mesh::from(shape::Cube));
|
||||
let cube_material_handle = material_storage.add(StandardMaterial {
|
||||
let cube_handle = meshes.add(Mesh::from(shape::Cube));
|
||||
let cube_material_handle = materials.add(StandardMaterial {
|
||||
albedo: Color::rgb(0.5, 0.4, 0.3),
|
||||
..Default::default()
|
||||
});
|
||||
|
|
|
@ -64,12 +64,12 @@ fn move_system(
|
|||
|
||||
/// creates a simple scene
|
||||
fn setup(world: &mut World, resources: &mut Resources) {
|
||||
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||
let mut material_storage = resources
|
||||
.get_mut::<AssetStorage<StandardMaterial>>()
|
||||
let mut meshes = resources.get_mut::<Assets<Mesh>>().unwrap();
|
||||
let mut materials = resources
|
||||
.get_mut::<Assets<StandardMaterial>>()
|
||||
.unwrap();
|
||||
let cube_handle = mesh_storage.add(Mesh::from(shape::Cube));
|
||||
let cube_material_handle = material_storage.add(StandardMaterial {
|
||||
let cube_handle = meshes.add(Mesh::from(shape::Cube));
|
||||
let cube_material_handle = materials.add(StandardMaterial {
|
||||
albedo: Color::rgb(0.5, 0.4, 0.3),
|
||||
..Default::default()
|
||||
});
|
||||
|
|
|
@ -17,9 +17,9 @@ fn setup(world: &mut World, resources: &mut Resources) {
|
|||
// create new shader pipeline and add to main pass in Render Graph
|
||||
let pipeline_handle = {
|
||||
let mut pipelines = resources
|
||||
.get_mut::<AssetStorage<PipelineDescriptor>>()
|
||||
.get_mut::<Assets<PipelineDescriptor>>()
|
||||
.unwrap();
|
||||
let mut shaders = resources.get_mut::<AssetStorage<Shader>>().unwrap();
|
||||
let mut shaders = resources.get_mut::<Assets<Shader>>().unwrap();
|
||||
|
||||
let pipeline_handle = pipelines.add(PipelineDescriptor::default_config(ShaderStages {
|
||||
vertex: shaders.add(Shader::from_glsl(
|
||||
|
@ -67,13 +67,13 @@ fn setup(world: &mut World, resources: &mut Resources) {
|
|||
};
|
||||
|
||||
// create materials
|
||||
let mut material_storage = resources.get_mut::<AssetStorage<MyMaterial>>().unwrap();
|
||||
let material = material_storage.add(MyMaterial {
|
||||
let mut materials = resources.get_mut::<Assets<MyMaterial>>().unwrap();
|
||||
let material = materials.add(MyMaterial {
|
||||
color: Color::rgb(0.0, 0.8, 0.0),
|
||||
});
|
||||
|
||||
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||
let cube_handle = mesh_storage.add(Mesh::from(shape::Cube));
|
||||
let mut meshes = resources.get_mut::<Assets<Mesh>>().unwrap();
|
||||
let cube_handle = meshes.add(Mesh::from(shape::Cube));
|
||||
|
||||
world
|
||||
.build()
|
||||
|
|
|
@ -23,9 +23,9 @@ fn setup(world: &mut World, resources: &mut Resources) {
|
|||
// create new shader pipeline and add to main pass in Render Graph
|
||||
let pipeline_handle = {
|
||||
let mut pipelines = resources
|
||||
.get_mut::<AssetStorage<PipelineDescriptor>>()
|
||||
.get_mut::<Assets<PipelineDescriptor>>()
|
||||
.unwrap();
|
||||
let mut shaders = resources.get_mut::<AssetStorage<Shader>>().unwrap();
|
||||
let mut shaders = resources.get_mut::<Assets<Shader>>().unwrap();
|
||||
|
||||
let pipeline_handle = pipelines.add(PipelineDescriptor::default_config(ShaderStages {
|
||||
vertex: shaders.add(Shader::from_glsl(
|
||||
|
@ -77,19 +77,19 @@ fn setup(world: &mut World, resources: &mut Resources) {
|
|||
};
|
||||
|
||||
// create materials
|
||||
let mut material_storage = resources.get_mut::<AssetStorage<MyMaterial>>().unwrap();
|
||||
let green_material = material_storage.add(MyMaterial {
|
||||
let mut materials = resources.get_mut::<Assets<MyMaterial>>().unwrap();
|
||||
let green_material = materials.add(MyMaterial {
|
||||
color: Color::rgb(0.0, 0.8, 0.0),
|
||||
always_red: false,
|
||||
});
|
||||
|
||||
let red_material = material_storage.add(MyMaterial {
|
||||
let red_material = materials.add(MyMaterial {
|
||||
color: Color::rgb(0.0, 0.0, 0.0),
|
||||
always_red: true,
|
||||
});
|
||||
|
||||
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||
let cube_handle = mesh_storage.add(Mesh::from(shape::Cube));
|
||||
let mut meshes = resources.get_mut::<Assets<Mesh>>().unwrap();
|
||||
let cube_handle = meshes.add(Mesh::from(shape::Cube));
|
||||
|
||||
world
|
||||
.build()
|
||||
|
|
|
@ -9,7 +9,7 @@ fn main() {
|
|||
}
|
||||
|
||||
fn setup(world: &mut World, resources: &mut Resources) {
|
||||
let mut texture_storage = resources.get_mut::<AssetStorage<Texture>>().unwrap();
|
||||
let mut textures = resources.get_mut::<Assets<Texture>>().unwrap();
|
||||
let font_path = concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/assets/fonts/FiraSans-Bold.ttf"
|
||||
|
@ -22,8 +22,8 @@ fn setup(world: &mut World, resources: &mut Resources) {
|
|||
let texture = font.render_text("Hello from Bevy!", Color::rgba(0.9, 0.9, 0.9, 1.0), 500, 60);
|
||||
let half_width = texture.width as f32 / 2.0;
|
||||
let half_height = texture.height as f32 / 2.0;
|
||||
let texture_handle = texture_storage.add(texture);
|
||||
let mut color_materials = resources.get_mut::<AssetStorage<ColorMaterial>>().unwrap();
|
||||
let texture_handle = textures.add(texture);
|
||||
let mut color_materials = resources.get_mut::<Assets<ColorMaterial>>().unwrap();
|
||||
world
|
||||
.build()
|
||||
// 2d camera
|
||||
|
|
|
@ -19,16 +19,16 @@ fn setup(world: &mut World, resources: &mut Resources) {
|
|||
// ..Default::default()
|
||||
// });
|
||||
|
||||
let mut texture_storage = resources.get_mut::<AssetStorage<Texture>>().unwrap();
|
||||
let mut textures = resources.get_mut::<Assets<Texture>>().unwrap();
|
||||
let texture_path = concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/assets/branding/bevy_logo_dark_big.png"
|
||||
);
|
||||
let texture = Texture::load(TextureType::Png(texture_path.to_string()));
|
||||
let aspect = texture.aspect();
|
||||
let texture_handle = texture_storage.add(texture);
|
||||
let texture_handle = textures.add(texture);
|
||||
|
||||
let mut color_materials = resources.get_mut::<AssetStorage<ColorMaterial>>().unwrap();
|
||||
let mut color_materials = resources.get_mut::<Assets<ColorMaterial>>().unwrap();
|
||||
let blue_material_handle = color_materials.add(Color::rgb(0.6, 0.6, 1.0).into());
|
||||
|
||||
world
|
||||
|
|
|
@ -11,7 +11,7 @@ fn main() {
|
|||
|
||||
fn placement_system(
|
||||
time: Resource<Time>,
|
||||
materials: Resource<AssetStorage<ColorMaterial>>,
|
||||
materials: Resource<Assets<ColorMaterial>>,
|
||||
mut node: RefMut<Node>,
|
||||
material_handle: Ref<Handle<ColorMaterial>>,
|
||||
) {
|
||||
|
@ -25,7 +25,7 @@ fn setup(world: &mut World, resources: &mut Resources) {
|
|||
let mut builder = world.build();
|
||||
builder.add_entity(Camera2dEntity::default());
|
||||
|
||||
let mut materials = resources.get_mut::<AssetStorage<ColorMaterial>>().unwrap();
|
||||
let mut materials = resources.get_mut::<Assets<ColorMaterial>>().unwrap();
|
||||
let mut prev = Vec2::default();
|
||||
let count = 1000;
|
||||
for i in 0..count {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#[cfg(feature = "asset")]
|
||||
pub use crate::asset::{AddAsset, AssetEvent, AssetStorage, Handle};
|
||||
pub use crate::asset::{AddAsset, AssetEvent, Assets, Handle};
|
||||
#[cfg(feature = "core")]
|
||||
pub use crate::core::{
|
||||
time::Time,
|
||||
|
|
Loading…
Reference in a new issue