diff --git a/Cargo.toml b/Cargo.toml index 6e1b9597..af66789a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_ecs_tilemap" description = "A tilemap rendering plugin for bevy which is more ECS friendly by having an entity per tile." -version = "0.11.1" +version = "0.12.0" authors = ["John Mitchell"] homepage = "https://github.com/StarArawn/bevy_ecs_tilemap" repository = "https://github.com/StarArawn/bevy_ecs_tilemap" @@ -16,7 +16,7 @@ atlas = [] render = [] [dependencies] -bevy = { version = "0.11", default-features = false, features = [ +bevy = { version = "0.12", default-features = false, features = [ "bevy_core_pipeline", "bevy_render", "bevy_asset", @@ -26,15 +26,15 @@ log = "0.4" regex = "1.5.4" [dev-dependencies] -anyhow = { version = "1.0" } ldtk_rust = { version = "0.6" } rand = "0.8" env_logger = "0.10" serde_json = { version = "1.0" } tiled = { version = "0.11.0", default-features = false } +thiserror = { version = "1.0" } [dev-dependencies.bevy] -version = "0.11" +version = "0.12" default-features = false features = [ "bevy_core_pipeline", @@ -45,12 +45,13 @@ features = [ "bevy_winit", "bevy_text", "bevy_sprite", - "filesystem_watcher", - "webgl2" + "file_watcher", + "webgl2", + "multi-threaded" ] [target.'cfg(unix)'.dev-dependencies.bevy] -version = "0.11" +version = "0.12" default-features = false features = [ "bevy_core_pipeline", @@ -62,6 +63,7 @@ features = [ "x11", "bevy_text", "bevy_sprite", + "multi-threaded" ] diff --git a/README.md b/README.md index 265da182..b7b645d6 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ cargo run --target wasm32-unknown-unknown --example animation --release --featur |bevy|bevy_ecs_tilemap| |---|---| |`main`|`bevy-track`| +|0.12|0.12| |0.11|0.11.*| |0.10|0.10| |0.9|0.9| diff --git a/examples/3d_iso.rs b/examples/3d_iso.rs index 5afa42a3..1b441fe6 100644 --- a/examples/3d_iso.rs +++ b/examples/3d_iso.rs @@ -1,6 +1,4 @@ -use bevy::utils::Duration; - -use bevy::{asset::ChangeWatcher, prelude::*}; +use bevy::prelude::*; use bevy_ecs_tilemap::prelude::*; mod helpers; @@ -33,11 +31,7 @@ fn main() { }), ..default() }) - .set(ImagePlugin::default_nearest()) - .set(AssetPlugin { - watch_for_changes: ChangeWatcher::with_delay(Duration::from_millis(200)), - ..default() - }), + .set(ImagePlugin::default_nearest()), ) .add_plugins((TilemapPlugin, helpers::tiled::TiledMapPlugin)) .add_systems(Startup, startup) diff --git a/examples/custom_shader.rs b/examples/custom_shader.rs index 361cb80e..3c37a7d6 100644 --- a/examples/custom_shader.rs +++ b/examples/custom_shader.rs @@ -1,13 +1,8 @@ -use bevy::{ - prelude::*, - reflect::{TypePath, TypeUuid}, - render::render_resource::AsBindGroup, -}; +use bevy::{prelude::*, reflect::TypePath, render::render_resource::AsBindGroup}; use bevy_ecs_tilemap::prelude::*; mod helpers; -#[derive(AsBindGroup, TypeUuid, TypePath, Debug, Clone, Default)] -#[uuid = "31575692-a956-4762-98e2-5d457f552d0a"] +#[derive(AsBindGroup, TypePath, Debug, Clone, Default, Asset)] pub struct MyMaterial { #[uniform(0)] brightness: f32, diff --git a/examples/helpers/ldtk.rs b/examples/helpers/ldtk.rs index e00ffc70..d3125c3d 100644 --- a/examples/helpers/ldtk.rs +++ b/examples/helpers/ldtk.rs @@ -4,12 +4,17 @@ use bevy_ecs_tilemap::{ tiles::{TileBundle, TilePos, TileStorage, TileTextureIndex}, TilemapBundle, }; -use std::collections::HashMap; +use std::{collections::HashMap, io::ErrorKind}; +use thiserror::Error; -use bevy::reflect::{TypePath, TypeUuid}; use bevy::{ - asset::{AssetLoader, AssetPath, BoxedFuture, LoadContext, LoadedAsset}, + asset::{io::Reader, AsyncReadExt}, + reflect::TypePath, +}; +use bevy::{ + asset::{AssetLoader, AssetPath, LoadContext}, prelude::*, + utils::BoxedFuture, }; use bevy_ecs_tilemap::map::TilemapType; @@ -18,14 +23,13 @@ pub struct LdtkPlugin; impl Plugin for LdtkPlugin { fn build(&self, app: &mut App) { - app.add_asset::() - .add_asset_loader(LdtkLoader) + app.init_asset::() + .register_asset_loader(LdtkLoader) .add_systems(Update, process_loaded_tile_maps); } } -#[derive(TypeUuid, TypePath)] -#[uuid = "abf9eaf2-f21c-4b46-89b0-8aa5c42199af"] +#[derive(TypePath, Asset)] pub struct LdtkMap { pub project: ldtk_rust::Project, pub tilesets: HashMap>, @@ -46,14 +50,34 @@ pub struct LdtkMapBundle { pub struct LdtkLoader; +#[derive(Debug, Error)] +pub enum LdtkAssetLoaderError { + /// An [IO](std::io) Error + #[error("Could not load LDTk file: {0}")] + Io(#[from] std::io::Error), +} + impl AssetLoader for LdtkLoader { + type Asset = LdtkMap; + type Settings = (); + type Error = LdtkAssetLoaderError; + fn load<'a>( &'a self, - bytes: &'a [u8], + reader: &'a mut Reader, + _settings: &'a Self::Settings, load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result<(), anyhow::Error>> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { - let project: ldtk_rust::Project = serde_json::from_slice(bytes)?; + let mut bytes = Vec::new(); + reader.read_to_end(&mut bytes).await?; + + let project: ldtk_rust::Project = serde_json::from_slice(&bytes).map_err(|e| { + std::io::Error::new( + ErrorKind::Other, + format!("Could not read contents of Ldtk map: {e}"), + ) + })?; let dependencies: Vec<(i64, AssetPath)> = project .defs .tilesets @@ -68,17 +92,14 @@ impl AssetLoader for LdtkLoader { }) .collect(); - let loaded_asset = LoadedAsset::new(LdtkMap { + let ldtk_map = LdtkMap { project, tilesets: dependencies .iter() - .map(|dep| (dep.0, load_context.get_handle(dep.1.clone()))) + .map(|dep| (dep.0, load_context.load(dep.1.clone()))) .collect(), - }); - load_context.set_default_asset( - loaded_asset.with_dependencies(dependencies.iter().map(|x| x.1.clone()).collect()), - ); - Ok(()) + }; + Ok(ldtk_map) }) } @@ -95,35 +116,36 @@ pub fn process_loaded_tile_maps( mut query: Query<(Entity, &Handle, &LdtkMapConfig)>, new_maps: Query<&Handle, Added>>, ) { - let mut changed_maps = Vec::>::default(); - for event in map_events.iter() { + let mut changed_maps = Vec::>::default(); + for event in map_events.read() { match event { - AssetEvent::Created { handle } => { + AssetEvent::Added { id } => { log::info!("Map added!"); - changed_maps.push(handle.clone()); + changed_maps.push(*id); } - AssetEvent::Modified { handle } => { + AssetEvent::Modified { id } => { log::info!("Map changed!"); - changed_maps.push(handle.clone()); + changed_maps.push(*id); } - AssetEvent::Removed { handle } => { + AssetEvent::Removed { id } => { log::info!("Map removed!"); // if mesh was modified and removed in the same update, ignore the modification // events are ordered so future modification events are ok - changed_maps.retain(|changed_handle| changed_handle == handle); + changed_maps.retain(|changed_handle| changed_handle == id); } + _ => continue, } } // If we have new map entities, add them to the changed_maps list for new_map_handle in new_maps.iter() { - changed_maps.push(new_map_handle.clone()); + changed_maps.push(new_map_handle.id()); } for changed_map in changed_maps.iter() { for (entity, map_handle, map_config) in query.iter_mut() { // only deal with currently changed map - if map_handle != changed_map { + if map_handle.id() != *changed_map { continue; } if let Some(ldtk_map) = maps.get(map_handle) { diff --git a/examples/helpers/tiled.rs b/examples/helpers/tiled.rs index c48a89ef..f2ac0256 100644 --- a/examples/helpers/tiled.rs +++ b/examples/helpers/tiled.rs @@ -12,37 +12,37 @@ // * When the 'atlas' feature is enabled tilesets using a collection of images will be skipped. // * Only finite tile layers are loaded. Infinite tile layers and object layers will be skipped. -use std::io::Cursor; +use std::io::{Cursor, ErrorKind}; use std::path::Path; use std::sync::Arc; use bevy::{ - asset::{AssetLoader, AssetPath, LoadedAsset}, + asset::{io::Reader, AssetLoader, AssetPath, AsyncReadExt}, log, prelude::{ - AddAsset, Added, AssetEvent, Assets, Bundle, Commands, Component, DespawnRecursiveExt, - Entity, EventReader, GlobalTransform, Handle, Image, Plugin, Query, Res, Transform, Update, + Added, Asset, AssetApp, AssetEvent, AssetId, Assets, Bundle, Commands, Component, + DespawnRecursiveExt, Entity, EventReader, GlobalTransform, Handle, Image, Plugin, Query, + Res, Transform, Update, }, - reflect::{TypePath, TypeUuid}, - utils::HashMap, + reflect::TypePath, + utils::{BoxedFuture, HashMap}, }; use bevy_ecs_tilemap::prelude::*; -use anyhow::Result; +use thiserror::Error; #[derive(Default)] pub struct TiledMapPlugin; impl Plugin for TiledMapPlugin { fn build(&self, app: &mut bevy::prelude::App) { - app.add_asset::() - .add_asset_loader(TiledLoader) + app.init_asset::() + .register_asset_loader(TiledLoader) .add_systems(Update, process_loaded_maps); } } -#[derive(TypeUuid, TypePath)] -#[uuid = "e51081d0-6168-4881-a1c6-4249b2000d7f"] +#[derive(TypePath, Asset)] pub struct TiledMap { pub map: tiled::Map, @@ -91,27 +91,35 @@ impl tiled::ResourceReader for BytesResourceReader { pub struct TiledLoader; +#[derive(Debug, Error)] +pub enum TiledAssetLoaderError { + /// An [IO](std::io) Error + #[error("Could not load Tiled file: {0}")] + Io(#[from] std::io::Error), +} + impl AssetLoader for TiledLoader { + type Asset = TiledMap; + type Settings = (); + type Error = TiledAssetLoaderError; + fn load<'a>( &'a self, - bytes: &'a [u8], + reader: &'a mut Reader, + _settings: &'a Self::Settings, load_context: &'a mut bevy::asset::LoadContext, - ) -> bevy::asset::BoxedFuture<'a, Result<()>> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { - // The load context path is the TMX file itself. If the file is at the root of the - // assets/ directory structure then the tmx_dir will be empty, which is fine. - let tmx_dir = load_context - .path() - .parent() - .expect("The asset load context was empty."); + let mut bytes = Vec::new(); + reader.read_to_end(&mut bytes).await?; let mut loader = tiled::Loader::with_cache_and_reader( tiled::DefaultResourceCache::new(), - BytesResourceReader::new(bytes), + BytesResourceReader::new(&bytes), ); - let map = loader - .load_tmx_map(load_context.path()) - .map_err(|e| anyhow::anyhow!("Could not load TMX map: {e}"))?; + let map = loader.load_tmx_map(load_context.path()).map_err(|e| { + std::io::Error::new(ErrorKind::Other, format!("Could not load TMX map: {e}")) + })?; let mut dependencies = Vec::new(); let mut tilemap_textures = HashMap::default(); @@ -132,11 +140,17 @@ impl AssetLoader for TiledLoader { let mut tile_images: Vec> = Vec::new(); for (tile_id, tile) in tileset.tiles() { if let Some(img) = &tile.image { + // The load context path is the TMX file itself. If the file is at the root of the + // assets/ directory structure then the tmx_dir will be empty, which is fine. + let tmx_dir = load_context + .path() + .parent() + .expect("The asset load context was empty."); let tile_path = tmx_dir.join(&img.source); - let asset_path = AssetPath::new(tile_path, None); + let asset_path = AssetPath::from(tile_path); log::info!("Loading tile image from {asset_path:?} as image ({tileset_index}, {tile_id})"); let texture: Handle = - load_context.get_handle(asset_path.clone()); + load_context.load(asset_path.clone()); tile_image_offsets .insert((tileset_index, tile_id), tile_images.len() as u32); tile_images.push(texture.clone()); @@ -148,9 +162,15 @@ impl AssetLoader for TiledLoader { } } Some(img) => { + // The load context path is the TMX file itself. If the file is at the root of the + // assets/ directory structure then the tmx_dir will be empty, which is fine. + let tmx_dir = load_context + .path() + .parent() + .expect("The asset load context was empty."); let tile_path = tmx_dir.join(&img.source); - let asset_path = AssetPath::new(tile_path, None); - let texture: Handle = load_context.get_handle(asset_path.clone()); + let asset_path = AssetPath::from(tile_path); + let texture: Handle = load_context.load(asset_path.clone()); dependencies.push(asset_path); TilemapTexture::Single(texture.clone()) @@ -168,10 +188,7 @@ impl AssetLoader for TiledLoader { }; log::info!("Loaded map: {}", load_context.path().display()); - - let loaded_asset = LoadedAsset::new(asset_map); - load_context.set_default_asset(loaded_asset.with_dependencies(dependencies)); - Ok(()) + Ok(asset_map) }) } @@ -189,35 +206,36 @@ pub fn process_loaded_maps( mut map_query: Query<(&Handle, &mut TiledLayersStorage)>, new_maps: Query<&Handle, Added>>, ) { - let mut changed_maps = Vec::>::default(); - for event in map_events.iter() { + let mut changed_maps = Vec::>::default(); + for event in map_events.read() { match event { - AssetEvent::Created { handle } => { + AssetEvent::Added { id } => { log::info!("Map added!"); - changed_maps.push(handle.clone()); + changed_maps.push(*id); } - AssetEvent::Modified { handle } => { + AssetEvent::Modified { id } => { log::info!("Map changed!"); - changed_maps.push(handle.clone()); + changed_maps.push(*id); } - AssetEvent::Removed { handle } => { + AssetEvent::Removed { id } => { log::info!("Map removed!"); // if mesh was modified and removed in the same update, ignore the modification // events are ordered so future modification events are ok - changed_maps.retain(|changed_handle| changed_handle == handle); + changed_maps.retain(|changed_handle| changed_handle == id); } + _ => continue, } } // If we have new map entities add them to the changed_maps list. for new_map_handle in new_maps.iter() { - changed_maps.push(new_map_handle.clone_weak()); + changed_maps.push(new_map_handle.id()); } for changed_map in changed_maps.iter() { for (map_handle, mut layer_storage) in map_query.iter_mut() { // only deal with currently changed map - if map_handle != changed_map { + if map_handle.id() != *changed_map { continue; } if let Some(tiled_map) = maps.get(map_handle) { diff --git a/examples/hex_neighbors.rs b/examples/hex_neighbors.rs index b30a0e72..6288d316 100644 --- a/examples/hex_neighbors.rs +++ b/examples/hex_neighbors.rs @@ -256,7 +256,7 @@ pub fn update_cursor_pos( mut cursor_moved_events: EventReader, mut cursor_pos: ResMut, ) { - for cursor_moved in cursor_moved_events.iter() { + for cursor_moved in cursor_moved_events.read() { // To get the mouse's world position, we have to transform its window position by // any transforms on the camera. This is done by projecting the cursor position into // camera space (world space). diff --git a/examples/hex_neighbors_radius_chunks.rs b/examples/hex_neighbors_radius_chunks.rs index afdd8e04..628dbb9f 100644 --- a/examples/hex_neighbors_radius_chunks.rs +++ b/examples/hex_neighbors_radius_chunks.rs @@ -377,7 +377,7 @@ pub fn update_cursor_pos( mut cursor_moved_events: EventReader, mut cursor_pos: ResMut, ) { - for cursor_moved in cursor_moved_events.iter() { + for cursor_moved in cursor_moved_events.read() { // To get the mouse's world position, we have to transform its window position by // any transforms on the camera. This is done by projecting the cursor position into // camera space (world space). diff --git a/examples/ldtk.rs b/examples/ldtk.rs index 43a63dd9..8e68a22c 100644 --- a/examples/ldtk.rs +++ b/examples/ldtk.rs @@ -8,9 +8,7 @@ //! //! For a more comprehensive LDtk solution, consider [bevy_ecs_ldtk](https://github.com/Trouv/bevy_ecs_ldtk), which uses bevy_ecs_tilemap internally. -use bevy::utils::Duration; - -use bevy::{asset::ChangeWatcher, prelude::*}; +use bevy::prelude::*; use bevy_ecs_tilemap::*; mod helpers; @@ -38,11 +36,7 @@ fn main() { }), ..default() }) - .set(ImagePlugin::default_nearest()) - .set(AssetPlugin { - watch_for_changes: ChangeWatcher::with_delay(Duration::from_millis(200)), - ..default() - }), + .set(ImagePlugin::default_nearest()), ) .add_plugins(TilemapPlugin) .add_plugins(helpers::ldtk::LdtkPlugin) diff --git a/examples/mouse_to_tile.rs b/examples/mouse_to_tile.rs index 13f4f215..2a0bf550 100644 --- a/examples/mouse_to_tile.rs +++ b/examples/mouse_to_tile.rs @@ -299,7 +299,7 @@ pub fn update_cursor_pos( mut cursor_moved_events: EventReader, mut cursor_pos: ResMut, ) { - for cursor_moved in cursor_moved_events.iter() { + for cursor_moved in cursor_moved_events.read() { // To get the mouse's world position, we have to transform its window position by // any transforms on the camera. This is done by projecting the cursor position into // camera space (world space). diff --git a/examples/tiled.rs b/examples/tiled.rs index 3426585a..79e59292 100644 --- a/examples/tiled.rs +++ b/examples/tiled.rs @@ -1,6 +1,4 @@ -use bevy::utils::Duration; - -use bevy::{asset::ChangeWatcher, prelude::*}; +use bevy::prelude::*; use bevy_ecs_tilemap::prelude::*; mod helpers; @@ -27,11 +25,7 @@ fn main() { }), ..default() }) - .set(ImagePlugin::default_nearest()) - .set(AssetPlugin { - watch_for_changes: ChangeWatcher::with_delay(Duration::from_millis(200)), - ..default() - }), + .set(ImagePlugin::default_nearest()), ) .add_plugins(TilemapPlugin) .add_plugins(helpers::tiled::TiledMapPlugin) diff --git a/examples/tiled_rotated.rs b/examples/tiled_rotated.rs index d0c7f9b2..bca68123 100644 --- a/examples/tiled_rotated.rs +++ b/examples/tiled_rotated.rs @@ -1,6 +1,4 @@ -use bevy::utils::Duration; - -use bevy::{asset::ChangeWatcher, prelude::*}; +use bevy::prelude::*; use bevy_ecs_tilemap::prelude::*; mod helpers; @@ -27,11 +25,7 @@ fn main() { }), ..default() }) - .set(ImagePlugin::default_nearest()) - .set(AssetPlugin { - watch_for_changes: ChangeWatcher::with_delay(Duration::from_millis(200)), - ..default() - }), + .set(ImagePlugin::default_nearest()), ) .add_plugins(TilemapPlugin) .add_plugins(helpers::tiled::TiledMapPlugin) diff --git a/src/array_texture_preload.rs b/src/array_texture_preload.rs index 909546f3..9a894237 100644 --- a/src/array_texture_preload.rs +++ b/src/array_texture_preload.rs @@ -68,14 +68,14 @@ pub(crate) fn extract( if array_texture.filter.is_none() { array_texture .filter - .replace(default_image_settings.mag_filter); + .replace(default_image_settings.mag_filter.into()); } if array_texture.texture.verify_ready(&images) { texture_array_cache.add_texture( array_texture.texture, array_texture.tile_size, array_texture.tile_spacing, - default_image_settings.min_filter, + default_image_settings.min_filter.into(), array_texture.format, &images, ); diff --git a/src/lib.rs b/src/lib.rs index 9509256d..bb6e3d01 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,8 +15,8 @@ //! - Texture array support. use bevy::prelude::{ - Bundle, Changed, Component, ComputedVisibility, Deref, First, GlobalTransform, Plugin, Query, - Reflect, ReflectComponent, Transform, Visibility, + Bundle, Changed, Component, Deref, First, GlobalTransform, InheritedVisibility, Plugin, Query, + Reflect, ReflectComponent, Transform, ViewVisibility, Visibility, }; #[cfg(feature = "render")] @@ -118,7 +118,8 @@ pub struct MaterialTilemapBundle { pub visibility: Visibility, /// Algorithmically-computed indication of whether an entity is visible and should be extracted /// for rendering - pub computed_visibility: ComputedVisibility, + pub inherited_visibility: InheritedVisibility, + pub view_visibility: ViewVisibility, /// User indication of whether tilemap should be frustum culled. pub frustum_culling: FrustumCulling, pub material: Handle, @@ -141,7 +142,8 @@ pub struct StandardTilemapBundle { pub visibility: Visibility, /// Algorithmically-computed indication of whether an entity is visible and should be extracted /// for rendering - pub computed_visibility: ComputedVisibility, + pub inherited_visibility: InheritedVisibility, + pub view_visibility: ViewVisibility, /// User indication of whether tilemap should be frustum culled. pub frustum_culling: FrustumCulling, } diff --git a/src/render/chunk.rs b/src/render/chunk.rs index d84ba2ab..d56a0652 100644 --- a/src/render/chunk.rs +++ b/src/render/chunk.rs @@ -1,11 +1,11 @@ use std::hash::{Hash, Hasher}; use bevy::math::Mat4; -use bevy::prelude::{Resource, Transform}; +use bevy::prelude::{InheritedVisibility, Resource, Transform}; use bevy::render::primitives::Aabb; use bevy::{ math::{UVec2, UVec3, UVec4, Vec2, Vec3Swizzles, Vec4, Vec4Swizzles}, - prelude::{Component, ComputedVisibility, Entity, GlobalTransform, Mesh, Vec3}, + prelude::{Component, Entity, GlobalTransform, Mesh, Vec3}, render::{ mesh::{GpuBufferInfo, GpuMesh, Indices, VertexAttributeValues}, render_resource::{BufferInitDescriptor, BufferUsages, ShaderType}, @@ -49,7 +49,7 @@ impl RenderChunk2dStorage { texture: TilemapTexture, map_size: TilemapSize, transform: GlobalTransform, - visibility: &ComputedVisibility, + visibility: &InheritedVisibility, frustum_culling: &FrustumCulling, ) -> &mut RenderChunk2d { let pos = position.xyz(); @@ -84,7 +84,7 @@ impl RenderChunk2dStorage { texture_size, map_size, transform, - visibility.is_visible(), + visibility.get(), **frustum_culling, ); self.entity_to_chunk.insert(chunk_entity, pos); diff --git a/src/render/draw.rs b/src/render/draw.rs index 20808d4b..0fccb06f 100644 --- a/src/render/draw.rs +++ b/src/render/draw.rs @@ -155,7 +155,7 @@ impl RenderCommand if let Ok(material_handle) = material_handles.get(id.0) { let bind_group = material_bind_groups .into_inner() - .get(material_handle) + .get(&material_handle.id()) .unwrap(); pass.set_bind_group(I, &bind_group.bind_group, &[]); } diff --git a/src/render/extract.rs b/src/render/extract.rs index a65fe10d..a84c4087 100644 --- a/src/render/extract.rs +++ b/src/render/extract.rs @@ -1,3 +1,4 @@ +use bevy::math::Affine3A; use bevy::prelude::Res; use bevy::prelude::Time; use bevy::render::primitives::{Aabb, Frustum}; @@ -65,7 +66,7 @@ pub struct ExtractedTilemapBundle { map_type: TilemapType, texture: TilemapTexture, map_size: TilemapSize, - visibility: ComputedVisibility, + visibility: InheritedVisibility, frustum_culling: FrustumCulling, } @@ -96,7 +97,7 @@ impl ExtractedTilemapTexture { "Expected image to have finished loading if \ it is being extracted as a texture!", ); - let texture_size: TilemapTextureSize = image.size().into(); + let texture_size: TilemapTextureSize = image.size_f32().into(); let tile_count_x = ((texture_size.x) / (tile_size.x + tile_spacing.x)).floor(); let tile_count_y = ((texture_size.y) / (tile_size.y + tile_spacing.y)).floor(); ( @@ -112,7 +113,7 @@ impl ExtractedTilemapTexture { "Expected image to have finished loading if \ it is being extracted as a texture!", ); - let this_tile_size: TilemapTileSize = image.size().into(); + let this_tile_size: TilemapTileSize = image.size_f32().into(); if this_tile_size != tile_size { panic!( "Expected all provided image assets to have size {tile_size:?}, \ @@ -141,7 +142,7 @@ impl ExtractedTilemapTexture { "Expected image to have finished loading if \ it is being extracted as a texture!", ); - let tile_size: TilemapTileSize = image.size().into(); + let tile_size: TilemapTileSize = image.size_f32().into(); ( image.texture_descriptor.array_layer_count(), tile_size.into(), @@ -176,7 +177,7 @@ pub struct ExtractedFrustum { impl ExtractedFrustum { pub fn intersects_obb(&self, aabb: &Aabb, transform_matrix: &Mat4) -> bool { self.frustum - .intersects_obb(aabb, transform_matrix, true, false) + .intersects_obb(aabb, &Affine3A::from_mat4(*transform_matrix), true, false) } } @@ -216,7 +217,7 @@ pub fn extract( &TilemapType, &TilemapTexture, &TilemapSize, - &ComputedVisibility, + &InheritedVisibility, &FrustumCulling, )>, >, @@ -232,7 +233,7 @@ pub fn extract( Changed, Changed, Changed, - Changed, + Changed, Changed, )>, >, @@ -296,7 +297,7 @@ pub fn extract( map_type: *data.5, texture: data.6.clone_weak(), map_size: *data.7, - visibility: data.8.clone(), + visibility: *data.8, frustum_culling: *data.9, }, ), @@ -331,7 +332,7 @@ pub fn extract( map_type: *data.5, texture: data.6.clone_weak(), map_size: *data.7, - visibility: data.8.clone(), + visibility: *data.8, frustum_culling: *data.9, }, ), @@ -353,7 +354,7 @@ pub fn extract( texture.clone_weak(), *tile_size, *tile_spacing, - default_image_settings.0.min_filter, + default_image_settings.0.min_filter.into(), &images, ), }, diff --git a/src/render/material.rs b/src/render/material.rs index f1643696..cc6ffe44 100644 --- a/src/render/material.rs +++ b/src/render/material.rs @@ -1,17 +1,16 @@ use bevy::{ core_pipeline::core_2d::Transparent2d, prelude::*, - reflect::{TypePath, TypeUuid}, + reflect::TypePath, render::{ extract_component::ExtractComponentPlugin, globals::GlobalsBuffer, - render_asset::{PrepareAssetSet, RenderAssets}, + render_asset::RenderAssets, render_phase::{AddRenderCommand, DrawFunctions, RenderPhase}, render_resource::{ - AsBindGroup, AsBindGroupError, BindGroup, BindGroupDescriptor, BindGroupEntry, - BindGroupLayout, BindingResource, OwnedBindingResource, PipelineCache, - RenderPipelineDescriptor, ShaderRef, SpecializedRenderPipeline, - SpecializedRenderPipelines, + AsBindGroup, AsBindGroupError, BindGroup, BindGroupEntry, BindGroupLayout, + BindingResource, OwnedBindingResource, PipelineCache, RenderPipelineDescriptor, + ShaderRef, SpecializedRenderPipeline, SpecializedRenderPipelines, }, renderer::RenderDevice, texture::FallbackImage, @@ -38,9 +37,7 @@ use super::{ #[cfg(not(feature = "atlas"))] pub(crate) use super::TextureArrayCache; -pub trait MaterialTilemap: - AsBindGroup + Send + Sync + Clone + TypeUuid + TypePath + Sized + 'static -{ +pub trait MaterialTilemap: AsBindGroup + Asset + Clone + Sized { /// Returns this material's vertex shader. If [`ShaderRef::Default`] is returned, the default mesh vertex shader /// will be used. fn vertex_shader() -> ShaderRef { @@ -111,7 +108,7 @@ where M::Data: PartialEq + Eq + Hash + Clone, { fn build(&self, app: &mut App) { - app.add_asset::() + app.init_asset::() .add_plugins(ExtractComponentPlugin::>::extract_visible()); } @@ -126,28 +123,29 @@ where .add_systems(ExtractSchedule, extract_materials_tilemap::) .add_systems( Render, - prepare_materials_tilemap:: - .in_set(RenderSet::Prepare) - .after(PrepareAssetSet::PreAssetPrepare), + prepare_materials_tilemap::.in_set(RenderSet::PrepareAssets), ) .add_systems( Render, - queue_material_tilemap_meshes::.in_set(RenderSet::Queue), + ( + queue_material_tilemap_meshes::.in_set(RenderSet::Queue), + bind_material_tilemap_meshes::.in_set(RenderSet::PrepareBindGroups), + ), ); } } } pub struct PreparedMaterialTilemap { - pub bindings: Vec, + pub bindings: Vec<(u32, OwnedBindingResource)>, pub bind_group: BindGroup, pub key: T::Data, } #[derive(Resource)] struct ExtractedMaterialsTilemap { - extracted: Vec<(Handle, M)>, - removed: Vec>, + extracted: Vec<(AssetId, M)>, + removed: Vec>, } impl Default for ExtractedMaterialsTilemap { @@ -234,7 +232,7 @@ impl FromWorld for MaterialTilemapPipeline { /// Stores all prepared representations of [`Material2d`] assets for as long as they exist. #[derive(Resource, Deref, DerefMut)] pub struct RenderMaterialsTilemap( - HashMap, PreparedMaterialTilemap>, + HashMap, PreparedMaterialTilemap>, ); impl Default for RenderMaterialsTilemap { @@ -252,22 +250,23 @@ fn extract_materials_tilemap( ) { let mut changed_assets = HashSet::default(); let mut removed = Vec::new(); - for event in events.iter() { + for event in events.read() { match event { - AssetEvent::Created { handle } | AssetEvent::Modified { handle } => { - changed_assets.insert(handle.clone_weak()); + AssetEvent::Added { id } | AssetEvent::Modified { id } => { + changed_assets.insert(id); } - AssetEvent::Removed { handle } => { - changed_assets.remove(handle); - removed.push(handle.clone_weak()); + AssetEvent::Removed { id } => { + changed_assets.remove(id); + removed.push(*id); } + _ => continue, } } let mut extracted_assets = Vec::new(); - for handle in changed_assets.drain() { - if let Some(asset) = assets.get(&handle) { - extracted_assets.push((handle, asset.clone())); + for id in changed_assets.drain() { + if let Some(asset) = assets.get(*id) { + extracted_assets.push((*id, asset.clone())); } } @@ -279,7 +278,7 @@ fn extract_materials_tilemap( /// All [`Material2d`] values of a given type that should be prepared next frame. pub struct PrepareNextFrameMaterials { - assets: Vec<(Handle, M)>, + assets: Vec<(AssetId, M)>, } impl Default for PrepareNextFrameMaterials { @@ -363,13 +362,11 @@ fn prepare_material_tilemap( #[allow(clippy::too_many_arguments)] pub fn queue_material_tilemap_meshes( - mut commands: Commands, y_sort: Res, chunk_storage: Res, transparent_2d_draw_functions: Res>, render_device: Res, - (tilemap_pipeline, material_tilemap_pipeline, mut material_pipelines): ( - Res, + (material_tilemap_pipeline, mut material_pipelines): ( Res>, ResMut>>, ), @@ -378,13 +375,11 @@ pub fn queue_material_tilemap_meshes( gpu_images: Res>, msaa: Res, globals_buffer: Res, - mut image_bind_groups: ResMut, (standard_tilemap_meshes, materials): ( Query<(Entity, &ChunkId, &Transform, &TilemapId)>, Query<&Handle>, ), mut views: Query<( - Entity, &ExtractedView, &VisibleEntities, &mut RenderPhase, @@ -404,13 +399,119 @@ pub fn queue_material_tilemap_meshes( return; } + if view_uniforms.uniforms.binding().is_none() && globals_buffer.buffer.binding().is_none() { + return; + } + + for (view, visible_entities, mut transparent_phase) in views.iter_mut() { + let draw_tilemap = transparent_2d_draw_functions + .read() + .get_id::>() + .unwrap(); + + for (entity, chunk_id, transform, tilemap_id) in standard_tilemap_meshes.iter() { + if !visible_entities + .entities + .iter() + .any(|&entity| entity.index() == tilemap_id.0.index()) + { + continue; + } + + let Ok(material_handle) = materials.get(tilemap_id.0) else { + continue; + }; + let Some(material) = render_materials.get(&material_handle.id()) else { + continue; + }; + + if let Some(chunk) = chunk_storage.get(&UVec4::new( + chunk_id.0.x, + chunk_id.0.y, + chunk_id.0.z, + tilemap_id.0.index(), + )) { + #[cfg(not(feature = "atlas"))] + if !texture_array_cache.contains(&chunk.texture) { + continue; + } + + #[cfg(feature = "atlas")] + if gpu_images.get(chunk.texture.image_handle()).is_none() { + continue; + } + + let key = TilemapPipelineKey { + msaa: msaa.samples(), + map_type: chunk.get_map_type(), + hdr: view.hdr, + }; + + let pipeline_id = material_pipelines.specialize( + &pipeline_cache, + &material_tilemap_pipeline, + MaterialTilemapKey { + tilemap_pipeline_key: key, + bind_group_data: material.key.clone(), + }, + ); + let z = if **y_sort { + transform.translation.z + + (1.0 + - (transform.translation.y + / (chunk.map_size.y as f32 * chunk.tile_size.y))) + } else { + transform.translation.z + }; + transparent_phase.add(Transparent2d { + entity, + draw_function: draw_tilemap, + pipeline: pipeline_id, + sort_key: FloatOrd(z), + batch_range: 0..1, + dynamic_offset: None, + }); + } + } + } +} + +#[allow(clippy::too_many_arguments)] +pub fn bind_material_tilemap_meshes( + mut commands: Commands, + chunk_storage: Res, + render_device: Res, + tilemap_pipeline: Res, + view_uniforms: Res, + gpu_images: Res>, + globals_buffer: Res, + mut image_bind_groups: ResMut, + (standard_tilemap_meshes, materials): (Query<(&ChunkId, &TilemapId)>, Query<&Handle>), + mut views: Query<(Entity, &VisibleEntities)>, + render_materials: Res>, + #[cfg(not(feature = "atlas"))] (mut texture_array_cache, render_queue): ( + ResMut, + Res, + ), +) where + M::Data: PartialEq + Eq + Hash + Clone, +{ + #[cfg(not(feature = "atlas"))] + texture_array_cache.queue(&render_device, &render_queue, &gpu_images); + + if standard_tilemap_meshes.is_empty() { + return; + } + if let (Some(view_binding), Some(globals)) = ( view_uniforms.uniforms.binding(), globals_buffer.buffer.binding(), ) { - for (entity, view, visible_entities, mut transparent_phase) in views.iter_mut() { - let view_bind_group = render_device.create_bind_group(&BindGroupDescriptor { - entries: &[ + for (entity, visible_entities) in views.iter_mut() { + let view_bind_group = render_device.create_bind_group( + Some("tilemap_view_bind_group"), + &tilemap_pipeline.view_layout, + &[ BindGroupEntry { binding: 0, resource: view_binding.clone(), @@ -420,20 +521,13 @@ pub fn queue_material_tilemap_meshes( resource: globals.clone(), }, ], - label: Some("tilemap_view_bind_group"), - layout: &tilemap_pipeline.view_layout, - }); + ); commands.entity(entity).insert(TilemapViewBindGroup { value: view_bind_group, }); - let draw_tilemap = transparent_2d_draw_functions - .read() - .get_id::>() - .unwrap(); - - for (entity, chunk_id, transform, tilemap_id) in standard_tilemap_meshes.iter() { + for (chunk_id, tilemap_id) in standard_tilemap_meshes.iter() { if !visible_entities .entities .iter() @@ -445,7 +539,7 @@ pub fn queue_material_tilemap_meshes( let Ok(material_handle) = materials.get(tilemap_id.0) else { continue; }; - let Some(material) = render_materials.get(material_handle) else { + if render_materials.get(&material_handle.id()).is_none() { continue; }; @@ -473,8 +567,10 @@ pub fn queue_material_tilemap_meshes( let gpu_image = texture_array_cache.get(&chunk.texture); #[cfg(feature = "atlas")] let gpu_image = gpu_images.get(chunk.texture.image_handle()).unwrap(); - render_device.create_bind_group(&BindGroupDescriptor { - entries: &[ + render_device.create_bind_group( + Some("sprite_material_bind_group"), + &tilemap_pipeline.material_layout, + &[ BindGroupEntry { binding: 0, resource: BindingResource::TextureView( @@ -486,48 +582,15 @@ pub fn queue_material_tilemap_meshes( resource: BindingResource::Sampler(&gpu_image.sampler), }, ], - label: Some("sprite_material_bind_group"), - layout: &tilemap_pipeline.material_layout, - }) + ) }); - - let key = TilemapPipelineKey { - msaa: msaa.samples(), - map_type: chunk.get_map_type(), - hdr: view.hdr, - }; - - let pipeline_id = material_pipelines.specialize( - &pipeline_cache, - &material_tilemap_pipeline, - MaterialTilemapKey { - tilemap_pipeline_key: key, - bind_group_data: material.key.clone(), - }, - ); - let z = if **y_sort { - transform.translation.z - + (1.0 - - (transform.translation.y - / (chunk.map_size.y as f32 * chunk.tile_size.y))) - } else { - transform.translation.z - }; - transparent_phase.add(Transparent2d { - entity, - draw_function: draw_tilemap, - pipeline: pipeline_id, - sort_key: FloatOrd(z), - batch_range: None, - }); } } } } } -#[derive(AsBindGroup, TypeUuid, Debug, Clone, Default, TypePath)] -#[uuid = "d6f8aeb8-510c-499a-9c0b-38551ae0b72a"] +#[derive(AsBindGroup, Debug, Clone, Default, TypePath, Asset)] pub struct StandardTilemapMaterial {} impl MaterialTilemap for StandardTilemapMaterial {} diff --git a/src/render/mod.rs b/src/render/mod.rs index 146376c5..1f50d180 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -4,13 +4,11 @@ use bevy::{ asset::load_internal_asset, core_pipeline::core_2d::Transparent2d, prelude::*, - reflect::TypeUuid, render::{ mesh::MeshVertexAttribute, render_phase::AddRenderCommand, - render_resource::{ - FilterMode, SamplerDescriptor, SpecializedRenderPipelines, VertexFormat, - }, + render_resource::{FilterMode, SpecializedRenderPipelines, VertexFormat}, + texture::ImageSamplerDescriptor, Render, RenderApp, RenderSet, }, }; @@ -58,7 +56,7 @@ const CHUNK_SIZE_2D: UVec2 = UVec2::from_array([64, 64]); pub(crate) struct ExtractedFilterMode(FilterMode); #[derive(Resource, Deref)] -pub struct DefaultSampler(SamplerDescriptor<'static>); +pub struct DefaultSampler(ImageSamplerDescriptor); /// Size of the chunks used to render the tilemap. /// @@ -99,30 +97,18 @@ pub struct TilemapRenderingPlugin; #[derive(Resource, Default, Deref, DerefMut)] pub struct SecondsSinceStartup(pub f32); -pub const COLUMN_EVEN_HEX: HandleUntyped = - HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 7704924705970804993); -pub const COLUMN_HEX: HandleUntyped = - HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 11710877199891728627); -pub const COLUMN_ODD_HEX: HandleUntyped = - HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 6706359414982022142); -pub const COMMON: HandleUntyped = - HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 15420881977837458322); -pub const DIAMOND_ISO: HandleUntyped = - HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 6710251300621614118); -pub const MESH_OUTPUT: HandleUntyped = - HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 2707251459590872179); -pub const ROW_EVEN_HEX: HandleUntyped = - HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 7149718726759672633); -pub const ROW_HEX: HandleUntyped = - HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 5506589682629967569); -pub const ROW_ODD_HEX: HandleUntyped = - HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 13608302855194400936); -pub const STAGGERED_ISO: HandleUntyped = - HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 9802843761568314416); -pub const SQUARE: HandleUntyped = - HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 7333720254399106799); -pub const TILEMAP_VERTEX_OUTPUT: HandleUntyped = - HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 6104533649830094529); +pub const COLUMN_EVEN_HEX: Handle = Handle::weak_from_u128(7704924705970804993); +pub const COLUMN_HEX: Handle = Handle::weak_from_u128(11710877199891728627); +pub const COLUMN_ODD_HEX: Handle = Handle::weak_from_u128(6706359414982022142); +pub const COMMON: Handle = Handle::weak_from_u128(15420881977837458322); +pub const DIAMOND_ISO: Handle = Handle::weak_from_u128(6710251300621614118); +pub const MESH_OUTPUT: Handle = Handle::weak_from_u128(2707251459590872179); +pub const ROW_EVEN_HEX: Handle = Handle::weak_from_u128(7149718726759672633); +pub const ROW_HEX: Handle = Handle::weak_from_u128(5506589682629967569); +pub const ROW_ODD_HEX: Handle = Handle::weak_from_u128(13608302855194400936); +pub const STAGGERED_ISO: Handle = Handle::weak_from_u128(9802843761568314416); +pub const SQUARE: Handle = Handle::weak_from_u128(7333720254399106799); +pub const TILEMAP_VERTEX_OUTPUT: Handle = Handle::weak_from_u128(6104533649830094529); impl Plugin for TilemapRenderingPlugin { fn build(&self, app: &mut App) { @@ -136,7 +122,7 @@ impl Plugin for TilemapRenderingPlugin { app.world .resource_mut::>() - .set_untracked( + .insert( Handle::::default(), StandardTilemapMaterial::default(), ); @@ -252,7 +238,7 @@ impl Plugin for TilemapRenderingPlugin { #[cfg(not(feature = "atlas"))] render_app .init_resource::() - .add_systems(Render, prepare_textures.in_set(RenderSet::Prepare)); + .add_systems(Render, prepare_textures.in_set(RenderSet::PrepareAssets)); render_app .insert_resource(DefaultSampler(sampler)) @@ -268,11 +254,11 @@ impl Plugin for TilemapRenderingPlugin { Render, (prepare::prepare_removal, prepare::prepare) .chain() - .in_set(RenderSet::Prepare), + .in_set(RenderSet::PrepareAssets), ) .add_systems( Render, - queue::queue_transform_bind_group.in_set(RenderSet::Queue), + queue::queue_transform_bind_group.in_set(RenderSet::PrepareBindGroups), ) .init_resource::() .init_resource::>() @@ -321,7 +307,7 @@ pub struct RemovedTileEntity(pub Entity); pub struct RemovedMapEntity(pub Entity); fn removal_helper(mut commands: Commands, mut removed_query: RemovedComponents) { - for entity in removed_query.iter() { + for entity in removed_query.read() { commands.spawn(RemovedTileEntity(entity)); } } @@ -330,7 +316,7 @@ fn removal_helper_tilemap( mut commands: Commands, mut removed_query: RemovedComponents, ) { - for entity in removed_query.iter() { + for entity in removed_query.read() { commands.spawn(RemovedMapEntity(entity)); } } diff --git a/src/render/pipeline.rs b/src/render/pipeline.rs index 6752b4c0..8beb2c27 100644 --- a/src/render/pipeline.rs +++ b/src/render/pipeline.rs @@ -1,6 +1,5 @@ use bevy::{ - prelude::{Component, FromWorld, HandleUntyped, Resource, Shader, World}, - reflect::TypeUuid, + prelude::{Component, FromWorld, Handle, Resource, Shader, World}, render::{ globals::GlobalsUniform, render_resource::{ @@ -22,10 +21,8 @@ use crate::map::{HexCoordSystem, IsoCoordSystem, TilemapType}; use super::{chunk::TilemapUniformData, prepare::MeshUniform}; -pub const TILEMAP_SHADER_VERTEX: HandleUntyped = - HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 8094008129742001941); -pub const TILEMAP_SHADER_FRAGMENT: HandleUntyped = - HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 5716002228110903793); +pub const TILEMAP_SHADER_VERTEX: Handle = Handle::weak_from_u128(8094008129742001941); +pub const TILEMAP_SHADER_FRAGMENT: Handle = Handle::weak_from_u128(5716002228110903793); #[derive(Clone, Resource)] pub struct TilemapPipeline { @@ -194,13 +191,13 @@ impl SpecializedRenderPipeline for TilemapPipeline { RenderPipelineDescriptor { vertex: VertexState { - shader: TILEMAP_SHADER_VERTEX.typed::(), + shader: TILEMAP_SHADER_VERTEX, entry_point: "vertex".into(), shader_defs: shader_defs.clone(), buffers: vec![vertex_layout], }, fragment: Some(FragmentState { - shader: TILEMAP_SHADER_FRAGMENT.typed::(), + shader: TILEMAP_SHADER_FRAGMENT, shader_defs, entry_point: "fragment".into(), targets: vec![Some(ColorTargetState { diff --git a/src/render/prepare.rs b/src/render/prepare.rs index 2ee7b681..f8fac976 100644 --- a/src/render/prepare.rs +++ b/src/render/prepare.rs @@ -9,12 +9,10 @@ use crate::{ prelude::TilemapGridSize, render::RenderChunkSize, render::SecondsSinceStartup, FrustumCulling, }; use bevy::log::trace; -use bevy::prelude::Resource; +use bevy::prelude::{InheritedVisibility, Resource}; use bevy::{ math::{Mat4, UVec4}, - prelude::{ - Commands, Component, ComputedVisibility, Entity, GlobalTransform, Query, Res, ResMut, Vec2, - }, + prelude::{Commands, Component, Entity, GlobalTransform, Query, Res, ResMut, Vec2}, render::{ render_resource::{DynamicUniformBuffer, ShaderType}, renderer::{RenderDevice, RenderQueue}, @@ -56,7 +54,7 @@ pub(crate) fn prepare( &TilemapType, &TilemapTexture, &TilemapSize, - &ComputedVisibility, + &InheritedVisibility, &FrustumCulling, )>, extracted_tilemap_textures: Query<&ExtractedTilemapTexture>, @@ -145,7 +143,7 @@ pub(crate) fn prepare( chunk.map_size = *map_size; chunk.texture_size = (*texture_size).into(); chunk.spacing = (*spacing).into(); - chunk.visible = visibility.is_visible(); + chunk.visible = visibility.get(); chunk.frustum_culling = **frustum_culling; chunk.update_geometry( (*global_transform).into(), diff --git a/src/render/queue.rs b/src/render/queue.rs index ca0353f8..01ae5b78 100644 --- a/src/render/queue.rs +++ b/src/render/queue.rs @@ -1,7 +1,7 @@ use bevy::{ prelude::*, render::{ - render_resource::{BindGroup, BindGroupDescriptor, BindGroupEntry}, + render_resource::{BindGroup, BindGroupEntry}, renderer::RenderDevice, }, utils::HashMap, @@ -29,8 +29,10 @@ pub fn queue_transform_bind_group( (transform_uniforms.0.binding(), tilemap_uniforms.0.binding()) { commands.insert_resource(TransformBindGroup { - value: render_device.create_bind_group(&BindGroupDescriptor { - entries: &[ + value: render_device.create_bind_group( + Some("transform_bind_group"), + &tilemap_pipeline.mesh_layout, + &[ BindGroupEntry { binding: 0, resource: binding1, @@ -40,9 +42,7 @@ pub fn queue_transform_bind_group( resource: binding2, }, ], - label: Some("transform_bind_group"), - layout: &tilemap_pipeline.mesh_layout, - }), + ), }); } } diff --git a/src/render/shaders/column_even_hex.wgsl b/src/render/shaders/column_even_hex.wgsl index 1c2bbd29..8550ac9d 100644 --- a/src/render/shaders/column_even_hex.wgsl +++ b/src/render/shaders/column_even_hex.wgsl @@ -1,7 +1,7 @@ #define_import_path bevy_ecs_tilemap::column_even_hex -#import bevy_ecs_tilemap::mesh_output MeshOutput -#import bevy_ecs_tilemap::common VertexInput, tilemap_data, mesh +#import bevy_ecs_tilemap::mesh_output::MeshOutput +#import bevy_ecs_tilemap::common::{VertexInput, tilemap_data, mesh} // Gets the screen space coordinates of the bottom left of an isometric tile position. fn hex_col_tile_pos_to_world_pos(pos: vec2, grid_width: f32, grid_height: f32) -> vec2 { diff --git a/src/render/shaders/column_hex.wgsl b/src/render/shaders/column_hex.wgsl index 2bf6ddc2..371447b6 100644 --- a/src/render/shaders/column_hex.wgsl +++ b/src/render/shaders/column_hex.wgsl @@ -1,7 +1,7 @@ #define_import_path bevy_ecs_tilemap::column_hex -#import bevy_ecs_tilemap::common VertexInput, tilemap_data, mesh -#import bevy_ecs_tilemap::mesh_output MeshOutput +#import bevy_ecs_tilemap::common::{VertexInput, tilemap_data, mesh} +#import bevy_ecs_tilemap::mesh_output::MeshOutput // Gets the screen space coordinates of the bottom left of an isometric tile position. fn hex_col_tile_pos_to_world_pos(pos: vec2, grid_width: f32, grid_height: f32) -> vec2 { diff --git a/src/render/shaders/column_odd_hex.wgsl b/src/render/shaders/column_odd_hex.wgsl index f0b96ac5..84b57a42 100644 --- a/src/render/shaders/column_odd_hex.wgsl +++ b/src/render/shaders/column_odd_hex.wgsl @@ -1,7 +1,7 @@ #define_import_path bevy_ecs_tilemap::column_odd_hex -#import bevy_ecs_tilemap::mesh_output MeshOutput -#import bevy_ecs_tilemap::common VertexInput, tilemap_data, mesh +#import bevy_ecs_tilemap::mesh_output::MeshOutput +#import bevy_ecs_tilemap::common::{VertexInput, tilemap_data, mesh} // Gets the screen space coordinates of the bottom left of an isometric tile position. diff --git a/src/render/shaders/common.wgsl b/src/render/shaders/common.wgsl index 1cc25409..e9a17971 100644 --- a/src/render/shaders/common.wgsl +++ b/src/render/shaders/common.wgsl @@ -39,7 +39,7 @@ var sprite_texture: texture_2d_array; @group(2) @binding(1) var sprite_sampler: sampler; -#import bevy_ecs_tilemap::vertex_output MeshVertexOutput +#import bevy_ecs_tilemap::vertex_output::MeshVertexOutput fn process_fragment(in: MeshVertexOutput) -> vec4 { #ifdef ATLAS diff --git a/src/render/shaders/diamond_iso.wgsl b/src/render/shaders/diamond_iso.wgsl index 8d07dcd1..48b479c7 100644 --- a/src/render/shaders/diamond_iso.wgsl +++ b/src/render/shaders/diamond_iso.wgsl @@ -1,7 +1,7 @@ #define_import_path bevy_ecs_tilemap::diamond_iso -#import bevy_ecs_tilemap::common VertexInput, tilemap_data, mesh -#import bevy_ecs_tilemap::mesh_output MeshOutput +#import bevy_ecs_tilemap::common::{VertexInput, tilemap_data, mesh} +#import bevy_ecs_tilemap::mesh_output::MeshOutput const DIAMOND_BASIS_X: vec2 = vec2(0.5, -0.5); const DIAMOND_BASIS_Y: vec2 = vec2(0.5, 0.5); diff --git a/src/render/shaders/row_even_hex.wgsl b/src/render/shaders/row_even_hex.wgsl index ed8f920b..2d9ddc6e 100644 --- a/src/render/shaders/row_even_hex.wgsl +++ b/src/render/shaders/row_even_hex.wgsl @@ -1,7 +1,7 @@ #define_import_path bevy_ecs_tilemap::row_even_hex -#import bevy_ecs_tilemap::common VertexInput, tilemap_data, mesh -#import bevy_ecs_tilemap::mesh_output MeshOutput +#import bevy_ecs_tilemap::common::{VertexInput, tilemap_data, mesh} +#import bevy_ecs_tilemap::mesh_output::MeshOutput // Gets the screen space coordinates of the bottom left of an isometric tile position. fn hex_row_tile_pos_to_world_pos(pos: vec2, grid_width: f32, grid_height: f32) -> vec2 { diff --git a/src/render/shaders/row_hex.wgsl b/src/render/shaders/row_hex.wgsl index 5e8ad406..80e442ea 100644 --- a/src/render/shaders/row_hex.wgsl +++ b/src/render/shaders/row_hex.wgsl @@ -1,7 +1,7 @@ #define_import_path bevy_ecs_tilemap::row_hex -#import bevy_ecs_tilemap::common VertexInput, tilemap_data, mesh -#import bevy_ecs_tilemap::mesh_output MeshOutput +#import bevy_ecs_tilemap::common::{VertexInput, tilemap_data, mesh} +#import bevy_ecs_tilemap::mesh_output::MeshOutput // Gets the screen space coordinates of the bottom left of an isometric tile position. fn hex_row_tile_pos_to_world_pos(pos: vec2, grid_width: f32, grid_height: f32) -> vec2 { diff --git a/src/render/shaders/row_odd_hex.wgsl b/src/render/shaders/row_odd_hex.wgsl index 4ae284b6..ab6e62f0 100644 --- a/src/render/shaders/row_odd_hex.wgsl +++ b/src/render/shaders/row_odd_hex.wgsl @@ -1,7 +1,7 @@ #define_import_path bevy_ecs_tilemap::row_odd_hex -#import bevy_ecs_tilemap::common VertexInput, tilemap_data, mesh -#import bevy_ecs_tilemap::mesh_output MeshOutput +#import bevy_ecs_tilemap::common::{VertexInput, tilemap_data, mesh} +#import bevy_ecs_tilemap::mesh_output::MeshOutput // Gets the screen space coordinates of the bottom left of an isometric tile position. fn hex_row_tile_pos_to_world_pos(pos: vec2, grid_width: f32, grid_height: f32) -> vec2 { diff --git a/src/render/shaders/square.wgsl b/src/render/shaders/square.wgsl index c86f6b76..af228dbe 100644 --- a/src/render/shaders/square.wgsl +++ b/src/render/shaders/square.wgsl @@ -1,6 +1,6 @@ #define_import_path bevy_ecs_tilemap::square -#import bevy_ecs_tilemap::common VertexInput, tilemap_data, mesh -#import bevy_ecs_tilemap::mesh_output MeshOutput +#import bevy_ecs_tilemap::common::{VertexInput, tilemap_data, mesh} +#import bevy_ecs_tilemap::mesh_output::MeshOutput fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { var out: MeshOutput; diff --git a/src/render/shaders/staggered_iso.wgsl b/src/render/shaders/staggered_iso.wgsl index e8e08ab0..117f7c21 100644 --- a/src/render/shaders/staggered_iso.wgsl +++ b/src/render/shaders/staggered_iso.wgsl @@ -1,7 +1,7 @@ #define_import_path bevy_ecs_tilemap::staggered_iso -#import bevy_ecs_tilemap::common VertexInput, tilemap_data, mesh -#import bevy_ecs_tilemap::mesh_output MeshOutput +#import bevy_ecs_tilemap::common::{VertexInput, tilemap_data, mesh} +#import bevy_ecs_tilemap::mesh_output::MeshOutput const DIAMOND_BASIS_X: vec2 = vec2(0.5, -0.5); const DIAMOND_BASIS_Y: vec2 = vec2(0.5, 0.5); diff --git a/src/render/shaders/tilemap_fragment.wgsl b/src/render/shaders/tilemap_fragment.wgsl index 6f2da1a1..d907d43a 100644 --- a/src/render/shaders/tilemap_fragment.wgsl +++ b/src/render/shaders/tilemap_fragment.wgsl @@ -1,5 +1,5 @@ -#import bevy_ecs_tilemap::common process_fragment -#import bevy_ecs_tilemap::vertex_output MeshVertexOutput +#import bevy_ecs_tilemap::common::process_fragment +#import bevy_ecs_tilemap::vertex_output::MeshVertexOutput @fragment fn fragment(in: MeshVertexOutput) -> @location(0) vec4 { diff --git a/src/render/shaders/tilemap_vertex.wgsl b/src/render/shaders/tilemap_vertex.wgsl index e164d9fb..ce5411e1 100644 --- a/src/render/shaders/tilemap_vertex.wgsl +++ b/src/render/shaders/tilemap_vertex.wgsl @@ -1,42 +1,42 @@ -#import bevy_ecs_tilemap::common VertexInput, tilemap_data -#import bevy_ecs_tilemap::mesh_output MeshOutput -#import bevy_sprite::mesh2d_view_bindings view -#import bevy_ecs_tilemap::vertex_output MeshVertexOutput +#import bevy_ecs_tilemap::common::{VertexInput, tilemap_data} +#import bevy_ecs_tilemap::mesh_output::MeshOutput +#import bevy_sprite::mesh2d_view_bindings::view +#import bevy_ecs_tilemap::vertex_output::MeshVertexOutput #ifdef SQUARE - #import bevy_ecs_tilemap::square get_mesh + #import bevy_ecs_tilemap::square::get_mesh #endif #ifdef ISO_DIAMOND - #import bevy_ecs_tilemap::diamond_iso get_mesh + #import bevy_ecs_tilemap::diamond_iso::get_mesh #endif #ifdef ISO_STAGGERED - #import bevy_ecs_tilemap::staggered_iso get_mesh + #import bevy_ecs_tilemap::staggered_iso::get_mesh #endif #ifdef COLUMN_EVEN_HEX - #import bevy_ecs_tilemap::column_even_hex get_mesh + #import bevy_ecs_tilemap::column_even_hex::get_mesh #endif #ifdef COLUMN_HEX - #import bevy_ecs_tilemap::column_hex get_mesh + #import bevy_ecs_tilemap::column_hex::get_mesh #endif #ifdef COLUMN_ODD_HEX - #import bevy_ecs_tilemap::column_odd_hex get_mesh + #import bevy_ecs_tilemap::column_odd_hex::get_mesh #endif #ifdef ROW_EVEN_HEX - #import bevy_ecs_tilemap::row_even_hex get_mesh + #import bevy_ecs_tilemap::row_even_hex::get_mesh #endif #ifdef ROW_HEX - #import bevy_ecs_tilemap::row_hex get_mesh + #import bevy_ecs_tilemap::row_hex::get_mesh #endif #ifdef ROW_ODD_HEX - #import bevy_ecs_tilemap::row_odd_hex get_mesh + #import bevy_ecs_tilemap::row_odd_hex::get_mesh #endif diff --git a/src/render/texture_array_cache.rs b/src/render/texture_array_cache.rs index 3fb17883..9bd34855 100644 --- a/src/render/texture_array_cache.rs +++ b/src/render/texture_array_cache.rs @@ -75,7 +75,7 @@ impl TextureArrayCache { "Expected image to have finished loading if \ it is being extracted as a texture!", ); - let texture_size: TilemapTextureSize = image.size().into(); + let texture_size: TilemapTextureSize = image.size_f32().into(); let tile_count_x = ((texture_size.x) / (tile_size.x + tile_spacing.x)).floor(); let tile_count_y = ((texture_size.y) / (tile_size.y + tile_spacing.y)).floor(); ((tile_count_x * tile_count_y) as u32, texture_size) @@ -86,7 +86,7 @@ impl TextureArrayCache { "Expected image to have finished loading if \ it is being extracted as a texture!", ); - let this_tile_size: TilemapTileSize = image.size().try_into().unwrap(); + let this_tile_size: TilemapTileSize = image.size_f32().try_into().unwrap(); if this_tile_size != tile_size { panic!( "Expected all provided image assets to have size {tile_size:?}, \ @@ -101,7 +101,7 @@ impl TextureArrayCache { "Expected image to have finished loading if \ it is being extracted as a texture!", ); - let tile_size: TilemapTileSize = image.size().into(); + let tile_size: TilemapTileSize = image.size_f32().into(); ( image.texture_descriptor.array_layer_count(), tile_size.into(),