From 9621ad04f335da77a6014f44a8a39512ae396414 Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Tue, 12 Nov 2024 08:11:10 -0700 Subject: [PATCH 01/52] Migrate up to af865e76a323fc87dd16157e7f4d7593d02c2b95 --- Cargo.toml | 8 +++++--- examples/helpers/ldtk.rs | 7 ++----- examples/helpers/tiled.rs | 4 ++-- src/helpers/filling.rs | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0fb27974..65eb9441 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ render = [] serde = ["dep:serde"] [dependencies] -bevy = { version = "0.14.0", default-features = false, features = [ +bevy = { git = "https://github.com/bevyengine/bevy", rev = "af865e76a323fc87dd16157e7f4d7593d02c2b95", default-features = false, features = [ "bevy_core_pipeline", "bevy_render", "bevy_asset", @@ -34,7 +34,8 @@ tiled = { version = "0.11.0", default-features = false } thiserror = { version = "1.0" } [dev-dependencies.bevy] -version = "0.14.0" +git = "https://github.com/bevyengine/bevy" +rev = "af865e76a323fc87dd16157e7f4d7593d02c2b95" default-features = false features = [ "bevy_core_pipeline", @@ -51,7 +52,8 @@ features = [ ] [target.'cfg(unix)'.dev-dependencies.bevy] -version = "0.14.0" +git = "https://github.com/bevyengine/bevy" +rev = "af865e76a323fc87dd16157e7f4d7593d02c2b95" default-features = false features = [ "bevy_core_pipeline", diff --git a/examples/helpers/ldtk.rs b/examples/helpers/ldtk.rs index e515ed01..7df12064 100644 --- a/examples/helpers/ldtk.rs +++ b/examples/helpers/ldtk.rs @@ -7,10 +7,7 @@ use bevy_ecs_tilemap::{ use std::{collections::HashMap, io::ErrorKind}; use thiserror::Error; -use bevy::{ - asset::{io::Reader, AsyncReadExt}, - reflect::TypePath, -}; +use bevy::{asset::io::Reader, reflect::TypePath}; use bevy::{ asset::{AssetLoader, AssetPath, LoadContext}, prelude::*, @@ -63,7 +60,7 @@ impl AssetLoader for LdtkLoader { async fn load<'a>( &'a self, - reader: &'a mut Reader<'_>, + reader: &'a mut dyn Reader, _settings: &'a Self::Settings, load_context: &'a mut LoadContext<'_>, ) -> Result { diff --git a/examples/helpers/tiled.rs b/examples/helpers/tiled.rs index 4e5172ff..0b54bfbc 100644 --- a/examples/helpers/tiled.rs +++ b/examples/helpers/tiled.rs @@ -17,7 +17,7 @@ use std::path::Path; use std::sync::Arc; use bevy::{ - asset::{io::Reader, AssetLoader, AssetPath, AsyncReadExt}, + asset::{io::Reader, AssetLoader, AssetPath}, log, prelude::{ Added, Asset, AssetApp, AssetEvent, AssetId, Assets, Bundle, Commands, Component, @@ -106,7 +106,7 @@ impl AssetLoader for TiledLoader { async fn load<'a>( &'a self, - reader: &'a mut Reader<'_>, + reader: &'a mut dyn Reader, _settings: &'a Self::Settings, load_context: &'a mut bevy::asset::LoadContext<'_>, ) -> Result { diff --git a/src/helpers/filling.rs b/src/helpers/filling.rs index 77cad55b..60dfd894 100644 --- a/src/helpers/filling.rs +++ b/src/helpers/filling.rs @@ -5,7 +5,7 @@ use crate::prelude::HexCoordSystem; use crate::tiles::{TileBundle, TileColor, TilePos, TileTextureIndex}; use crate::{TileStorage, TilemapSize}; use bevy::hierarchy::BuildChildren; -use bevy::prelude::{Color, Commands}; +use bevy::prelude::{ChildBuild, Color, Commands}; /// Fills an entire tile storage with the given tile. pub fn fill_tilemap( From 2f66d8f80105b6345ee6ab5fe45824fff3ceaaef Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Tue, 12 Nov 2024 08:46:15 -0700 Subject: [PATCH 02/52] Migrate up to bc34216 --- Cargo.toml | 6 +++--- src/render/chunk.rs | 40 +++++++++++++++++++++------------------- src/render/draw.rs | 21 ++++++++++++--------- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 65eb9441..9458b053 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ render = [] serde = ["dep:serde"] [dependencies] -bevy = { git = "https://github.com/bevyengine/bevy", rev = "af865e76a323fc87dd16157e7f4d7593d02c2b95", default-features = false, features = [ +bevy = { git = "https://github.com/bevyengine/bevy", rev = "bc34216", default-features = false, features = [ "bevy_core_pipeline", "bevy_render", "bevy_asset", @@ -35,7 +35,7 @@ thiserror = { version = "1.0" } [dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "af865e76a323fc87dd16157e7f4d7593d02c2b95" +rev = "bc34216" default-features = false features = [ "bevy_core_pipeline", @@ -53,7 +53,7 @@ features = [ [target.'cfg(unix)'.dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "af865e76a323fc87dd16157e7f4d7593d02c2b95" +rev = "bc34216" default-features = false features = [ "bevy_core_pipeline", diff --git a/src/render/chunk.rs b/src/render/chunk.rs index 93319f58..7e8e489b 100644 --- a/src/render/chunk.rs +++ b/src/render/chunk.rs @@ -1,13 +1,14 @@ use std::hash::{Hash, Hasher}; use bevy::render::render_asset::RenderAssetUsages; +use bevy::render::render_resource::Buffer; use bevy::render::{mesh::BaseMeshPipelineKey, primitives::Aabb}; use bevy::{math::Mat4, render::mesh::PrimitiveTopology}; use bevy::{ math::{UVec2, UVec3, UVec4, Vec2, Vec3Swizzles, Vec4, Vec4Swizzles}, prelude::{Component, Entity, GlobalTransform, Mesh, Vec3}, render::{ - mesh::{GpuBufferInfo, GpuMesh, Indices, VertexAttributeValues}, + mesh::{Indices, RenderMesh, RenderMeshBufferInfo, VertexAttributeValues}, render_resource::{BufferInitDescriptor, BufferUsages, ShaderType}, renderer::RenderDevice, }, @@ -214,7 +215,9 @@ pub struct RenderChunk2d { pub texture: TilemapTexture, pub texture_size: Vec2, pub mesh: Mesh, - pub gpu_mesh: Option, + pub render_mesh: Option, + pub vertex_buffer: Option, + pub index_buffer: Option, pub dirty_mesh: bool, pub visible: bool, pub frustum_culling: bool, @@ -250,7 +253,7 @@ impl RenderChunk2d { let aabb = chunk_aabb(size_in_tiles, &grid_size, &tile_size, &map_type); Self { dirty_mesh: true, - gpu_mesh: None, + render_mesh: None, id, index: *index, position, @@ -268,6 +271,8 @@ impl RenderChunk2d { bevy::render::render_resource::PrimitiveTopology::TriangleList, RenderAssetUsages::default(), ), + vertex_buffer: None, + index_buffer: None, spacing, texture_size, texture, @@ -436,26 +441,21 @@ impl RenderChunk2d { contents: &vertex_buffer_data, }); - let buffer_info = - self.mesh - .get_index_buffer_bytes() - .map_or(GpuBufferInfo::NonIndexed {}, |data| { - GpuBufferInfo::Indexed { - buffer: device.create_buffer_with_data(&BufferInitDescriptor { - usage: BufferUsages::INDEX, - contents: data, - label: Some("Mesh Index Buffer"), - }), - count: self.mesh.indices().unwrap().len() as u32, - index_format: self.mesh.indices().unwrap().into(), - } - }); + let index_buffer = device.create_buffer_with_data(&BufferInitDescriptor { + usage: BufferUsages::INDEX, + contents: self.mesh.get_index_buffer_bytes().unwrap(), + label: Some("Mesh Index Buffer"), + }); + + let buffer_info = RenderMeshBufferInfo::Indexed { + count: self.mesh.indices().unwrap().len() as u32, + index_format: self.mesh.indices().unwrap().into(), + }; let mesh_vertex_buffer_layout = self .mesh .get_mesh_vertex_buffer_layout(mesh_vertex_buffer_layouts); - self.gpu_mesh = Some(GpuMesh { - vertex_buffer, + self.render_mesh = Some(RenderMesh { vertex_count: self.mesh.count_vertices() as u32, buffer_info, morph_targets: None, @@ -464,6 +464,8 @@ impl RenderChunk2d { PrimitiveTopology::TriangleList, ), }); + self.vertex_buffer = Some(vertex_buffer); + self.index_buffer = Some(index_buffer); self.dirty_mesh = false; } } diff --git a/src/render/draw.rs b/src/render/draw.rs index 26c8f7ec..81417a85 100644 --- a/src/render/draw.rs +++ b/src/render/draw.rs @@ -9,7 +9,7 @@ use bevy::{ math::UVec4, prelude::Handle, render::{ - mesh::GpuBufferInfo, + mesh::RenderMeshBufferInfo, render_phase::{RenderCommand, RenderCommandResult, TrackedRenderPass}, render_resource::PipelineCache, view::ViewUniformOffset, @@ -199,19 +199,22 @@ impl RenderCommand for DrawMesh { chunk_id.0.z, tilemap_id.0.index(), )) { - if let Some(gpu_mesh) = &chunk.gpu_mesh { - pass.set_vertex_buffer(0, gpu_mesh.vertex_buffer.slice(..)); - match &gpu_mesh.buffer_info { - GpuBufferInfo::Indexed { - buffer, + if let (Some(render_mesh), Some(vertex_buffer), Some(index_buffer)) = ( + &chunk.render_mesh, + &chunk.vertex_buffer, + &chunk.index_buffer, + ) { + pass.set_vertex_buffer(0, vertex_buffer.slice(..)); + match &render_mesh.buffer_info { + RenderMeshBufferInfo::Indexed { index_format, count, } => { - pass.set_index_buffer(buffer.slice(..), 0, *index_format); + pass.set_index_buffer(index_buffer.slice(..), 0, *index_format); pass.draw_indexed(0..*count, 0, 0..1); } - GpuBufferInfo::NonIndexed {} => { - pass.draw(0..gpu_mesh.vertex_count, 0..1); + RenderMeshBufferInfo::NonIndexed {} => { + pass.draw(0..render_mesh.vertex_count, 0..1); } } } From ee5cf96bae1e79fe9ae822b6e2115b337960bedb Mon Sep 17 00:00:00 2001 From: Rich Churcher Date: Fri, 25 Oct 2024 13:19:23 +1300 Subject: [PATCH 03/52] Msaa has been moved to a component See: https://github.com/bevyengine/bevy/pull/14273 --- Cargo.toml | 6 +++--- src/render/material.rs | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9458b053..f746691d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ render = [] serde = ["dep:serde"] [dependencies] -bevy = { git = "https://github.com/bevyengine/bevy", rev = "bc34216", default-features = false, features = [ +bevy = { git = "https://github.com/bevyengine/bevy", rev = "03fd1b4", default-features = false, features = [ "bevy_core_pipeline", "bevy_render", "bevy_asset", @@ -35,7 +35,7 @@ thiserror = { version = "1.0" } [dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "bc34216" +rev = "03fd1b4" default-features = false features = [ "bevy_core_pipeline", @@ -53,7 +53,7 @@ features = [ [target.'cfg(unix)'.dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "bc34216" +rev = "03fd1b4" default-features = false features = [ "bevy_core_pipeline", diff --git a/src/render/material.rs b/src/render/material.rs index d7382412..faaabd93 100644 --- a/src/render/material.rs +++ b/src/render/material.rs @@ -383,13 +383,12 @@ pub fn queue_material_tilemap_meshes( pipeline_cache: Res, view_uniforms: Res, gpu_images: Res>, - msaa: Res, globals_buffer: Res, (standard_tilemap_meshes, materials): ( Query<(Entity, &ChunkId, &Transform, &TilemapId)>, Query<&Handle>, ), - mut views: Query<(Entity, &ExtractedView, &VisibleEntities)>, + mut views: Query<(Entity, &ExtractedView, &Msaa, &VisibleEntities)>, render_materials: Res>, #[cfg(not(feature = "atlas"))] (mut texture_array_cache, render_queue): ( ResMut, @@ -410,7 +409,7 @@ pub fn queue_material_tilemap_meshes( return; } - for (view_entity, view, visible_entities) in views.iter_mut() { + for (view_entity, view, msaa, visible_entities) in views.iter_mut() { let Some(transparent_phase) = transparent_render_phases.get_mut(&view_entity) else { continue; }; From cdf17e546d8996df3f0c4aa0318a9771baa9677a Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Tue, 12 Nov 2024 14:18:17 -0700 Subject: [PATCH 04/52] Migrate up to 3faca1e --- Cargo.toml | 6 +++--- src/render/draw.rs | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f746691d..643cbe3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ render = [] serde = ["dep:serde"] [dependencies] -bevy = { git = "https://github.com/bevyengine/bevy", rev = "03fd1b4", default-features = false, features = [ +bevy = { git = "https://github.com/bevyengine/bevy", rev = "3faca1e", default-features = false, features = [ "bevy_core_pipeline", "bevy_render", "bevy_asset", @@ -35,7 +35,7 @@ thiserror = { version = "1.0" } [dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "03fd1b4" +rev = "3faca1e" default-features = false features = [ "bevy_core_pipeline", @@ -53,7 +53,7 @@ features = [ [target.'cfg(unix)'.dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "03fd1b4" +rev = "3faca1e" default-features = false features = [ "bevy_core_pipeline", diff --git a/src/render/draw.rs b/src/render/draw.rs index 81417a85..74f330c8 100644 --- a/src/render/draw.rs +++ b/src/render/draw.rs @@ -66,7 +66,7 @@ impl RenderCommand for SetTransformBindGroup { pass: &mut TrackedRenderPass<'w>, ) -> RenderCommandResult { let Some((transform_index, tilemap_index)) = uniform_indices else { - return RenderCommandResult::Failure; + return RenderCommandResult::Skip; }; pass.set_bind_group( @@ -93,7 +93,7 @@ impl RenderCommand for SetTextureBindGroup { pass: &mut TrackedRenderPass<'w>, ) -> RenderCommandResult { let Some(texture) = texture else { - return RenderCommandResult::Failure; + return RenderCommandResult::Skip; }; let bind_group = image_bind_groups.into_inner().values.get(texture).unwrap(); @@ -123,7 +123,7 @@ impl RenderCommand for SetItemPipeline { pass.set_render_pipeline(pipeline); RenderCommandResult::Success } else { - RenderCommandResult::Failure + RenderCommandResult::Skip } } } @@ -161,7 +161,7 @@ impl RenderCommand pass: &mut TrackedRenderPass<'w>, ) -> RenderCommandResult { let Some(id) = id else { - return RenderCommandResult::Failure; + return RenderCommandResult::Skip; }; if let Ok(material_handle) = material_handles.get(id.0) { @@ -190,7 +190,7 @@ impl RenderCommand for DrawMesh { pass: &mut TrackedRenderPass<'w>, ) -> RenderCommandResult { let Some((chunk_id, tilemap_id)) = ids else { - return RenderCommandResult::Failure; + return RenderCommandResult::Skip; }; if let Some(chunk) = chunk_storage.into_inner().get(&UVec4::new( From a8961231f0348bdb628ec7b695453c9f7208e34c Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Tue, 12 Nov 2024 14:34:02 -0700 Subject: [PATCH 05/52] Migrate up to 5abc32c See bevy#13069, bevy#14831 --- Cargo.toml | 6 +++--- src/render/pipeline.rs | 30 ++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 643cbe3c..67f75241 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ render = [] serde = ["dep:serde"] [dependencies] -bevy = { git = "https://github.com/bevyengine/bevy", rev = "3faca1e", default-features = false, features = [ +bevy = { git = "https://github.com/bevyengine/bevy", rev = "3e86787e93abb73958fd8884b77fe435e0f13333", default-features = false, features = [ "bevy_core_pipeline", "bevy_render", "bevy_asset", @@ -35,7 +35,7 @@ thiserror = { version = "1.0" } [dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "3faca1e" +rev = "3e86787e93abb73958fd8884b77fe435e0f13333" default-features = false features = [ "bevy_core_pipeline", @@ -53,7 +53,7 @@ features = [ [target.'cfg(unix)'.dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "3faca1e" +rev = "3e86787e93abb73958fd8884b77fe435e0f13333" default-features = false features = [ "bevy_core_pipeline", diff --git a/src/render/pipeline.rs b/src/render/pipeline.rs index 09ec40bb..57e8053a 100644 --- a/src/render/pipeline.rs +++ b/src/render/pipeline.rs @@ -1,14 +1,17 @@ use bevy::{ + core_pipeline::core_2d::CORE_2D_DEPTH_FORMAT, prelude::{Component, FromWorld, Handle, Resource, Shader, World}, render::{ globals::GlobalsUniform, render_resource::{ BindGroupLayout, BindGroupLayoutEntry, BindingType, BlendComponent, BlendFactor, - BlendOperation, BlendState, BufferBindingType, ColorTargetState, ColorWrites, Face, - FragmentState, FrontFace, MultisampleState, PolygonMode, PrimitiveState, - PrimitiveTopology, RenderPipelineDescriptor, SamplerBindingType, ShaderStages, - ShaderType, SpecializedRenderPipeline, TextureFormat, TextureSampleType, - TextureViewDimension, VertexBufferLayout, VertexFormat, VertexState, VertexStepMode, + BlendOperation, BlendState, BufferBindingType, ColorTargetState, ColorWrites, + CompareFunction, DepthBiasState, DepthStencilState, Face, FragmentState, FrontFace, + MultisampleState, PolygonMode, PrimitiveState, PrimitiveTopology, + RenderPipelineDescriptor, SamplerBindingType, ShaderStages, ShaderType, + SpecializedRenderPipeline, StencilFaceState, StencilState, TextureFormat, + TextureSampleType, TextureViewDimension, VertexBufferLayout, VertexFormat, VertexState, + VertexStepMode, }, renderer::RenderDevice, texture::BevyDefault, @@ -233,7 +236,22 @@ impl SpecializedRenderPipeline for TilemapPipeline { topology: PrimitiveTopology::TriangleList, unclipped_depth: false, }, - depth_stencil: None, + depth_stencil: Some(DepthStencilState { + format: CORE_2D_DEPTH_FORMAT, + depth_write_enabled: false, + depth_compare: CompareFunction::GreaterEqual, + stencil: StencilState { + front: StencilFaceState::IGNORE, + back: StencilFaceState::IGNORE, + read_mask: 0, + write_mask: 0, + }, + bias: DepthBiasState { + constant: 0, + slope_scale: 0.0, + clamp: 0.0, + }, + }), multisample: MultisampleState { count: key.msaa, mask: !0, From 1fdeec63f488c86e6bd672a378ae5b11e2c5285b Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Tue, 12 Nov 2024 14:50:33 -0700 Subject: [PATCH 06/52] Migrate up to 6e2f96f --- Cargo.toml | 6 +++--- src/render/material.rs | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 67f75241..cd855e3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ render = [] serde = ["dep:serde"] [dependencies] -bevy = { git = "https://github.com/bevyengine/bevy", rev = "3e86787e93abb73958fd8884b77fe435e0f13333", default-features = false, features = [ +bevy = { git = "https://github.com/bevyengine/bevy", rev = "6e2f96f2224032e04e77b993ad4c06d76d49039f", default-features = false, features = [ "bevy_core_pipeline", "bevy_render", "bevy_asset", @@ -35,7 +35,7 @@ thiserror = { version = "1.0" } [dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "3e86787e93abb73958fd8884b77fe435e0f13333" +rev = "6e2f96f2224032e04e77b993ad4c06d76d49039f" default-features = false features = [ "bevy_core_pipeline", @@ -53,7 +53,7 @@ features = [ [target.'cfg(unix)'.dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "3e86787e93abb73958fd8884b77fe435e0f13333" +rev = "6e2f96f2224032e04e77b993ad4c06d76d49039f" default-features = false features = [ "bevy_core_pipeline", diff --git a/src/render/material.rs b/src/render/material.rs index faaabd93..4a1c92c8 100644 --- a/src/render/material.rs +++ b/src/render/material.rs @@ -1,5 +1,6 @@ use bevy::{ core_pipeline::core_2d::Transparent2d, + log::error, math::FloatOrd, prelude::*, reflect::TypePath, @@ -326,6 +327,9 @@ fn prepare_materials_tilemap( Err(AsBindGroupError::RetryNextUpdate) => { prepare_next_frame.assets.push((handle, material)); } + Err(AsBindGroupError::InvalidSamplerType(_, _, _)) => { + error!("Encountered AsBindGroupError::InvalidSamplerType while preparing material"); + } } } @@ -347,6 +351,9 @@ fn prepare_materials_tilemap( Err(AsBindGroupError::RetryNextUpdate) => { prepare_next_frame.assets.push((handle, material)); } + Err(AsBindGroupError::InvalidSamplerType(_, _, _)) => { + error!("Encountered AsBindGroupError::InvalidSamplerType while preparing material"); + } } } } From d678ab14d53e71a363b51226c1ad3478220942b0 Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Tue, 12 Nov 2024 15:08:36 -0700 Subject: [PATCH 07/52] Migrate up to 739007f See bevy#14909 Co-authored-by: Rich Churcher --- Cargo.toml | 6 ++--- examples/hex_neighbors.rs | 2 +- examples/hex_neighbors_radius_chunks.rs | 2 +- examples/mouse_to_tile.rs | 2 +- src/render/material.rs | 33 ++++++------------------- 5 files changed, 14 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cd855e3b..2e4d75e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ render = [] serde = ["dep:serde"] [dependencies] -bevy = { git = "https://github.com/bevyengine/bevy", rev = "6e2f96f2224032e04e77b993ad4c06d76d49039f", default-features = false, features = [ +bevy = { git = "https://github.com/bevyengine/bevy", rev = "739007f1483c4cdeffe5121732422b078188ef56", default-features = false, features = [ "bevy_core_pipeline", "bevy_render", "bevy_asset", @@ -35,7 +35,7 @@ thiserror = { version = "1.0" } [dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "6e2f96f2224032e04e77b993ad4c06d76d49039f" +rev = "739007f1483c4cdeffe5121732422b078188ef56" default-features = false features = [ "bevy_core_pipeline", @@ -53,7 +53,7 @@ features = [ [target.'cfg(unix)'.dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "6e2f96f2224032e04e77b993ad4c06d76d49039f" +rev = "739007f1483c4cdeffe5121732422b078188ef56" default-features = false features = [ "bevy_core_pipeline", diff --git a/examples/hex_neighbors.rs b/examples/hex_neighbors.rs index 9aa2f1bd..dbb63d1d 100644 --- a/examples/hex_neighbors.rs +++ b/examples/hex_neighbors.rs @@ -261,7 +261,7 @@ pub fn update_cursor_pos( // any transforms on the camera. This is done by projecting the cursor position into // camera space (world space). for (cam_t, cam) in camera_q.iter() { - if let Some(pos) = cam.viewport_to_world_2d(cam_t, cursor_moved.position) { + if let Ok(pos) = cam.viewport_to_world_2d(cam_t, cursor_moved.position) { *cursor_pos = CursorPos(pos); } } diff --git a/examples/hex_neighbors_radius_chunks.rs b/examples/hex_neighbors_radius_chunks.rs index 9f3f9593..6ff1eb1a 100644 --- a/examples/hex_neighbors_radius_chunks.rs +++ b/examples/hex_neighbors_radius_chunks.rs @@ -382,7 +382,7 @@ pub fn update_cursor_pos( // any transforms on the camera. This is done by projecting the cursor position into // camera space (world space). for (cam_t, cam) in camera_q.iter() { - if let Some(pos) = cam.viewport_to_world_2d(cam_t, cursor_moved.position) { + if let Ok(pos) = cam.viewport_to_world_2d(cam_t, cursor_moved.position) { *cursor_pos = CursorPos(pos); } } diff --git a/examples/mouse_to_tile.rs b/examples/mouse_to_tile.rs index 9ea13ec2..031d3354 100644 --- a/examples/mouse_to_tile.rs +++ b/examples/mouse_to_tile.rs @@ -304,7 +304,7 @@ pub fn update_cursor_pos( // any transforms on the camera. This is done by projecting the cursor position into // camera space (world space). for (cam_t, cam) in camera_q.iter() { - if let Some(pos) = cam.viewport_to_world_2d(cam_t, cursor_moved.position) { + if let Ok(pos) = cam.viewport_to_world_2d(cam_t, cursor_moved.position) { *cursor_pos = CursorPos(pos); } } diff --git a/src/render/material.rs b/src/render/material.rs index 4a1c92c8..46c253c6 100644 --- a/src/render/material.rs +++ b/src/render/material.rs @@ -1,5 +1,6 @@ use bevy::{ core_pipeline::core_2d::Transparent2d, + ecs::system::{StaticSystemParam, SystemParamItem}, log::error, math::FloatOrd, prelude::*, @@ -17,7 +18,7 @@ use bevy::{ ShaderRef, SpecializedRenderPipeline, SpecializedRenderPipelines, }, renderer::RenderDevice, - texture::{FallbackImage, GpuImage}, + texture::GpuImage, view::{ExtractedView, ViewUniforms, VisibleEntities}, Extract, Render, RenderApp, RenderSet, }, @@ -308,19 +309,12 @@ fn prepare_materials_tilemap( mut extracted_assets: ResMut>, mut render_materials: ResMut>, render_device: Res, - images: Res>, - fallback_image: Res, pipeline: Res>, + mut param: StaticSystemParam, ) { let queued_assets = std::mem::take(&mut prepare_next_frame.assets); for (handle, material) in queued_assets { - match prepare_material_tilemap( - &material, - &render_device, - &images, - &fallback_image, - &pipeline, - ) { + match prepare_material_tilemap(&material, &render_device, &pipeline, &mut param) { Ok(prepared_asset) => { render_materials.insert(handle, prepared_asset); } @@ -338,13 +332,7 @@ fn prepare_materials_tilemap( } for (handle, material) in std::mem::take(&mut extracted_assets.extracted) { - match prepare_material_tilemap( - &material, - &render_device, - &images, - &fallback_image, - &pipeline, - ) { + match prepare_material_tilemap(&material, &render_device, &pipeline, &mut param) { Ok(prepared_asset) => { render_materials.insert(handle, prepared_asset); } @@ -361,16 +349,11 @@ fn prepare_materials_tilemap( fn prepare_material_tilemap( material: &M, render_device: &RenderDevice, - images: &RenderAssets, - fallback_image: &FallbackImage, pipeline: &MaterialTilemapPipeline, + param: &mut SystemParamItem<::Param>, ) -> Result, AsBindGroupError> { - let prepared = material.as_bind_group( - &pipeline.material_tilemap_layout, - render_device, - images, - fallback_image, - )?; + let prepared = + material.as_bind_group(&pipeline.material_tilemap_layout, render_device, param)?; Ok(PreparedMaterialTilemap { bindings: prepared.bindings, bind_group: prepared.bind_group, From 1f31ed3ea8015ad187afff765ac3cfcf3ca142ae Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Tue, 12 Nov 2024 15:40:24 -0700 Subject: [PATCH 08/52] WIP: last commit that works before retained render world --- Cargo.toml | 6 +++--- examples/basic.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2e4d75e1..fba20fe4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ render = [] serde = ["dep:serde"] [dependencies] -bevy = { git = "https://github.com/bevyengine/bevy", rev = "739007f1483c4cdeffe5121732422b078188ef56", default-features = false, features = [ +bevy = { git = "https://github.com/bevyengine/bevy", rev = "01dce4742f77a572a1ef21ce8f64ce3b6d2328a8", default-features = false, features = [ "bevy_core_pipeline", "bevy_render", "bevy_asset", @@ -35,7 +35,7 @@ thiserror = { version = "1.0" } [dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "739007f1483c4cdeffe5121732422b078188ef56" +rev = "01dce4742f77a572a1ef21ce8f64ce3b6d2328a8" default-features = false features = [ "bevy_core_pipeline", @@ -53,7 +53,7 @@ features = [ [target.'cfg(unix)'.dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "739007f1483c4cdeffe5121732422b078188ef56" +rev = "01dce4742f77a572a1ef21ce8f64ce3b6d2328a8" default-features = false features = [ "bevy_core_pipeline", diff --git a/examples/basic.rs b/examples/basic.rs index b9a2868e..40bd15ac 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -1,7 +1,7 @@ use bevy::prelude::*; use bevy_ecs_tilemap::prelude::*; -mod helpers; +//mod helpers; fn startup( mut commands: Commands, @@ -111,7 +111,7 @@ fn main() { }).set(ImagePlugin::default_nearest())) .add_plugins(TilemapPlugin) .add_systems(Startup, startup) - .add_systems(Update, helpers::camera::movement) + //.add_systems(Update, helpers::camera::movement) .add_systems(Update, swap_texture_or_hide) .run(); } From ce982c9ebc068090c5775d04387341a2bc8a976a Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Wed, 13 Nov 2024 12:31:37 -0700 Subject: [PATCH 09/52] WIP: RRW PoC - Needs bundle cleanup and visibility fix --- Cargo.toml | 6 +++--- examples/basic.rs | 38 +++++++++++++++++++++---------------- examples/helpers/camera.rs | 18 +++++++++--------- src/render/draw.rs | 1 + src/render/extract.rs | 39 ++++++++++++++++++++------------------ src/render/material.rs | 24 +++++++++++------------ src/render/prepare.rs | 9 ++++++--- 7 files changed, 74 insertions(+), 61 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fba20fe4..8c019641 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ render = [] serde = ["dep:serde"] [dependencies] -bevy = { git = "https://github.com/bevyengine/bevy", rev = "01dce4742f77a572a1ef21ce8f64ce3b6d2328a8", default-features = false, features = [ +bevy = { git = "https://github.com/bevyengine/bevy", rev = "56f8e52", default-features = false, features = [ "bevy_core_pipeline", "bevy_render", "bevy_asset", @@ -35,7 +35,7 @@ thiserror = { version = "1.0" } [dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "01dce4742f77a572a1ef21ce8f64ce3b6d2328a8" +rev = "56f8e52" default-features = false features = [ "bevy_core_pipeline", @@ -53,7 +53,7 @@ features = [ [target.'cfg(unix)'.dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "01dce4742f77a572a1ef21ce8f64ce3b6d2328a8" +rev = "56f8e52" default-features = false features = [ "bevy_core_pipeline", diff --git a/examples/basic.rs b/examples/basic.rs index 40bd15ac..0114231b 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -1,4 +1,4 @@ -use bevy::prelude::*; +use bevy::{prelude::*, render::world_sync::SyncToRenderWorld}; use bevy_ecs_tilemap::prelude::*; //mod helpers; @@ -35,11 +35,14 @@ fn startup( for y in 0..map_size.y { let tile_pos = TilePos { x, y }; let tile_entity = commands - .spawn(TileBundle { - position: tile_pos, - tilemap_id: TilemapId(tilemap_entity), - ..Default::default() - }) + .spawn(( + TileBundle { + position: tile_pos, + tilemap_id: TilemapId(tilemap_entity), + ..Default::default() + }, + SyncToRenderWorld, + )) .id(); tile_storage.set(&tile_pos, tile_entity); } @@ -49,16 +52,19 @@ fn startup( let grid_size = tile_size.into(); let map_type = TilemapType::default(); - commands.entity(tilemap_entity).insert(TilemapBundle { - grid_size, - map_type, - size: map_size, - storage: tile_storage, - texture: TilemapTexture::Single(texture_handle), - tile_size, - transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), - ..Default::default() - }); + commands.entity(tilemap_entity).insert(( + TilemapBundle { + grid_size, + map_type, + size: map_size, + storage: tile_storage, + texture: TilemapTexture::Single(texture_handle), + tile_size, + transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), + ..Default::default() + }, + SyncToRenderWorld, + )); // Add atlas to array texture loader so it's preprocessed before we need to use it. // Only used when the atlas feature is off and we are using array textures. diff --git a/examples/helpers/camera.rs b/examples/helpers/camera.rs index e6155f5c..19f28b8d 100644 --- a/examples/helpers/camera.rs +++ b/examples/helpers/camera.rs @@ -26,17 +26,17 @@ pub fn movement( direction -= Vec3::new(0.0, 1.0, 0.0); } - if keyboard_input.pressed(KeyCode::KeyZ) { - ortho.scale += 0.1; - } + // if keyboard_input.pressed(KeyCode::KeyZ) { + // ortho.scale += 0.1; + // } - if keyboard_input.pressed(KeyCode::KeyX) { - ortho.scale -= 0.1; - } + // if keyboard_input.pressed(KeyCode::KeyX) { + // ortho.scale -= 0.1; + // } - if ortho.scale < 0.5 { - ortho.scale = 0.5; - } + // if ortho.scale < 0.5 { + // ortho.scale = 0.5; + // } let z = transform.translation.z; transform.translation += time.delta_seconds() * direction * 500.; diff --git a/src/render/draw.rs b/src/render/draw.rs index 74f330c8..aee9d7cb 100644 --- a/src/render/draw.rs +++ b/src/render/draw.rs @@ -6,6 +6,7 @@ use bevy::{ lifetimeless::{Read, SQuery, SRes}, SystemParamItem, }, + log::info, math::UVec4, prelude::Handle, render::{ diff --git a/src/render/extract.rs b/src/render/extract.rs index 06fd69a6..14b3c293 100644 --- a/src/render/extract.rs +++ b/src/render/extract.rs @@ -2,6 +2,7 @@ use bevy::math::Affine3A; use bevy::render::primitives::{Aabb, Frustum}; use bevy::render::render_resource::FilterMode; use bevy::render::render_resource::TextureFormat; +use bevy::render::world_sync::{RenderEntity, TemporaryRenderEntity}; use bevy::{prelude::*, render::Extract, utils::HashMap}; use crate::prelude::TilemapGridSize; @@ -188,7 +189,7 @@ pub fn extract( changed_tiles_query: Extract< Query< ( - Entity, + &RenderEntity, &TilePos, &TilePosOld, &TilemapId, @@ -210,7 +211,7 @@ pub fn extract( >, tilemap_query: Extract< Query<( - Entity, + &RenderEntity, &GlobalTransform, &TilemapTileSize, &TilemapSpacing, @@ -225,7 +226,7 @@ pub fn extract( >, changed_tilemap_query: Extract< Query< - Entity, + &RenderEntity, Or<( Added, Changed, @@ -241,7 +242,7 @@ pub fn extract( )>, >, >, - camera_query: Extract>>, + camera_query: Extract>>, images: Extract>>, time: Extract>, ) { @@ -250,7 +251,7 @@ pub fn extract( let mut extracted_tilemap_textures = Vec::new(); // Process all tiles for ( - entity, + render_entity, tile_pos, tile_pos_old, tilemap_id, @@ -288,9 +289,9 @@ pub fn extract( let data = tilemap_query.get(tilemap_id.0).unwrap(); extracted_tilemaps.insert( - data.0, + data.0.id(), ( - data.0, + data.0.id(), ExtractedTilemapBundle { transform: *data.1, tile_size: *data.2, @@ -308,25 +309,25 @@ pub fn extract( ); extracted_tiles.push(( - entity, + render_entity.id(), ExtractedTileBundle { tile: ExtractedTile { - entity, + entity: render_entity.id(), position: *tile_pos, old_position: *tile_pos_old, tile, - tilemap_id: *tilemap_id, + tilemap_id: TilemapId(data.0.id()), }, }, )); } for tilemap_entity in changed_tilemap_query.iter() { - if let Ok(data) = tilemap_query.get(tilemap_entity) { + if let Ok(data) = tilemap_query.get(tilemap_entity.id()) { extracted_tilemaps.insert( - data.0, + data.0.id(), ( - data.0, + data.0.id(), ExtractedTilemapBundle { transform: *data.1, tile_size: *data.2, @@ -349,13 +350,15 @@ pub fn extract( extracted_tilemaps.drain().map(|kv| kv.1).collect(); // Extracts tilemap textures. - for (entity, _, tile_size, tile_spacing, _, _, texture, _, _, _, _) in tilemap_query.iter() { + for (render_entity, _, tile_size, tile_spacing, _, _, texture, _, _, _, _) in + tilemap_query.iter() + { if texture.verify_ready(&images) { extracted_tilemap_textures.push(( - entity, + render_entity.id(), ExtractedTilemapTextureBundle { data: ExtractedTilemapTexture::new( - entity, + render_entity.id(), texture.clone_weak(), *tile_size, *tile_spacing, @@ -367,9 +370,9 @@ pub fn extract( } } - for (entity, frustum) in camera_query.iter() { + for (render_entity, frustum) in camera_query.iter() { commands - .get_or_spawn(entity) + .get_or_spawn(render_entity.id()) .insert(ExtractedFrustum { frustum: *frustum }); } diff --git a/src/render/material.rs b/src/render/material.rs index 46c253c6..6f65247a 100644 --- a/src/render/material.rs +++ b/src/render/material.rs @@ -410,12 +410,12 @@ pub fn queue_material_tilemap_meshes( .unwrap(); for (entity, chunk_id, transform, tilemap_id) in standard_tilemap_meshes.iter() { - if !visible_entities - .iter::>() - .any(|&entity| entity.index() == tilemap_id.0.index()) - { - continue; - } + // if !visible_entities + // .iter::>() + // .any(|&entity| entity.index() == tilemap_id.0.index()) + // { + // continue; + // } let Ok(material_handle) = materials.get(tilemap_id.0) else { continue; @@ -528,12 +528,12 @@ pub fn bind_material_tilemap_meshes( }); for (chunk_id, tilemap_id) in standard_tilemap_meshes.iter() { - if !visible_entities - .iter::>() - .any(|&entity| entity.index() == tilemap_id.0.index()) - { - continue; - } + // if !visible_entities + // .iter::>() + // .any(|&entity| entity.index() == tilemap_id.0.index()) + // { + // continue; + // } let Ok(material_handle) = materials.get(tilemap_id.0) else { continue; diff --git a/src/render/prepare.rs b/src/render/prepare.rs index afdb602f..c13bb0b1 100644 --- a/src/render/prepare.rs +++ b/src/render/prepare.rs @@ -9,7 +9,9 @@ use crate::render::extract::ExtractedFrustum; use crate::{ prelude::TilemapGridSize, render::RenderChunkSize, render::SecondsSinceStartup, FrustumCulling, }; +use bevy::log::{debug, info}; use bevy::prelude::{InheritedVisibility, Resource}; +use bevy::render::world_sync::{RenderEntity, TemporaryRenderEntity}; use bevy::{log::trace, render::mesh::MeshVertexBufferLayouts}; use bevy::{ math::{Mat4, UVec4}, @@ -175,7 +177,7 @@ pub(crate) fn prepare( for chunk in chunk_storage.iter_mut() { if !chunk.visible { - trace!("Visibility culled chunk: {:?}", chunk.get_index()); + info!("Visibility culled chunk: {:?}", chunk.get_index()); continue; } @@ -184,10 +186,10 @@ pub(crate) fn prepare( .iter() .any(|frustum| chunk.intersects_frustum(frustum)) { - trace!("Frustum culled chunk: {:?}", chunk.get_index()); + info!("Frustum culled chunk: {:?}", chunk.get_index()); continue; } - trace!("Preparing chunk: {:?}", chunk.get_index()); + info!("Preparing chunk: {:?}", chunk.get_index()); chunk.prepare(&render_device, &mut mesh_vertex_buffer_layouts); @@ -210,6 +212,7 @@ pub(crate) fn prepare( index: tilemap_uniforms.0.push(&chunk_uniform), marker: PhantomData, }, + TemporaryRenderEntity, )); } From 15b5b4203533e0e2462f648cf99ee16e0712d14e Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Wed, 13 Nov 2024 12:55:42 -0700 Subject: [PATCH 10/52] WIP: plowing onward anyway --- Cargo.toml | 6 +++--- src/render/chunk.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8c019641..7993fb61 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ render = [] serde = ["dep:serde"] [dependencies] -bevy = { git = "https://github.com/bevyengine/bevy", rev = "56f8e52", default-features = false, features = [ +bevy = { git = "https://github.com/bevyengine/bevy", rev = "91bed8ce510efe8cdb265789faf41102fbdaaab8", default-features = false, features = [ "bevy_core_pipeline", "bevy_render", "bevy_asset", @@ -35,7 +35,7 @@ thiserror = { version = "1.0" } [dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "56f8e52" +rev = "91bed8ce510efe8cdb265789faf41102fbdaaab8" default-features = false features = [ "bevy_core_pipeline", @@ -53,7 +53,7 @@ features = [ [target.'cfg(unix)'.dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "56f8e52" +rev = "91bed8ce510efe8cdb265789faf41102fbdaaab8" default-features = false features = [ "bevy_core_pipeline", diff --git a/src/render/chunk.rs b/src/render/chunk.rs index 7e8e489b..da9da83e 100644 --- a/src/render/chunk.rs +++ b/src/render/chunk.rs @@ -434,7 +434,7 @@ impl RenderChunk2d { ); self.mesh.insert_indices(Indices::U32(indices)); - let vertex_buffer_data = self.mesh.get_vertex_buffer_data(); + let vertex_buffer_data = self.mesh.create_packed_vertex_buffer_data(); let vertex_buffer = device.create_buffer_with_data(&BufferInitDescriptor { usage: BufferUsages::VERTEX, label: Some("Mesh Vertex Buffer"), From 7bb74287034afb93d2764f636bffe8c7d61f73fe Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Wed, 13 Nov 2024 13:18:01 -0700 Subject: [PATCH 11/52] WIP: further plowing --- Cargo.toml | 6 +++--- examples/basic.rs | 2 +- src/render/extract.rs | 2 +- src/render/prepare.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7993fb61..a1ef51c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ render = [] serde = ["dep:serde"] [dependencies] -bevy = { git = "https://github.com/bevyengine/bevy", rev = "91bed8ce510efe8cdb265789faf41102fbdaaab8", default-features = false, features = [ +bevy = { git = "https://github.com/bevyengine/bevy", rev = "2d1b4939d2b35a7a7ce165c7c188770b8baedb0c", default-features = false, features = [ "bevy_core_pipeline", "bevy_render", "bevy_asset", @@ -35,7 +35,7 @@ thiserror = { version = "1.0" } [dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "91bed8ce510efe8cdb265789faf41102fbdaaab8" +rev = "2d1b4939d2b35a7a7ce165c7c188770b8baedb0c" default-features = false features = [ "bevy_core_pipeline", @@ -53,7 +53,7 @@ features = [ [target.'cfg(unix)'.dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "91bed8ce510efe8cdb265789faf41102fbdaaab8" +rev = "2d1b4939d2b35a7a7ce165c7c188770b8baedb0c" default-features = false features = [ "bevy_core_pipeline", diff --git a/examples/basic.rs b/examples/basic.rs index 0114231b..35858150 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -1,4 +1,4 @@ -use bevy::{prelude::*, render::world_sync::SyncToRenderWorld}; +use bevy::{prelude::*, render::sync_world::SyncToRenderWorld}; use bevy_ecs_tilemap::prelude::*; //mod helpers; diff --git a/src/render/extract.rs b/src/render/extract.rs index 14b3c293..5d56c494 100644 --- a/src/render/extract.rs +++ b/src/render/extract.rs @@ -2,7 +2,7 @@ use bevy::math::Affine3A; use bevy::render::primitives::{Aabb, Frustum}; use bevy::render::render_resource::FilterMode; use bevy::render::render_resource::TextureFormat; -use bevy::render::world_sync::{RenderEntity, TemporaryRenderEntity}; +use bevy::render::sync_world::{RenderEntity, TemporaryRenderEntity}; use bevy::{prelude::*, render::Extract, utils::HashMap}; use crate::prelude::TilemapGridSize; diff --git a/src/render/prepare.rs b/src/render/prepare.rs index c13bb0b1..83e8546d 100644 --- a/src/render/prepare.rs +++ b/src/render/prepare.rs @@ -11,7 +11,7 @@ use crate::{ }; use bevy::log::{debug, info}; use bevy::prelude::{InheritedVisibility, Resource}; -use bevy::render::world_sync::{RenderEntity, TemporaryRenderEntity}; +use bevy::render::sync_world::{RenderEntity, TemporaryRenderEntity}; use bevy::{log::trace, render::mesh::MeshVertexBufferLayouts}; use bevy::{ math::{Mat4, UVec4}, From 7937dbc9a6320983b34d845578a82dcfa5c07b06 Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Wed, 20 Nov 2024 12:48:20 -0700 Subject: [PATCH 12/52] wip: forward --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a1ef51c1..e5752f9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ render = [] serde = ["dep:serde"] [dependencies] -bevy = { git = "https://github.com/bevyengine/bevy", rev = "2d1b4939d2b35a7a7ce165c7c188770b8baedb0c", default-features = false, features = [ +bevy = { git = "https://github.com/bevyengine/bevy", rev = "a06802a66eb0af8c2d2c4ec77a654a5ed5913596", default-features = false, features = [ "bevy_core_pipeline", "bevy_render", "bevy_asset", @@ -35,7 +35,7 @@ thiserror = { version = "1.0" } [dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "2d1b4939d2b35a7a7ce165c7c188770b8baedb0c" +rev = "a06802a66eb0af8c2d2c4ec77a654a5ed5913596" default-features = false features = [ "bevy_core_pipeline", @@ -53,7 +53,7 @@ features = [ [target.'cfg(unix)'.dev-dependencies.bevy] git = "https://github.com/bevyengine/bevy" -rev = "2d1b4939d2b35a7a7ce165c7c188770b8baedb0c" +rev = "a06802a66eb0af8c2d2c4ec77a654a5ed5913596" default-features = false features = [ "bevy_core_pipeline", From 5055c6e9483f715f5e97728eeda3752b68a24c6f Mon Sep 17 00:00:00 2001 From: Rich Churcher Date: Fri, 25 Oct 2024 12:57:20 +1300 Subject: [PATCH 13/52] Wrapper component for Handle See https://github.com/bevyengine/bevy/issues/15716 --- src/render/material.rs | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/render/material.rs b/src/render/material.rs index 6f65247a..09093d90 100644 --- a/src/render/material.rs +++ b/src/render/material.rs @@ -101,6 +101,34 @@ where } } +#[derive(Component, Clone, Debug, Deref, DerefMut, Reflect, PartialEq, Eq, ExtractComponent)] +#[reflect(Component, Default)] +pub struct MaterialTilemapHandle(pub Handle); + +impl Default for MaterialTilemapHandle { + fn default() -> Self { + Self(Handle::default()) + } +} + +impl From> for MaterialTilemapHandle { + fn from(handle: Handle) -> Self { + Self(handle) + } +} + +impl From> for AssetId { + fn from(tilemap: MaterialTilemapHandle) -> Self { + tilemap.id() + } +} + +impl From<&MaterialTilemapHandle> for AssetId { + fn from(tilemap: &MaterialTilemapHandle) -> Self { + tilemap.id() + } +} + pub struct MaterialTilemapPlugin(PhantomData); impl Default for MaterialTilemapPlugin { @@ -115,7 +143,7 @@ where { fn build(&self, app: &mut App) { app.init_asset::() - .add_plugins(ExtractComponentPlugin::>::extract_visible()); + .add_plugins(ExtractComponentPlugin::>::extract_visible()); } fn finish(&self, app: &mut App) { @@ -376,7 +404,7 @@ pub fn queue_material_tilemap_meshes( globals_buffer: Res, (standard_tilemap_meshes, materials): ( Query<(Entity, &ChunkId, &Transform, &TilemapId)>, - Query<&Handle>, + Query<&MaterialTilemapHandle>, ), mut views: Query<(Entity, &ExtractedView, &Msaa, &VisibleEntities)>, render_materials: Res>, @@ -485,7 +513,10 @@ pub fn bind_material_tilemap_meshes( gpu_images: Res>, globals_buffer: Res, mut image_bind_groups: ResMut, - (standard_tilemap_meshes, materials): (Query<(&ChunkId, &TilemapId)>, Query<&Handle>), + (standard_tilemap_meshes, materials): ( + Query<(&ChunkId, &TilemapId)>, + Query<&MaterialTilemapHandle>, + ), mut views: Query<(Entity, &VisibleEntities)>, render_materials: Res>, modified_image_ids: Res, From 7a85e0895cb5737b79233cf3359e6393f7307638 Mon Sep 17 00:00:00 2001 From: Rich Churcher Date: Fri, 25 Oct 2024 13:14:14 +1300 Subject: [PATCH 14/52] Missed a Handle to wrap --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4783bd08..1b322893 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,7 @@ use bevy::{ }; #[cfg(feature = "render")] -use bevy::prelude::Handle; +use render::material::MaterialTilemapHandle; use map::{ TilemapGridSize, TilemapSize, TilemapSpacing, TilemapTexture, TilemapTextureSize, @@ -131,7 +131,7 @@ pub struct MaterialTilemapBundle { pub view_visibility: ViewVisibility, /// User indication of whether tilemap should be frustum culled. pub frustum_culling: FrustumCulling, - pub material: Handle, + pub material: MaterialTilemapHandle, } #[cfg(not(feature = "render"))] From c81f0c806b7ec09739ffb3b6733d416b9ef9f687 Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Wed, 20 Nov 2024 13:20:47 -0700 Subject: [PATCH 15/52] WIP: another handle wrap --- Cargo.toml | 8 +++----- src/render/draw.rs | 7 +++++-- src/render/material.rs | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e5752f9e..58c65e49 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ render = [] serde = ["dep:serde"] [dependencies] -bevy = { git = "https://github.com/bevyengine/bevy", rev = "a06802a66eb0af8c2d2c4ec77a654a5ed5913596", default-features = false, features = [ +bevy = { version = "0.15.0-rc.3", default-features = false, features = [ "bevy_core_pipeline", "bevy_render", "bevy_asset", @@ -34,8 +34,7 @@ tiled = { version = "0.11.0", default-features = false } thiserror = { version = "1.0" } [dev-dependencies.bevy] -git = "https://github.com/bevyengine/bevy" -rev = "a06802a66eb0af8c2d2c4ec77a654a5ed5913596" +version = "0.15.0-rc.3" default-features = false features = [ "bevy_core_pipeline", @@ -52,8 +51,7 @@ features = [ ] [target.'cfg(unix)'.dev-dependencies.bevy] -git = "https://github.com/bevyengine/bevy" -rev = "a06802a66eb0af8c2d2c4ec77a654a5ed5913596" +version = "0.15.0-rc.3" default-features = false features = [ "bevy_core_pipeline", diff --git a/src/render/draw.rs b/src/render/draw.rs index aee9d7cb..490e96ff 100644 --- a/src/render/draw.rs +++ b/src/render/draw.rs @@ -22,7 +22,7 @@ use crate::TilemapTexture; use super::{ chunk::{ChunkId, RenderChunk2dStorage, TilemapUniformData}, - material::{MaterialTilemap, RenderMaterialsTilemap}, + material::{MaterialTilemap, MaterialTilemapHandle, RenderMaterialsTilemap}, prepare::MeshUniform, queue::{ImageBindGroups, TilemapViewBindGroup, TransformBindGroup}, DynamicUniformIndex, @@ -150,7 +150,10 @@ pub struct SetMaterialBindGroup(PhantomData< impl RenderCommand for SetMaterialBindGroup { - type Param = (SRes>, SQuery<&'static Handle>); + type Param = ( + SRes>, + SQuery<&'static MaterialTilemapHandle>, + ); type ViewQuery = (); type ItemQuery = Read; #[inline] diff --git a/src/render/material.rs b/src/render/material.rs index 09093d90..d329a149 100644 --- a/src/render/material.rs +++ b/src/render/material.rs @@ -6,7 +6,7 @@ use bevy::{ prelude::*, reflect::TypePath, render::{ - extract_component::ExtractComponentPlugin, + extract_component::{ExtractComponent, ExtractComponentPlugin}, globals::GlobalsBuffer, render_asset::RenderAssets, render_phase::{ From 6d1480d5ce127be4eca0a8dc84f2b4468f7396d7 Mon Sep 17 00:00:00 2001 From: Rich Churcher Date: Fri, 25 Oct 2024 13:39:15 +1300 Subject: [PATCH 16/52] elapsed_seconds -> elapsed_secs See: https://github.com/bevyengine/bevy/pull/15962 --- examples/accessing_tiles.rs | 2 +- examples/game_of_life.rs | 2 +- examples/random_map.rs | 2 +- examples/remove_tiles.rs | 2 +- examples/visibility.rs | 2 +- src/render/extract.rs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/accessing_tiles.rs b/examples/accessing_tiles.rs index 16929c40..261e4d7a 100644 --- a/examples/accessing_tiles.rs +++ b/examples/accessing_tiles.rs @@ -109,7 +109,7 @@ fn update_map( )>, mut tile_query: Query<&mut TileTextureIndex>, ) { - let current_time = time.elapsed_seconds_f64(); + let current_time = time.elapsed_secs_f64(); for (mut current_color, mut last_update, tile_storage, map_size) in tilemap_query.iter_mut() { if current_time - last_update.0 > 0.1 { current_color.0 += 1; diff --git a/examples/game_of_life.rs b/examples/game_of_life.rs index 6b11cacc..f1e5c978 100644 --- a/examples/game_of_life.rs +++ b/examples/game_of_life.rs @@ -58,7 +58,7 @@ fn update( mut tile_storage_query: Query<(&TileStorage, &TilemapSize, &mut LastUpdate)>, tile_query: Query<(Entity, &TilePos, &TileVisible)>, ) { - let current_time = time.elapsed_seconds_f64(); + let current_time = time.elapsed_secs_f64(); let (tile_storage, map_size, mut last_update) = tile_storage_query.single_mut(); if current_time - last_update.0 > 0.1 { for (entity, position, visibility) in tile_query.iter() { diff --git a/examples/random_map.rs b/examples/random_map.rs index fe32b727..49cadc2f 100644 --- a/examples/random_map.rs +++ b/examples/random_map.rs @@ -57,7 +57,7 @@ struct LastUpdate { // In this example it's better not to use the default `MapQuery` SystemParam as // it's faster to do it this way: fn random(time: ResMut