diff --git a/Cargo.toml b/Cargo.toml index a9f49dcc..9a83d93e 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.10.0" +version = "0.11.0" authors = ["John Mitchell"] homepage = "https://github.com/StarArawn/bevy_ecs_tilemap" repository = "https://github.com/StarArawn/bevy_ecs_tilemap" @@ -15,7 +15,7 @@ atlas = [] render = [] [dependencies] -bevy = { version = "0.10", default-features = false, features = [ +bevy = { version = "0.11", default-features = false, features = [ "bevy_core_pipeline", "bevy_render", "bevy_asset", @@ -28,12 +28,12 @@ regex = "1.5.4" anyhow = { version = "1.0" } ldtk_rust = { version = "0.6" } rand = "0.8" -env_logger = "0.9" +env_logger = "0.10" serde_json = { version = "1.0" } tiled = { version = "0.11.0", default-features = false } [dev-dependencies.bevy] -version = "0.10" +version = "0.11" default-features = false features = [ "bevy_core_pipeline", @@ -45,10 +45,11 @@ features = [ "bevy_text", "bevy_sprite", "filesystem_watcher", + "webgl2" ] [target.'cfg(unix)'.dev-dependencies.bevy] -version = "0.10" +version = "0.11" default-features = false features = [ "bevy_core_pipeline", diff --git a/examples/3d_iso.rs b/examples/3d_iso.rs index 0904c8da..5afa42a3 100644 --- a/examples/3d_iso.rs +++ b/examples/3d_iso.rs @@ -1,4 +1,6 @@ -use bevy::prelude::*; +use bevy::utils::Duration; + +use bevy::{asset::ChangeWatcher, prelude::*}; use bevy_ecs_tilemap::prelude::*; mod helpers; @@ -33,13 +35,12 @@ fn main() { }) .set(ImagePlugin::default_nearest()) .set(AssetPlugin { - watch_for_changes: true, + watch_for_changes: ChangeWatcher::with_delay(Duration::from_millis(200)), ..default() }), ) - .add_plugin(TilemapPlugin) - .add_plugin(helpers::tiled::TiledMapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) + .add_plugins((TilemapPlugin, helpers::tiled::TiledMapPlugin)) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) .run(); } diff --git a/examples/accessing_tiles.rs b/examples/accessing_tiles.rs index b101bd90..16929c40 100644 --- a/examples/accessing_tiles.rs +++ b/examples/accessing_tiles.rs @@ -160,9 +160,9 @@ fn main() { }) .set(ImagePlugin::default_nearest()), ) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) - .add_system(update_map) + .add_plugins(TilemapPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) + .add_systems(Update, update_map) .run(); } diff --git a/examples/animation.rs b/examples/animation.rs index 7a49297c..31e37378 100644 --- a/examples/animation.rs +++ b/examples/animation.rs @@ -139,12 +139,12 @@ fn main() { }) .set(ImagePlugin::default_nearest()), ) - .add_plugin(LogDiagnosticsPlugin::default()) - .add_plugin(FrameTimeDiagnosticsPlugin::default()) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_startup_system(create_background) - .add_startup_system(create_animated_flowers) - .add_system(helpers::camera::movement) + .add_plugins(LogDiagnosticsPlugin::default()) + .add_plugins(FrameTimeDiagnosticsPlugin::default()) + .add_plugins(TilemapPlugin) + .add_systems(Startup, startup) + .add_systems(Startup, create_background) + .add_systems(Startup, create_animated_flowers) + .add_systems(Update, helpers::camera::movement) .run(); } diff --git a/examples/basic.rs b/examples/basic.rs index 1c64841b..7c1c83bd 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -109,9 +109,9 @@ fn main() { }), ..default() }).set(ImagePlugin::default_nearest())) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) - .add_system(swap_texture_or_hide) + .add_plugins(TilemapPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) + .add_systems(Update, swap_texture_or_hide) .run(); } diff --git a/examples/bench.rs b/examples/bench.rs index 21b8b4f5..694410d8 100644 --- a/examples/bench.rs +++ b/examples/bench.rs @@ -56,10 +56,10 @@ fn main() { render_chunk_size: UVec2::new(256, 256), ..Default::default() }) - .add_plugin(LogDiagnosticsPlugin::default()) - .add_plugin(FrameTimeDiagnosticsPlugin::default()) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) + .add_plugins(LogDiagnosticsPlugin::default()) + .add_plugins(FrameTimeDiagnosticsPlugin::default()) + .add_plugins(TilemapPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) .run(); } diff --git a/examples/chunking.rs b/examples/chunking.rs index 48d151dc..f0abf8e6 100644 --- a/examples/chunking.rs +++ b/examples/chunking.rs @@ -122,11 +122,11 @@ fn main() { render_chunk_size: RENDER_CHUNK_SIZE, ..Default::default() }) - .add_plugin(TilemapPlugin) + .add_plugins(TilemapPlugin) .insert_resource(ChunkManager::default()) - .add_startup_system(startup) - .add_system(helpers::camera::movement) - .add_system(spawn_chunks_around_camera) - .add_system(despawn_outofrange_chunks) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) + .add_systems(Update, spawn_chunks_around_camera) + .add_systems(Update, despawn_outofrange_chunks) .run(); } diff --git a/examples/colors.rs b/examples/colors.rs index 7fd22b43..95548281 100644 --- a/examples/colors.rs +++ b/examples/colors.rs @@ -103,8 +103,8 @@ fn main() { }) .set(ImagePlugin::default_nearest()), ) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) + .add_plugins(TilemapPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) .run(); } diff --git a/examples/frustum_cull_test.rs b/examples/frustum_cull_test.rs index ec35f7e7..48d29f88 100644 --- a/examples/frustum_cull_test.rs +++ b/examples/frustum_cull_test.rs @@ -242,14 +242,17 @@ fn main() { filter: "bevy_ecs_tilemap=trace".into(), }), ) - .add_plugin(TilemapPlugin) + .add_plugins(TilemapPlugin) .init_resource::() .init_resource::() .init_resource::() .init_resource::() .init_resource::() - .add_startup_systems((spawn_tilemap, apply_system_buffers, spawn_map_type_label).chain()) - .add_system(camera_movement.in_base_set(CoreSet::First)) - .add_system(swap_map_type) + .add_systems( + Startup, + (spawn_tilemap, apply_deferred, spawn_map_type_label).chain(), + ) + .add_systems(First, camera_movement) + .add_systems(Update, swap_map_type) .run(); } diff --git a/examples/game_of_life.rs b/examples/game_of_life.rs index 27ecc626..70ff515a 100644 --- a/examples/game_of_life.rs +++ b/examples/game_of_life.rs @@ -106,9 +106,9 @@ fn main() { }) .set(ImagePlugin::default_nearest()), ) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) - .add_system(update) + .add_plugins(TilemapPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) + .add_systems(Update, update) .run(); } diff --git a/examples/helpers/ldtk.rs b/examples/helpers/ldtk.rs index 36a53e66..e00ffc70 100644 --- a/examples/helpers/ldtk.rs +++ b/examples/helpers/ldtk.rs @@ -6,7 +6,7 @@ use bevy_ecs_tilemap::{ }; use std::collections::HashMap; -use bevy::reflect::TypeUuid; +use bevy::reflect::{TypePath, TypeUuid}; use bevy::{ asset::{AssetLoader, AssetPath, BoxedFuture, LoadContext, LoadedAsset}, prelude::*, @@ -20,11 +20,11 @@ impl Plugin for LdtkPlugin { fn build(&self, app: &mut App) { app.add_asset::() .add_asset_loader(LdtkLoader) - .add_system(process_loaded_tile_maps); + .add_systems(Update, process_loaded_tile_maps); } } -#[derive(TypeUuid)] +#[derive(TypeUuid, TypePath)] #[uuid = "abf9eaf2-f21c-4b46-89b0-8aa5c42199af"] pub struct LdtkMap { pub project: ldtk_rust::Project, diff --git a/examples/helpers/tiled.rs b/examples/helpers/tiled.rs index 5c5c65a8..a70f5490 100644 --- a/examples/helpers/tiled.rs +++ b/examples/helpers/tiled.rs @@ -21,9 +21,9 @@ use bevy::{ log, prelude::{ AddAsset, Added, AssetEvent, Assets, Bundle, Commands, Component, DespawnRecursiveExt, - Entity, EventReader, GlobalTransform, Handle, Image, Plugin, Query, Res, Transform, + Entity, EventReader, GlobalTransform, Handle, Image, Plugin, Query, Res, Transform, Update, }, - reflect::TypeUuid, + reflect::{TypePath, TypeUuid}, utils::HashMap, }; use bevy_ecs_tilemap::prelude::*; @@ -37,11 +37,11 @@ impl Plugin for TiledMapPlugin { fn build(&self, app: &mut bevy::prelude::App) { app.add_asset::() .add_asset_loader(TiledLoader) - .add_system(process_loaded_maps); + .add_systems(Update, process_loaded_maps); } } -#[derive(TypeUuid)] +#[derive(TypeUuid, TypePath)] #[uuid = "e51081d0-6168-4881-a1c6-4249b2000d7f"] pub struct TiledMap { pub map: tiled::Map, diff --git a/examples/hex_neighbors.rs b/examples/hex_neighbors.rs index 6a438441..d83be022 100644 --- a/examples/hex_neighbors.rs +++ b/examples/hex_neighbors.rs @@ -441,16 +441,16 @@ fn main() { }) .set(ImagePlugin::default_nearest()), ) - .add_plugin(TilemapPlugin) + .add_plugins(TilemapPlugin) .init_resource::() .init_resource::() .init_resource::() .init_resource::() - .add_startup_systems((spawn_tilemap, apply_system_buffers).chain().in_set(SpawnTilemapSet)) - .add_startup_systems((spawn_tile_labels, spawn_map_type_label).after(SpawnTilemapSet)) - .add_systems((camera_movement, update_cursor_pos).chain().in_base_set(CoreSet::First)) - .add_system(swap_map_type) - .add_system(hover_highlight_tile_label.after(swap_map_type)) - .add_system(highlight_neighbor_label.after(hover_highlight_tile_label)) + .add_systems(Startup, (spawn_tilemap, apply_deferred).chain().in_set(SpawnTilemapSet)) + .add_systems(Startup, (spawn_tile_labels, spawn_map_type_label).after(SpawnTilemapSet)) + .add_systems(First, (camera_movement, update_cursor_pos).chain()) + .add_systems(Update, swap_map_type) + .add_systems(Update, hover_highlight_tile_label.after(swap_map_type)) + .add_systems(Update, highlight_neighbor_label.after(hover_highlight_tile_label)) .run(); } diff --git a/examples/hex_neighbors_radius_chunks.rs b/examples/hex_neighbors_radius_chunks.rs index 142706df..5717f9f8 100644 --- a/examples/hex_neighbors_radius_chunks.rs +++ b/examples/hex_neighbors_radius_chunks.rs @@ -541,18 +541,18 @@ fn main() { }) .set(ImagePlugin::default_nearest()), ) - .add_plugin(TilemapPlugin) + .add_plugins(TilemapPlugin) .init_resource::() .init_resource::() .init_resource::() .init_resource::() .init_resource::() - .add_startup_systems((spawn_chunks, apply_system_buffers).chain().in_set(SpawnChunksSet)) - .add_startup_system(spawn_tile_labels.after(SpawnChunksSet)) - .add_systems((camera_movement, update_cursor_pos).chain().in_base_set(CoreSet::First)) - .add_system(swap_map_type) - .add_system(hover_highlight_tile_label.after(swap_map_type)) - .add_system(update_radius.after(hover_highlight_tile_label)) - .add_system(highlight_neighbor_labels.after(update_radius)) + .add_systems(Startup, (spawn_chunks, apply_deferred).chain().in_set(SpawnChunksSet)) + .add_systems(Startup, spawn_tile_labels.after(SpawnChunksSet)) + .add_systems(First, (camera_movement, update_cursor_pos).chain()) + .add_systems(Update, swap_map_type) + .add_systems(Update, hover_highlight_tile_label.after(swap_map_type)) + .add_systems(Update, update_radius.after(hover_highlight_tile_label)) + .add_systems(Update, highlight_neighbor_labels.after(update_radius)) .run(); } diff --git a/examples/hexagon_column.rs b/examples/hexagon_column.rs index e529595d..d0dbed03 100644 --- a/examples/hexagon_column.rs +++ b/examples/hexagon_column.rs @@ -128,9 +128,9 @@ fn main() { }) .set(ImagePlugin::default_nearest()), ) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) - .add_system(swap_mesh_type) + .add_plugins(TilemapPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) + .add_systems(Update, swap_mesh_type) .run(); } diff --git a/examples/hexagon_generation.rs b/examples/hexagon_generation.rs index 17cd7caa..4800cf98 100644 --- a/examples/hexagon_generation.rs +++ b/examples/hexagon_generation.rs @@ -226,12 +226,15 @@ fn main() { }) .set(ImagePlugin::default_nearest()), ) - .add_plugin(TilemapPlugin) + .add_plugins(TilemapPlugin) .init_resource::() .init_resource::() .init_resource::() - .add_startup_systems((spawn_tilemap, apply_system_buffers, spawn_map_type_label).chain()) - .add_system(camera_movement) - .add_system(swap_map_type) + .add_systems( + Startup, + (spawn_tilemap, apply_deferred, spawn_map_type_label).chain(), + ) + .add_systems(Update, camera_movement) + .add_systems(Update, swap_map_type) .run(); } diff --git a/examples/hexagon_row.rs b/examples/hexagon_row.rs index 04b1b7eb..067ad384 100644 --- a/examples/hexagon_row.rs +++ b/examples/hexagon_row.rs @@ -127,9 +127,9 @@ fn main() { }) .set(ImagePlugin::default_nearest()), ) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) - .add_system(swap_mesh_type) + .add_plugins(TilemapPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) + .add_systems(Update, swap_mesh_type) .run(); } diff --git a/examples/iso_diamond.rs b/examples/iso_diamond.rs index 7a51b7db..89ebc966 100644 --- a/examples/iso_diamond.rs +++ b/examples/iso_diamond.rs @@ -99,8 +99,8 @@ fn main() { }) .set(ImagePlugin::default_nearest()), ) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) + .add_plugins(TilemapPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) .run(); } diff --git a/examples/iso_staggered.rs b/examples/iso_staggered.rs index 6c71af9b..3070d852 100644 --- a/examples/iso_staggered.rs +++ b/examples/iso_staggered.rs @@ -101,8 +101,8 @@ fn main() { }) .set(ImagePlugin::default_nearest()), ) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) + .add_plugins(TilemapPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) .run(); } diff --git a/examples/layers.rs b/examples/layers.rs index c282aecc..85e488b7 100644 --- a/examples/layers.rs +++ b/examples/layers.rs @@ -74,8 +74,8 @@ fn main() { }) .set(ImagePlugin::default_nearest()), ) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) + .add_plugins(TilemapPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) .run(); } diff --git a/examples/ldtk.rs b/examples/ldtk.rs index 474c4e55..43a63dd9 100644 --- a/examples/ldtk.rs +++ b/examples/ldtk.rs @@ -8,7 +8,9 @@ //! //! 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::prelude::*; +use bevy::utils::Duration; + +use bevy::{asset::ChangeWatcher, prelude::*}; use bevy_ecs_tilemap::*; mod helpers; @@ -38,13 +40,13 @@ fn main() { }) .set(ImagePlugin::default_nearest()) .set(AssetPlugin { - watch_for_changes: true, + watch_for_changes: ChangeWatcher::with_delay(Duration::from_millis(200)), ..default() }), ) - .add_plugin(TilemapPlugin) - .add_plugin(helpers::ldtk::LdtkPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) + .add_plugins(TilemapPlugin) + .add_plugins(helpers::ldtk::LdtkPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) .run(); } diff --git a/examples/mouse_to_tile.rs b/examples/mouse_to_tile.rs index 547b56e0..c8bd1016 100644 --- a/examples/mouse_to_tile.rs +++ b/examples/mouse_to_tile.rs @@ -392,19 +392,19 @@ fn main() { .init_resource::() .init_resource::() .init_resource::() - .add_plugin(TilemapPlugin) - .add_startup_systems( - (spawn_tilemap, apply_system_buffers) + .add_plugins(TilemapPlugin) + .add_systems( + Startup, + (spawn_tilemap, apply_deferred) .chain() .in_set(SpawnTilemapSet), ) - .add_startup_systems((spawn_tile_labels, spawn_map_type_label).after(SpawnTilemapSet)) .add_systems( - (camera_movement, update_cursor_pos) - .chain() - .in_base_set(CoreSet::First), + Startup, + (spawn_tile_labels, spawn_map_type_label).after(SpawnTilemapSet), ) - .add_system(swap_map_type) - .add_system(highlight_tile_labels.after(swap_map_type)) + .add_systems(First, (camera_movement, update_cursor_pos).chain()) + .add_systems(Update, swap_map_type) + .add_systems(Update, highlight_tile_labels.after(swap_map_type)) .run(); } diff --git a/examples/move_tile.rs b/examples/move_tile.rs index f4acd9b1..68f5bfff 100644 --- a/examples/move_tile.rs +++ b/examples/move_tile.rs @@ -67,9 +67,9 @@ fn main() { }) .set(ImagePlugin::default_nearest()), ) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) - .add_system(swap_pos) + .add_plugins(TilemapPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) + .add_systems(Update, swap_pos) .run(); } diff --git a/examples/random_map.rs b/examples/random_map.rs index 2074073f..f226067c 100644 --- a/examples/random_map.rs +++ b/examples/random_map.rs @@ -80,11 +80,11 @@ fn main() { }) .set(ImagePlugin::default_nearest()), ) - .add_plugin(LogDiagnosticsPlugin::default()) - .add_plugin(FrameTimeDiagnosticsPlugin::default()) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) - .add_system(random) + .add_plugins(LogDiagnosticsPlugin::default()) + .add_plugins(FrameTimeDiagnosticsPlugin::default()) + .add_plugins(TilemapPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) + .add_systems(Update, random) .run(); } diff --git a/examples/remove_tiles.rs b/examples/remove_tiles.rs index b0f0d812..51a1d4f9 100644 --- a/examples/remove_tiles.rs +++ b/examples/remove_tiles.rs @@ -90,9 +90,9 @@ fn main() { }) .set(ImagePlugin::default_nearest()), ) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) - .add_system(remove_tiles) + .add_plugins(TilemapPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) + .add_systems(Update, remove_tiles) .run(); } diff --git a/examples/spacing.rs b/examples/spacing.rs index 65b4036a..05929a5d 100644 --- a/examples/spacing.rs +++ b/examples/spacing.rs @@ -75,8 +75,8 @@ fn main() { }) .set(ImagePlugin::default_nearest()), ) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) + .add_plugins(TilemapPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) .run(); } diff --git a/examples/texture_container.rs b/examples/texture_container.rs index 99ee0e0f..f716c132 100644 --- a/examples/texture_container.rs +++ b/examples/texture_container.rs @@ -101,9 +101,9 @@ mod no_atlas { }) .set(ImagePlugin::default_nearest()), ) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) + .add_plugins(TilemapPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) .run(); } } diff --git a/examples/texture_vec.rs b/examples/texture_vec.rs index bae4ff69..84202f97 100644 --- a/examples/texture_vec.rs +++ b/examples/texture_vec.rs @@ -95,9 +95,9 @@ mod no_atlas { }) .set(ImagePlugin::default_nearest()), ) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) + .add_plugins(TilemapPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) .run(); } } diff --git a/examples/tiled.rs b/examples/tiled.rs index da8c982e..3426585a 100644 --- a/examples/tiled.rs +++ b/examples/tiled.rs @@ -1,4 +1,6 @@ -use bevy::prelude::*; +use bevy::utils::Duration; + +use bevy::{asset::ChangeWatcher, prelude::*}; use bevy_ecs_tilemap::prelude::*; mod helpers; @@ -27,13 +29,13 @@ fn main() { }) .set(ImagePlugin::default_nearest()) .set(AssetPlugin { - watch_for_changes: true, + watch_for_changes: ChangeWatcher::with_delay(Duration::from_millis(200)), ..default() }), ) - .add_plugin(TilemapPlugin) - .add_plugin(helpers::tiled::TiledMapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) + .add_plugins(TilemapPlugin) + .add_plugins(helpers::tiled::TiledMapPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) .run(); } diff --git a/examples/tiled_rotated.rs b/examples/tiled_rotated.rs index 42d5bdc5..d0c7f9b2 100644 --- a/examples/tiled_rotated.rs +++ b/examples/tiled_rotated.rs @@ -1,4 +1,6 @@ -use bevy::prelude::*; +use bevy::utils::Duration; + +use bevy::{asset::ChangeWatcher, prelude::*}; use bevy_ecs_tilemap::prelude::*; mod helpers; @@ -27,13 +29,13 @@ fn main() { }) .set(ImagePlugin::default_nearest()) .set(AssetPlugin { - watch_for_changes: true, + watch_for_changes: ChangeWatcher::with_delay(Duration::from_millis(200)), ..default() }), ) - .add_plugin(TilemapPlugin) - .add_plugin(helpers::tiled::TiledMapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) + .add_plugins(TilemapPlugin) + .add_plugins(helpers::tiled::TiledMapPlugin) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) .run(); } diff --git a/examples/visibility.rs b/examples/visibility.rs index 422367c2..967ccab4 100644 --- a/examples/visibility.rs +++ b/examples/visibility.rs @@ -79,7 +79,7 @@ fn remove_tiles( fn main() { App::new() - .add_plugins( + .add_plugins(( DefaultPlugins .set(WindowPlugin { primary_window: Some(Window { @@ -89,10 +89,10 @@ fn main() { ..default() }) .set(ImagePlugin::default_nearest()), - ) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) - .add_system(remove_tiles) + TilemapPlugin, + )) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) + .add_systems(Update, remove_tiles) .run(); } diff --git a/src/lib.rs b/src/lib.rs index 12ca0787..89d061d9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,12 +14,9 @@ //! - Built in animation support – see [`animation` example](https://github.com/StarArawn/bevy_ecs_tilemap/blob/main/examples/animation.rs). //! - Texture array support. -use bevy::{ - prelude::{ - Bundle, Changed, Component, ComputedVisibility, CoreSet, Deref, GlobalTransform, - IntoSystemConfig, Plugin, Query, Reflect, ReflectComponent, Transform, Visibility, - }, - reflect::FromReflect, +use bevy::prelude::{ + Bundle, Changed, Component, ComputedVisibility, Deref, First, GlobalTransform, Plugin, Query, + Reflect, ReflectComponent, Transform, Visibility, }; use map::{ TilemapGridSize, TilemapSize, TilemapSpacing, TilemapTexture, TilemapTextureSize, @@ -32,10 +29,7 @@ use tiles::{ }; #[cfg(all(not(feature = "atlas"), feature = "render"))] -use bevy::{ - prelude::IntoSystemAppConfig, - render::{ExtractSchedule, RenderApp}, -}; +use bevy::render::{ExtractSchedule, RenderApp}; /// A module that allows pre-loading of atlases into array textures. #[cfg(all(not(feature = "atlas"), feature = "render"))] @@ -56,15 +50,15 @@ pub struct TilemapPlugin; impl Plugin for TilemapPlugin { fn build(&self, app: &mut bevy::prelude::App) { #[cfg(feature = "render")] - app.add_plugin(render::TilemapRenderingPlugin); + app.add_plugins(render::TilemapRenderingPlugin); - app.add_system(update_changed_tile_positions.in_base_set(CoreSet::First)); + app.add_systems(First, update_changed_tile_positions); #[cfg(all(not(feature = "atlas"), feature = "render"))] { app.insert_resource(array_texture_preload::ArrayTextureLoader::default()); let render_app = app.sub_app_mut(RenderApp); - render_app.add_system(array_texture_preload::extract.in_schedule(ExtractSchedule)); + render_app.add_systems(ExtractSchedule, array_texture_preload::extract); } app.register_type::() @@ -87,7 +81,7 @@ impl Plugin for TilemapPlugin { } } -#[derive(Component, Reflect, Debug, Clone, Copy, Deref, FromReflect)] +#[derive(Component, Reflect, Debug, Clone, Copy, Deref)] #[reflect(Component)] pub struct FrustumCulling(pub bool); diff --git a/src/map/mod.rs b/src/map/mod.rs index dfdc730e..d86e597c 100644 --- a/src/map/mod.rs +++ b/src/map/mod.rs @@ -3,7 +3,7 @@ use bevy::prelude::{ReflectComponent, Res, ResMut, Resource}; use bevy::render::render_resource::TextureUsages; use bevy::{ math::{UVec2, Vec2}, - prelude::{Component, Entity, FromReflect, Handle, Image, Reflect}, + prelude::{Component, Entity, Handle, Image, Reflect}, }; /// Custom parameters for the render pipeline. @@ -40,7 +40,7 @@ pub struct TilemapRenderSettings { } /// A component which stores a reference to the tilemap entity. -#[derive(Component, Reflect, Clone, Copy, Debug, Hash, FromReflect)] +#[derive(Component, Reflect, Clone, Copy, Debug, Hash)] #[reflect(Component)] pub struct TilemapId(pub Entity); @@ -51,7 +51,7 @@ impl Default for TilemapId { } /// Size of the tilemap in tiles. -#[derive(Component, Reflect, Default, Clone, Copy, Debug, Hash, FromReflect)] +#[derive(Component, Reflect, Default, Clone, Copy, Debug, Hash)] #[reflect(Component)] pub struct TilemapSize { pub x: u32, @@ -88,7 +88,7 @@ impl From for TilemapSize { } } -#[derive(Component, Reflect, Clone, Debug, Hash, PartialEq, Eq, FromReflect)] +#[derive(Component, Reflect, Clone, Debug, Hash, PartialEq, Eq)] #[reflect(Component)] pub enum TilemapTexture { /// All textures for tiles are inside a single image asset. @@ -194,7 +194,7 @@ impl TilemapTexture { } /// Size of the tiles in pixels -#[derive(Component, Reflect, Default, Clone, Copy, Debug, PartialOrd, PartialEq, FromReflect)] +#[derive(Component, Reflect, Default, Clone, Copy, Debug, PartialOrd, PartialEq)] #[reflect(Component)] pub struct TilemapTileSize { pub x: f32, @@ -233,7 +233,7 @@ impl From for TilemapTileSize { /// This can be used to overlay tiles on top of each other. /// Ex. A 16x16 pixel tile can be overlapped by 8 pixels by using /// a grid size of 16x8. -#[derive(Component, Reflect, Default, Clone, Copy, Debug, PartialOrd, PartialEq, FromReflect)] +#[derive(Component, Reflect, Default, Clone, Copy, Debug, PartialOrd, PartialEq)] #[reflect(Component)] pub struct TilemapGridSize { pub x: f32, @@ -266,7 +266,7 @@ impl From<&Vec2> for TilemapGridSize { /// Spacing between tiles in pixels inside of the texture atlas. /// Defaults to 0.0 -#[derive(Component, Reflect, Default, Clone, Copy, Debug, FromReflect)] +#[derive(Component, Reflect, Default, Clone, Copy, Debug)] #[reflect(Component)] pub struct TilemapSpacing { pub x: f32, @@ -286,7 +286,7 @@ impl TilemapSpacing { } /// Size of the atlas texture in pixels. -#[derive(Component, Reflect, Default, Clone, Copy, Debug, FromReflect)] +#[derive(Component, Reflect, Default, Clone, Copy, Debug)] #[reflect(Component)] pub struct TilemapTextureSize { pub x: f32, @@ -316,7 +316,7 @@ impl From for TilemapTextureSize { } /// Different hex grid coordinate systems. You can find out more at this link: -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect, FromReflect)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect)] pub enum HexCoordSystem { RowEven, RowOdd, @@ -327,14 +327,14 @@ pub enum HexCoordSystem { } /// Different isometric coordinate systems. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect, FromReflect)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect)] pub enum IsoCoordSystem { Diamond, Staggered, } /// The type of tile to be rendered, currently we support: Square, Hex, and Isometric. -#[derive(Component, Reflect, Debug, Clone, Copy, PartialEq, Eq, Hash, FromReflect)] +#[derive(Component, Reflect, Debug, Clone, Copy, PartialEq, Eq, Hash)] #[reflect(Component)] pub enum TilemapType { /// A tilemap with rectangular tiles. diff --git a/src/render/chunk.rs b/src/render/chunk.rs index 7f465f88..41537c74 100644 --- a/src/render/chunk.rs +++ b/src/render/chunk.rs @@ -414,25 +414,27 @@ impl RenderChunk2d { contents: &vertex_buffer_data, }); - let buffer_info = self.mesh.get_index_buffer_bytes().map_or( - GpuBufferInfo::NonIndexed { - vertex_count: self.mesh.count_vertices() as u32, - }, - |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 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 mesh_vertex_buffer_layout = self.mesh.get_mesh_vertex_buffer_layout(); self.gpu_mesh = Some(GpuMesh { vertex_buffer, + vertex_count: self.mesh.count_vertices() as u32, buffer_info, + morph_targets: None, layout: mesh_vertex_buffer_layout, primitive_topology: bevy::render::render_resource::PrimitiveTopology::TriangleList, }); diff --git a/src/render/draw.rs b/src/render/draw.rs index 7bc7d43e..506fcbf0 100644 --- a/src/render/draw.rs +++ b/src/render/draw.rs @@ -174,8 +174,8 @@ impl RenderCommand for DrawMesh { pass.set_index_buffer(buffer.slice(..), 0, *index_format); pass.draw_indexed(0..*count, 0, 0..1); } - GpuBufferInfo::NonIndexed { vertex_count } => { - pass.draw(0..*vertex_count, 0..1); + GpuBufferInfo::NonIndexed {} => { + pass.draw(0..gpu_mesh.vertex_count, 0..1); } } } diff --git a/src/render/mod.rs b/src/render/mod.rs index 024a1c8a..f037a0ee 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -11,7 +11,7 @@ use bevy::{ render_resource::{ FilterMode, SamplerDescriptor, SpecializedRenderPipelines, VertexFormat, }, - RenderApp, RenderSet, + Render, RenderApp, RenderSet, }, }; @@ -123,10 +123,10 @@ pub const TILEMAP_VERTEX_OUTPUT: HandleUntyped = impl Plugin for TilemapRenderingPlugin { fn build(&self, app: &mut App) { #[cfg(not(feature = "atlas"))] - app.add_system(set_texture_to_copy_src); + app.add_systems(Update, set_texture_to_copy_src); - app.add_system(clear_removed.in_base_set(CoreSet::First)); - app.add_systems((removal_helper_tilemap, removal_helper).in_base_set(CoreSet::PostUpdate)); + app.add_systems(First, clear_removed); + app.add_systems(PostUpdate, (removal_helper_tilemap, removal_helper)); // Extract the chunk size from the TilemapRenderSettings used to initialize the // ChunkCoordinate resource to insert into the render pipeline @@ -235,13 +235,18 @@ impl Plugin for TilemapRenderingPlugin { .insert_resource(RenderYSort(y_sort)) .insert_resource(RenderChunk2dStorage::default()) .insert_resource(SecondsSinceStartup(0.0)) - .add_systems((extract::extract, extract::extract_removal).in_schedule(ExtractSchedule)) .add_systems( + ExtractSchedule, + (extract::extract, extract::extract_removal), + ) + .add_systems( + Render, (prepare::prepare_removal, prepare::prepare) .chain() .in_set(RenderSet::Prepare), ) .add_systems( + Render, ( queue::queue_meshes, queue::queue_transform_bind_group, @@ -249,7 +254,6 @@ impl Plugin for TilemapRenderingPlugin { ) .in_set(RenderSet::Queue), ) - .init_resource::() .init_resource::() .init_resource::>() .init_resource::() @@ -260,7 +264,16 @@ impl Plugin for TilemapRenderingPlugin { #[cfg(not(feature = "atlas"))] render_app .init_resource::() - .add_system(prepare_textures.in_set(RenderSet::Prepare)); + .add_systems(Render, prepare_textures.in_set(RenderSet::Prepare)); + } + + fn finish(&self, app: &mut App) { + let render_app = match app.get_sub_app_mut(RenderApp) { + Ok(render_app) => render_app, + Err(_) => return, + }; + + render_app.init_resource::(); } } diff --git a/src/render/shaders/column_even_hex.wgsl b/src/render/shaders/column_even_hex.wgsl index 78a6aafb..1c2bbd29 100644 --- a/src/render/shaders/column_even_hex.wgsl +++ b/src/render/shaders/column_even_hex.wgsl @@ -1,14 +1,15 @@ #define_import_path bevy_ecs_tilemap::column_even_hex -#import bevy_ecs_tilemap::mesh_output - -const SQRT_3: f32 = 1.7320508; -const HALF_SQRT_3: f32 = 0.8660254; -const COL_BASIS_X: vec2 = vec2(HALF_SQRT_3, 0.5); -const COL_BASIS_Y: vec2 = vec2(0.0, 1.0); +#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 { + let SQRT_3: f32 = 1.7320508; + let HALF_SQRT_3: f32 = 0.8660254; + let COL_BASIS_X: vec2 = vec2(HALF_SQRT_3, 0.5); + let COL_BASIS_Y: vec2 = vec2(0.0, 1.0); + let unscaled_pos = pos.x * COL_BASIS_X + pos.y * COL_BASIS_Y; return vec2(COL_BASIS_X.x * grid_width * unscaled_pos.x, grid_height * unscaled_pos.y); } diff --git a/src/render/shaders/column_hex.wgsl b/src/render/shaders/column_hex.wgsl index 975bda54..2bf6ddc2 100644 --- a/src/render/shaders/column_hex.wgsl +++ b/src/render/shaders/column_hex.wgsl @@ -1,14 +1,15 @@ #define_import_path bevy_ecs_tilemap::column_hex -#import bevy_ecs_tilemap::mesh_output - -const SQRT_3: f32 = 1.7320508; -const HALF_SQRT_3: f32 = 0.8660254; -const COL_BASIS_X: vec2 = vec2(HALF_SQRT_3, 0.5); -const COL_BASIS_Y: vec2 = vec2(0.0, 1.0); +#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 { + let SQRT_3: f32 = 1.7320508; + let HALF_SQRT_3: f32 = 0.8660254; + let COL_BASIS_X: vec2 = vec2(HALF_SQRT_3, 0.5); + let COL_BASIS_Y: vec2 = vec2(0.0, 1.0); + let unscaled_pos = pos.x * COL_BASIS_X + pos.y * COL_BASIS_Y; return vec2(COL_BASIS_X.x * grid_width * unscaled_pos.x, grid_height * unscaled_pos.y); } diff --git a/src/render/shaders/column_odd_hex.wgsl b/src/render/shaders/column_odd_hex.wgsl index 55fb374e..f0b96ac5 100644 --- a/src/render/shaders/column_odd_hex.wgsl +++ b/src/render/shaders/column_odd_hex.wgsl @@ -1,14 +1,16 @@ #define_import_path bevy_ecs_tilemap::column_odd_hex -#import bevy_ecs_tilemap::mesh_output +#import bevy_ecs_tilemap::mesh_output MeshOutput +#import bevy_ecs_tilemap::common VertexInput, tilemap_data, mesh -const SQRT_3: f32 = 1.7320508; -const HALF_SQRT_3: f32 = 0.8660254; -const COL_BASIS_X: vec2 = vec2(HALF_SQRT_3, 0.5); -const COL_BASIS_Y: vec2 = vec2(0.0, 1.0); // 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 { + let SQRT_3: f32 = 1.7320508; + let HALF_SQRT_3: f32 = 0.8660254; + let COL_BASIS_X: vec2 = vec2(HALF_SQRT_3, 0.5); + let COL_BASIS_Y: vec2 = vec2(0.0, 1.0); + let unscaled_pos = pos.x * COL_BASIS_X + pos.y * COL_BASIS_Y; return vec2(COL_BASIS_X.x * grid_width * unscaled_pos.x, grid_height * unscaled_pos.y); } diff --git a/src/render/shaders/diamond_iso.wgsl b/src/render/shaders/diamond_iso.wgsl index 49925a3f..0bfaf9f8 100644 --- a/src/render/shaders/diamond_iso.wgsl +++ b/src/render/shaders/diamond_iso.wgsl @@ -1,6 +1,7 @@ #define_import_path bevy_ecs_tilemap::diamond_iso -#import bevy_ecs_tilemap::mesh_output +#import bevy_ecs_tilemap::mesh_output MeshOutput +#import bevy_ecs_tilemap::common tilemap_data, mesh 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 38c1faec..ed8f920b 100644 --- a/src/render/shaders/row_even_hex.wgsl +++ b/src/render/shaders/row_even_hex.wgsl @@ -1,14 +1,15 @@ #define_import_path bevy_ecs_tilemap::row_even_hex -#import bevy_ecs_tilemap::mesh_output - -const SQRT_3: f32 = 1.7320508; -const HALF_SQRT_3: f32 = 0.8660254; -const ROW_BASIS_X: vec2 = vec2(1.0, 0.0); -const ROW_BASIS_Y: vec2 = vec2(0.5, HALF_SQRT_3); +#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 { + let SQRT_3: f32 = 1.7320508; + let HALF_SQRT_3: f32 = 0.8660254; + let ROW_BASIS_X: vec2 = vec2(1.0, 0.0); + let ROW_BASIS_Y: vec2 = vec2(0.5, HALF_SQRT_3); + let unscaled_pos = pos.x * ROW_BASIS_X + pos.y * ROW_BASIS_Y; return vec2(grid_width * unscaled_pos.x, ROW_BASIS_Y.y * grid_height * unscaled_pos.y); } diff --git a/src/render/shaders/row_hex.wgsl b/src/render/shaders/row_hex.wgsl index 2b1f924e..5e8ad406 100644 --- a/src/render/shaders/row_hex.wgsl +++ b/src/render/shaders/row_hex.wgsl @@ -1,14 +1,15 @@ #define_import_path bevy_ecs_tilemap::row_hex -#import bevy_ecs_tilemap::mesh_output - -const SQRT_3: f32 = 1.7320508; -const HALF_SQRT_3: f32 = 0.8660254; -const ROW_BASIS_X: vec2 = vec2(1.0, 0.0); -const ROW_BASIS_Y: vec2 = vec2(0.5, HALF_SQRT_3); +#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 { + let SQRT_3: f32 = 1.7320508; + let HALF_SQRT_3: f32 = 0.8660254; + let ROW_BASIS_X: vec2 = vec2(1.0, 0.0); + let ROW_BASIS_Y: vec2 = vec2(0.5, HALF_SQRT_3); + let unscaled_pos = pos.x * ROW_BASIS_X + pos.y * ROW_BASIS_Y; return vec2(grid_width * unscaled_pos.x, ROW_BASIS_Y.y * grid_height * unscaled_pos.y); } diff --git a/src/render/shaders/row_odd_hex.wgsl b/src/render/shaders/row_odd_hex.wgsl index 5645fbd1..4ae284b6 100644 --- a/src/render/shaders/row_odd_hex.wgsl +++ b/src/render/shaders/row_odd_hex.wgsl @@ -1,14 +1,15 @@ #define_import_path bevy_ecs_tilemap::row_odd_hex -#import bevy_ecs_tilemap::mesh_output - -const SQRT_3: f32 = 1.7320508; -const HALF_SQRT_3: f32 = 0.8660254; -const ROW_BASIS_X: vec2 = vec2(1.0, 0.0); -const ROW_BASIS_Y: vec2 = vec2(0.5, HALF_SQRT_3); +#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 { + let SQRT_3: f32 = 1.7320508; + let HALF_SQRT_3: f32 = 0.8660254; + let ROW_BASIS_X: vec2 = vec2(1.0, 0.0); + let ROW_BASIS_Y: vec2 = vec2(0.5, HALF_SQRT_3); + let unscaled_pos = pos.x * ROW_BASIS_X + pos.y * ROW_BASIS_Y; return vec2(grid_width * unscaled_pos.x, ROW_BASIS_Y.y * grid_height * unscaled_pos.y); } diff --git a/src/render/shaders/square.wgsl b/src/render/shaders/square.wgsl index a581c219..c86f6b76 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::mesh_output +#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 d5c9d779..e8e08ab0 100644 --- a/src/render/shaders/staggered_iso.wgsl +++ b/src/render/shaders/staggered_iso.wgsl @@ -1,6 +1,7 @@ #define_import_path bevy_ecs_tilemap::staggered_iso -#import bevy_ecs_tilemap::mesh_output +#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 f68beae9..1718a0c8 100644 --- a/src/render/shaders/tilemap_fragment.wgsl +++ b/src/render/shaders/tilemap_fragment.wgsl @@ -1,12 +1,8 @@ -#import bevy_ecs_tilemap::common - -struct VertexOutput { - @builtin(position) position: vec4, - #import bevy_ecs_tilemap::vertex_output -} +#import bevy_ecs_tilemap::common sprite_texture, sprite_sampler, tilemap_data +#import bevy_ecs_tilemap::vertex_output MeshVertexOutput @fragment -fn fragment(in: VertexOutput) -> @location(0) vec4 { +fn fragment(in: MeshVertexOutput) -> @location(0) vec4 { #ifdef ATLAS let half_texture_pixel_size_u = 0.5 / tilemap_data.texture_size.x; let half_texture_pixel_size_v = 0.5 / tilemap_data.texture_size.y; diff --git a/src/render/shaders/tilemap_vertex.wgsl b/src/render/shaders/tilemap_vertex.wgsl index ae75e0c3..e164d9fb 100644 --- a/src/render/shaders/tilemap_vertex.wgsl +++ b/src/render/shaders/tilemap_vertex.wgsl @@ -1,50 +1,48 @@ -#import bevy_ecs_tilemap::common - -struct VertexOutput { - @builtin(position) position: vec4, - #import bevy_ecs_tilemap::vertex_output -} +#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 + #import bevy_ecs_tilemap::square get_mesh #endif #ifdef ISO_DIAMOND - #import bevy_ecs_tilemap::diamond_iso + #import bevy_ecs_tilemap::diamond_iso get_mesh #endif #ifdef ISO_STAGGERED - #import bevy_ecs_tilemap::staggered_iso + #import bevy_ecs_tilemap::staggered_iso get_mesh #endif #ifdef COLUMN_EVEN_HEX - #import bevy_ecs_tilemap::column_even_hex + #import bevy_ecs_tilemap::column_even_hex get_mesh #endif #ifdef COLUMN_HEX - #import bevy_ecs_tilemap::column_hex + #import bevy_ecs_tilemap::column_hex get_mesh #endif #ifdef COLUMN_ODD_HEX - #import bevy_ecs_tilemap::column_odd_hex + #import bevy_ecs_tilemap::column_odd_hex get_mesh #endif #ifdef ROW_EVEN_HEX - #import bevy_ecs_tilemap::row_even_hex + #import bevy_ecs_tilemap::row_even_hex get_mesh #endif #ifdef ROW_HEX - #import bevy_ecs_tilemap::row_hex + #import bevy_ecs_tilemap::row_hex get_mesh #endif #ifdef ROW_ODD_HEX - #import bevy_ecs_tilemap::row_odd_hex + #import bevy_ecs_tilemap::row_odd_hex get_mesh #endif @vertex -fn vertex(vertex_input: VertexInput) -> VertexOutput { - var out: VertexOutput; +fn vertex(vertex_input: VertexInput) -> MeshVertexOutput { + var out: MeshVertexOutput; let animation_speed = vertex_input.position.z; let mesh_data: MeshOutput = get_mesh(vertex_input.v_index, vec3(vertex_input.position.xy, 0.0)); diff --git a/src/render/shaders/tilemap_vertex_output.wgsl b/src/render/shaders/tilemap_vertex_output.wgsl index e62b0f5f..96531d8f 100644 --- a/src/render/shaders/tilemap_vertex_output.wgsl +++ b/src/render/shaders/tilemap_vertex_output.wgsl @@ -1,5 +1,8 @@ #define_import_path bevy_ecs_tilemap::vertex_output -@location(0) uv: vec4, -@location(1) color: vec4, -@location(2) @interpolate(flat) tile_id: i32, +struct MeshVertexOutput { + @builtin(position) position: vec4, + @location(0) uv: vec4, + @location(1) color: vec4, + @location(2) @interpolate(flat) tile_id: i32, +} diff --git a/src/render/texture_array_cache.rs b/src/render/texture_array_cache.rs index 367abec6..3fb17883 100644 --- a/src/render/texture_array_cache.rs +++ b/src/render/texture_array_cache.rs @@ -16,7 +16,6 @@ use bevy::{ }, utils::{HashMap, HashSet}, }; -use std::num::NonZeroU32; #[derive(Resource, Default, Debug, Clone)] pub struct TextureArrayCache { @@ -176,7 +175,7 @@ impl TextureArrayCache { lod_min_clamp: 0.0, lod_max_clamp: f32::MAX, compare: None, - anisotropy_clamp: None, + anisotropy_clamp: 1, border_color: None, }); @@ -188,7 +187,7 @@ impl TextureArrayCache { base_mip_level: 0, mip_level_count: None, base_array_layer: 0, - array_layer_count: NonZeroU32::new(count), + array_layer_count: Some(count), }); let mip_level_count = gpu_texture.mip_level_count(); diff --git a/src/tiles/mod.rs b/src/tiles/mod.rs index c02243e9..544018c7 100644 --- a/src/tiles/mod.rs +++ b/src/tiles/mod.rs @@ -2,7 +2,7 @@ mod storage; use bevy::{ math::{UVec2, Vec2}, - prelude::{Bundle, Color, Component, FromReflect, Reflect, ReflectComponent}, + prelude::{Bundle, Color, Component, Reflect, ReflectComponent}, }; pub use storage::*; @@ -10,9 +10,7 @@ use crate::map::TilemapId; use crate::TilemapSize; /// A tile position in the tilemap grid. -#[derive( - Component, Reflect, FromReflect, Default, Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, -)] +#[derive(Component, Reflect, Default, Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd)] #[reflect(Component)] pub struct TilePos { pub x: u32, @@ -67,12 +65,12 @@ impl From<&TilePos> for Vec2 { } /// A texture index into the atlas or texture array for a single tile. Indices in an atlas are horizontal based. -#[derive(Component, Reflect, Default, Clone, Copy, Debug, Hash, FromReflect)] +#[derive(Component, Reflect, Default, Clone, Copy, Debug, Hash)] #[reflect(Component)] pub struct TileTextureIndex(pub u32); /// A custom color for the tile. -#[derive(Component, Reflect, Default, Clone, Copy, Debug, FromReflect)] +#[derive(Component, Reflect, Default, Clone, Copy, Debug)] #[reflect(Component)] pub struct TileColor(pub Color); @@ -83,7 +81,7 @@ impl From for TileColor { } /// Hides or shows a tile based on the boolean. Default: True -#[derive(Component, Reflect, Clone, Copy, Debug, Hash, FromReflect)] +#[derive(Component, Reflect, Clone, Copy, Debug, Hash)] #[reflect(Component)] pub struct TileVisible(pub bool); @@ -94,7 +92,7 @@ impl Default for TileVisible { } /// Flips the tiles texture along the X, Y or diagonal axes -#[derive(Component, Reflect, Default, Clone, Copy, Debug, Hash, FromReflect)] +#[derive(Component, Reflect, Default, Clone, Copy, Debug, Hash)] #[reflect(Component)] pub struct TileFlip { /// Flip tile along the x axis. @@ -116,14 +114,14 @@ pub struct TileBundle { pub old_position: TilePosOld, } -#[derive(Component, Reflect, Default, Clone, Copy, Debug, FromReflect)] +#[derive(Component, Reflect, Default, Clone, Copy, Debug)] #[reflect(Component)] pub struct TilePosOld(pub TilePos); /// A component that is attached to a Tile entity that /// tells the GPU how to animate the tile. /// Currently all frames must be aligned in your tilemap. -#[derive(Component, Reflect, Clone, Copy, Debug, FromReflect)] +#[derive(Component, Reflect, Clone, Copy, Debug)] pub struct AnimatedTile { /// The start frame index in the tilemap atlas/array (inclusive). pub start: u32, diff --git a/src/tiles/storage.rs b/src/tiles/storage.rs index 5418a5a3..7937afd4 100644 --- a/src/tiles/storage.rs +++ b/src/tiles/storage.rs @@ -6,7 +6,7 @@ use super::TilePos; /// Used to store tile entities for fast look up. /// Tile entities are stored in a grid. The grid is always filled with None. -#[derive(Component, Reflect, Default, Debug, Clone, FromReflect)] +#[derive(Component, Reflect, Default, Debug, Clone)] #[reflect(Component)] pub struct TileStorage { tiles: Vec>,