diff --git a/Cargo.toml b/Cargo.toml index a9794d2..77fd1bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ exclude = [ ] [dependencies] -bevy = { version = "0.16.0", default-features = false, features = [ +bevy = { version = "0.17", default-features = false, features = [ "bevy_asset", "bevy_gizmos", "bevy_pbr", @@ -30,8 +30,7 @@ bytemuck = "1.21.0" image = "0.25.5" [dev-dependencies] -bevy_rts_camera = "0.10.0" -bevy = "0.16.0" +bevy = "0.17" [features] debug = [] diff --git a/assets/shaders/instancing.wgsl b/assets/shaders/instancing.wgsl index b2f5b78..5ee3f6c 100644 --- a/assets/shaders/instancing.wgsl +++ b/assets/shaders/instancing.wgsl @@ -82,33 +82,32 @@ fn vertex(in: VertexInput) -> VertexOutput { return out; } - //////////////////////////////////////////////////////////////////////////////// // TEXTURE BIND GROUP //////////////////////////////////////////////////////////////////////////////// // DIGIT ATLAS -@group(2) @binding(0) +@group(3) @binding(0) var digit_atlas_texture: texture_2d; -@group(2) @binding(1) +@group(3) @binding(1) var digit_atlas_sampler: sampler; // ARROW IMG -@group(2) @binding(2) +@group(3) @binding(2) var arrow_texture: texture_2d; -@group(2) @binding(3) +@group(3) @binding(3) var arrow_sampler: sampler; // 'X' IMG -@group(2) @binding(4) +@group(3) @binding(4) var x_texture: texture_2d; -@group(2) @binding(5) +@group(3) @binding(5) var x_sampler: sampler; // 'X' IMG -@group(2) @binding(6) +@group(3) @binding(6) var destination_texture: texture_2d; -@group(2) @binding(7) +@group(3) @binding(7) var destination_sampler: sampler; //////////////////////////////////////////////////////////////////////////////// @@ -171,4 +170,4 @@ fn fragment(in: VertexOutput) -> @location(0) vec4 { // GRID LINES return in.color; -} \ No newline at end of file +} diff --git a/examples/basic.rs b/examples/basic.rs index 6347a54..3cb3ec7 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -86,7 +86,7 @@ fn spawn_units( Mesh3d(meshes.add(Cuboid::new(5.0, 5.0, 5.0))), MeshMaterial3d(materials.add(StandardMaterial::from_color(BLUE_500))), Transform::from_translation(pos), - Speed(25.0), + Speed(50.0), Boid::default(), // ADD THIS! - Can also be set with custom parameters `Boid::new(50.0, 0.0, 0.0, 5.0)` Name::new("Unit"), ) diff --git a/examples/stress_test2.rs b/examples/stress_test2.rs index 9eed5e4..411dfaf 100644 --- a/examples/stress_test2.rs +++ b/examples/stress_test2.rs @@ -11,7 +11,6 @@ use bevy_pathfinding::{ grid::Grid, utils, BevyPathfindingPlugin, }; -use bevy_rts_camera::{Ground, RtsCamera, RtsCameraControls, RtsCameraPlugin}; const CELL_SIZE: f32 = 10.0; // size of each cell in the grid const BUCKETS: f32 = 150.0; // size of each bucket (spatial partitioning) in the grid @@ -31,7 +30,6 @@ fn main() { .add_plugins(( DefaultPlugins, BevyPathfindingPlugin, // ADD THIS! - RtsCameraPlugin, )) .add_systems(Startup, (camera, setup, spawn_units)) .add_systems(Update, (set_unit_destination, move_unit)) @@ -46,24 +44,6 @@ fn camera(mut cmds: Commands) { Camera3d::default(), GameCamera, // ADD THIS! Transform::from_translation(Vec3::new(0.0, 2000.0, 1500.0)).looking_at(Vec3::ZERO, Vec3::Y), - RtsCamera { - bounds: Aabb2d::new(Vec2::ZERO, Vec2::new(MAP_WIDTH / 2.0, MAP_DEPTH / 2.0)), - min_angle: 60.0f32.to_radians(), - // height_max: 300.0, - height_max: 1000.0, - height_min: 30.0, - ..default() - }, - RtsCameraControls { - edge_pan_width: 0.01, - key_left: KeyCode::KeyA, - key_right: KeyCode::KeyD, - key_up: KeyCode::KeyW, - key_down: KeyCode::KeyS, - pan_speed: 165.0, - zoom_sensitivity: 0.2, - ..default() - }, )); } @@ -77,7 +57,6 @@ fn setup( Mesh3d(meshes.add(Plane3d::default().mesh().size(MAP_WIDTH, MAP_DEPTH))), MeshMaterial3d(materials.add(StandardMaterial::from_color(GREEN_600))), MapBase, // ADD THIS! - Ground, Name::new("Map Base"), ); diff --git a/src/debug/draw.rs b/src/debug/draw.rs index e08a998..c7b88ff 100644 --- a/src/debug/draw.rs +++ b/src/debug/draw.rs @@ -30,7 +30,7 @@ fn draw_on_startup(mut cmds: Commands) { } fn set_active_dbg_flowfield( - trigger: Trigger, + trigger: On, mut cmds: Commands, mut active_dbg_flowfield: ResMut, ) { @@ -47,7 +47,7 @@ fn set_active_dbg_flowfield( } } -fn trigger_events(_trigger: Trigger, mut cmds: Commands, dbg: Res) { +fn trigger_events(_trigger: On, mut cmds: Commands, dbg: Res) { dbg.print("\ntrigger_events() start"); cmds.trigger(DrawGridEv); @@ -59,7 +59,7 @@ fn trigger_events(_trigger: Trigger, mut cmds: Commands, dbg: Res, + _trigger: On, mut cmds: Commands, mut meshes: ResMut>, q_grid_lines: Query>, @@ -140,7 +140,7 @@ fn draw_grid( } pub fn draw_flowfield( - _trigger: Trigger, + _trigger: On, dbg: Res, grid: Res, active_dbg_flowfield: Res, @@ -233,7 +233,7 @@ pub fn draw_flowfield( } fn draw_costfield( - _trigger: Trigger, + _trigger: On, dbg: Res, mut meshes: ResMut>, grid: Res, @@ -310,7 +310,7 @@ fn draw_costfield( } fn draw_integration_field( - _trigger: Trigger, + _trigger: On, dbg: Res, active_dbg_flowfield: Res, mut meshes: ResMut>, @@ -392,7 +392,7 @@ fn draw_integration_field( } fn draw_index( - _trigger: Trigger, + _trigger: On, dbg: Res, mut meshes: ResMut>, grid: Res, diff --git a/src/debug/resources.rs b/src/debug/resources.rs index 9a2a5f3..16c2a9a 100644 --- a/src/debug/resources.rs +++ b/src/debug/resources.rs @@ -199,6 +199,8 @@ pub fn load_dbg_icon(mut images: ResMut>, mut dbg_icon: ResMut) -> Option { + fn extract_component(item: QueryItem<'_, '_, Self::QueryData>) -> Option { Some(InstanceMaterialData(item.0.clone())) } } @@ -95,8 +99,8 @@ impl Plugin for CustomShaderPlugin { .add_systems( Render, ( - queue_custom.in_set(RenderSet::QueueMeshes), - prepare_instance_buffers.in_set(RenderSet::PrepareResources), + queue_custom.in_set(RenderSystems::QueueMeshes), + prepare_instance_buffers.in_set(RenderSystems::PrepareResources), ), ); @@ -155,6 +159,8 @@ fn load_textures( sampler: ImageSampler::Descriptor(ImageSamplerDescriptor::default()), texture_view_descriptor: None, asset_usage: Default::default(), + copy_on_resize: false, + data_order: Default::default(), }; // ARROW IMG @@ -182,6 +188,8 @@ fn load_textures( sampler: ImageSampler::Descriptor(ImageSamplerDescriptor::default()), texture_view_descriptor: None, asset_usage: Default::default(), + copy_on_resize: false, + data_order: Default::default(), }; // 'X' IMG @@ -209,6 +217,8 @@ fn load_textures( sampler: ImageSampler::Descriptor(ImageSamplerDescriptor::default()), texture_view_descriptor: None, asset_usage: Default::default(), + copy_on_resize: false, + data_order: Default::default(), }; // DESTINATION IMG @@ -236,6 +246,8 @@ fn load_textures( sampler: ImageSampler::Descriptor(ImageSamplerDescriptor::default()), texture_view_descriptor: None, asset_usage: Default::default(), + copy_on_resize: false, + data_order: Default::default(), }; // Store the atlas in the first slot of the Digits array @@ -266,6 +278,70 @@ fn queue_custom( ) { let draw_custom = transparent_3d_draw_functions.read().id::(); + // Check if textures are loaded + let (Some(digit_gpu), Some(arrow_gpu), Some(x_gpu), Some(dest_gpu)) = ( + gpu_images.get(&assets.digit_atlas), + gpu_images.get(&assets.arrow_img), + gpu_images.get(&assets.x_img), + gpu_images.get(&assets.destination_img), + ) else { + return; + }; + + let bind_group = render_device.create_bind_group( + Some("digit+arrow bind group"), + &custom_pipeline.texture_layout, + &[ + // digit atlas texture + BindGroupEntry { + binding: 0, + resource: BindingResource::TextureView(&digit_gpu.texture_view), + }, + // digit atlas sampler + BindGroupEntry { + binding: 1, + resource: BindingResource::Sampler(&digit_gpu.sampler), + }, + // arrow texture + BindGroupEntry { + binding: 2, + resource: BindingResource::TextureView(&arrow_gpu.texture_view), + }, + // arrow sampler + BindGroupEntry { + binding: 3, + resource: BindingResource::Sampler(&arrow_gpu.sampler), + }, + // 'x' texture + BindGroupEntry { + binding: 4, + resource: BindingResource::TextureView(&x_gpu.texture_view), + }, + // 'x' sampler + BindGroupEntry { + binding: 5, + resource: BindingResource::Sampler(&x_gpu.sampler), + }, + // destination texture + BindGroupEntry { + binding: 6, + resource: BindingResource::TextureView(&dest_gpu.texture_view), + }, + // destination sampler + BindGroupEntry { + binding: 7, + resource: BindingResource::Sampler(&dest_gpu.sampler), + }, + ], + ); + + // Insert the bind group for all relevant entities + for entity in &q_entities { + cmds.entity(entity).insert(DigitBindGroup { + bind_group: bind_group.clone(), + }); + } + for (view, msaa) in &mut views { let msaa_key = MeshPipelineKey::from_msaa_samples(msaa.samples()); @@ -284,6 +360,7 @@ fn queue_custom( let Some(mesh) = meshes.get(mesh_instance.mesh_asset_id) else { continue; }; + let indexed = matches!(mesh.buffer_info, RenderMeshBufferInfo::Indexed { .. }); let key = view_key | MeshPipelineKey::from_primitive_topology(mesh.primitive_topology()); let pipeline = pipelines @@ -296,68 +373,7 @@ fn queue_custom( distance: rangefinder.distance_translation(&mesh_instance.translation), batch_range: 0..1, extra_index: PhaseItemExtraIndex::None, - indexed: false, - }); - } - } - - if let (Some(digit_gpu), Some(arrow_gpu), Some(x_gpu), Some(dest_gpu)) = ( - gpu_images.get(&assets.digit_atlas), - gpu_images.get(&assets.arrow_img), - gpu_images.get(&assets.x_img), - gpu_images.get(&assets.destination_img), - ) { - let bind_group = render_device.create_bind_group( - Some("digit+arrow bind group"), - &custom_pipeline.texture_layout, - &[ - // digit atlas texture - BindGroupEntry { - binding: 0, - resource: BindingResource::TextureView(&digit_gpu.texture_view), - }, - // digit atlas sampler - BindGroupEntry { - binding: 1, - resource: BindingResource::Sampler(&digit_gpu.sampler), - }, - // arrow texture - BindGroupEntry { - binding: 2, - resource: BindingResource::TextureView(&arrow_gpu.texture_view), - }, - // arrow sampler - BindGroupEntry { - binding: 3, - resource: BindingResource::Sampler(&arrow_gpu.sampler), - }, - // 'x' texture - BindGroupEntry { - binding: 4, - resource: BindingResource::TextureView(&x_gpu.texture_view), - }, - // 'x' sampler - BindGroupEntry { - binding: 5, - resource: BindingResource::Sampler(&x_gpu.sampler), - }, - // destination texture - BindGroupEntry { - binding: 6, - resource: BindingResource::TextureView(&dest_gpu.texture_view), - }, - // destination sampler - BindGroupEntry { - binding: 7, - resource: BindingResource::Sampler(&dest_gpu.sampler), - }, - ], - ); - - // Insert the bind group for all relevant entities - for entity in &q_entities { - cmds.entity(entity).insert(DigitBindGroup { - bind_group: bind_group.clone(), + indexed, }); } } @@ -504,7 +520,6 @@ impl SpecializedMeshPipeline for CustomPipeline { layout: &MeshVertexBufferLayoutRef, ) -> Result { let mut descriptor = self.mesh_pipeline.specialize(key, layout)?; - descriptor.layout.push(self.texture_layout.clone()); descriptor.vertex.shader = self.shader.clone(); descriptor.vertex.buffers.push(VertexBufferLayout { @@ -547,8 +562,9 @@ impl SpecializedMeshPipeline for CustomPipeline { type DrawCustom = ( SetItemPipeline, SetMeshViewBindGroup<0>, - SetMeshBindGroup<1>, - SetDigitTextureBindGroup<2>, + SetMeshViewBindingArrayBindGroup<1>, + SetMeshBindGroup<2>, + SetDigitTextureBindGroup<3>, DrawMeshInstanced, ); diff --git a/src/debug/ui.rs b/src/debug/ui.rs index d712f19..27e4c06 100644 --- a/src/debug/ui.rs +++ b/src/debug/ui.rs @@ -6,7 +6,7 @@ use super::resources::*; use bevy::color::palettes::css::WHITE; use bevy::window::SystemCursorIcon; -use bevy::winit::cursor::CursorIcon; +use bevy::window::CursorIcon; use bevy::{prelude::*, window::PrimaryWindow}; const CLR_TXT: Color = Color::srgb(0.8, 0.8, 0.8); @@ -235,7 +235,7 @@ fn handle_hide_dbg_interaction( } fn toggle_dbg_visibility( - trigger: Trigger, + trigger: On, mut q_node: Query<&mut Node, With>, mut q_border: Query<&mut BorderRadius, With>, mut q_border_root: Query<&mut Node, (With, Without)>, @@ -266,7 +266,7 @@ fn toggle_dbg_visibility( } fn hide_options( - _trigger: Trigger, + _trigger: On, mut q_node: Query<&mut Node, Or<(With, With)>>, ) { for mut node in q_node.iter_mut() { @@ -275,7 +275,7 @@ fn hide_options( } fn update_active_dropdown_option( - _trigger: Trigger, + _trigger: On, dbg: Res, mut q_txt: Query<(&mut Text, &OptionBox)>, ) { @@ -319,7 +319,7 @@ fn handle_boids_dropdown_interaction( } fn toggle_boids_dropdown_visibility( - _trigger: Trigger, + _trigger: On, mut q_node: Query<&mut Node, With>, mut q_border: Query<&mut BorderRadius, (With, Without)>, ) { @@ -389,7 +389,7 @@ fn handle_drag( } fn toggle_dropdown_visibility( - trigger: Trigger, + trigger: On, mut q_dropdown: Query<(&mut Node, &DropdownOptions)>, ) { let option = trigger.event().0; @@ -940,15 +940,15 @@ fn handle_slider_arrow_interaction( } background_clr.0 = CLR_BTN_HOVER.into(); - border_clr.0 = WHITE.into(); + *border_clr = WHITE.into(); } Interaction::Hovered => { background_clr.0 = CLR_BTN_HOVER.into(); - border_clr.0 = WHITE.into(); + *border_clr = WHITE.into(); } Interaction::None => { background_clr.0 = CLR_BACKGROUND_1.into(); - border_clr.0 = CLR_BORDER.into(); + *border_clr = CLR_BORDER.into(); } } } diff --git a/src/flowfield.rs b/src/flowfield.rs index a12e062..8024014 100644 --- a/src/flowfield.rs +++ b/src/flowfield.rs @@ -303,7 +303,7 @@ pub fn flowfield_group_stop_system( } fn initialize_flowfield( - trigger: Trigger, + trigger: On, mut cmds: Commands, grid: ResMut, mut q_ff: Query<(Entity, &mut FlowField)>, @@ -382,7 +382,7 @@ fn initialize_flowfield( // TODO: Causes huge performance dip // Updates integration fields and flowfields whenever a cost field is updated fn update_fields( - _trigger: Trigger, + _trigger: On, mut cmds: Commands, mut q_ff: Query<&mut FlowField>, grid: Res,