Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bevy 0.10 #396

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ atlas = []
render = []

[dependencies]
bevy = { version = "0.9", default-features = false, features = [
bevy = { git = "https://github.com/bevyengine/bevy", default-features = false, features = [
"bevy_core_pipeline",
"bevy_render",
"bevy_asset",
Expand All @@ -33,7 +33,7 @@ serde_json = { version = "1.0" }
tiled = { version = "0.10.2", default-features = false }

[dev-dependencies.bevy]
version = "0.9"
git = "https://github.com/bevyengine/bevy"
default-features = false
features = [
"bevy_core_pipeline",
Expand All @@ -48,7 +48,7 @@ features = [
]

[target.'cfg(unix)'.dev-dependencies.bevy]
version = "0.9"
git = "https://github.com/bevyengine/bevy"
default-features = false
features = [
"bevy_core_pipeline",
Expand Down
6 changes: 3 additions & 3 deletions examples/accessing_tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ fn main() {
.add_plugins(
DefaultPlugins
.set(WindowPlugin {
window: WindowDescriptor {
primary_window: Some(Window {
title: String::from("Accessing Tiles Example"),
..Default::default()
},
..default()
}),
..default()
})
.set(ImagePlugin::default_nearest()),
Expand Down
13 changes: 6 additions & 7 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ fn swap_texture_or_hide(
}
if keyboard_input.just_pressed(KeyCode::H) {
for (_, mut visibility) in &mut query {
if visibility.is_visible {
visibility.is_visible = false;
} else {
visibility.is_visible = true;
*visibility = match *visibility {
Visibility::Hidden => Visibility::Inherited,
_ => Visibility::Hidden,
}
}
}
Expand All @@ -102,12 +101,12 @@ fn swap_texture_or_hide(
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin{
window: WindowDescriptor {
primary_window: Some(Window {
title: String::from(
"Basic Example - Press Space to change Texture and H to show/hide tilemap.",
),
..Default::default()
},
..default()
}),
..default()
}).set(ImagePlugin::default_nearest()))
.add_plugin(TilemapPlugin)
Expand Down
16 changes: 10 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
//! - 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, CoreStage, Deref, GlobalTransform, Plugin,
Query, Reflect, ReflectComponent, Transform, Visibility,
use bevy::{
prelude::{
Bundle, Changed, Component, ComputedVisibility, CoreSet, Deref, GlobalTransform,
IntoSystemAppConfig, IntoSystemConfig, Plugin, Query, Reflect, ReflectComponent, Transform,
Visibility,
},
render::ExtractSchedule,
};
use map::{
TilemapGridSize, TilemapSize, TilemapSpacing, TilemapTexture, TilemapTextureSize,
Expand All @@ -29,7 +33,7 @@ use tiles::{
};

#[cfg(all(not(feature = "atlas"), feature = "render"))]
use bevy::render::{RenderApp, RenderStage};
use bevy::render::RenderApp;

/// A module that allows pre-loading of atlases into array textures.
#[cfg(all(not(feature = "atlas"), feature = "render"))]
Expand All @@ -52,13 +56,13 @@ impl Plugin for TilemapPlugin {
#[cfg(feature = "render")]
app.add_plugin(render::TilemapRenderingPlugin);

app.add_system_to_stage(CoreStage::First, update_changed_tile_positions);
app.add_system(update_changed_tile_positions.in_base_set(CoreSet::First));

#[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_to_stage(RenderStage::Extract, array_texture_preload::extract);
render_app.add_system(array_texture_preload::extract.in_schedule(ExtractSchedule));
}

app.register_type::<FrustumCulling>()
Expand Down
90 changes: 51 additions & 39 deletions src/render/draw.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use bevy::{
core_pipeline::core_2d::Transparent2d,
ecs::system::{
lifetimeless::{Read, SQuery, SRes},
SystemParamItem,
ecs::{
query::ROQueryItem,
system::{
lifetimeless::{Read, SRes},
SystemParamItem,
},
},
math::UVec4,
prelude::Entity,
render::{
mesh::GpuBufferInfo,
render_phase::{RenderCommand, RenderCommandResult, TrackedRenderPass},
Expand All @@ -28,35 +30,38 @@ use super::{

pub struct SetMeshViewBindGroup<const I: usize>;
impl<const I: usize> RenderCommand<Transparent2d> for SetMeshViewBindGroup<I> {
type Param = SQuery<(Read<ViewUniformOffset>, Read<TilemapViewBindGroup>)>;
type Param = ();
type ViewWorldQuery = (Read<ViewUniformOffset>, Read<TilemapViewBindGroup>);
type ItemWorldQuery = ();

#[inline]
fn render<'w>(
view: Entity,
_item: &Transparent2d,
view_query: SystemParamItem<'w, '_, Self::Param>,
// _view: (),
(view_uniform, pbr_view_bind_group): ROQueryItem<'w, Self::ViewWorldQuery>,
_entity: ROQueryItem<'w, Self::ItemWorldQuery>,
_param: SystemParamItem<'w, '_, Self::Param>,
pass: &mut TrackedRenderPass<'w>,
) -> RenderCommandResult {
let (view_uniform, pbr_view_bind_group) = view_query.get_inner(view).unwrap();
pass.set_bind_group(I, &pbr_view_bind_group.value, &[view_uniform.offset]);

RenderCommandResult::Success
}
}

pub struct SetTransformBindGroup<const I: usize>;
impl<const I: usize> RenderCommand<Transparent2d> for SetTransformBindGroup<I> {
type Param = (
SRes<TransformBindGroup>,
SQuery<Read<DynamicUniformIndex<MeshUniform>>>,
);
type Param = SRes<TransformBindGroup>;
type ViewWorldQuery = ();
type ItemWorldQuery = Read<DynamicUniformIndex<MeshUniform>>;

#[inline]
fn render<'w>(
_view: Entity,
item: &Transparent2d,
(transform_bind_group, mesh_query): SystemParamItem<'w, '_, Self::Param>,
_item: &Transparent2d,
_view: (),
transform_index: ROQueryItem<'w, Self::ItemWorldQuery>,
transform_bind_group: SystemParamItem<'w, '_, Self::Param>,
pass: &mut TrackedRenderPass<'w>,
) -> RenderCommandResult {
let transform_index = mesh_query.get(item.entity).unwrap();
pass.set_bind_group(
I,
&transform_bind_group.into_inner().value,
Expand All @@ -69,18 +74,18 @@ impl<const I: usize> RenderCommand<Transparent2d> for SetTransformBindGroup<I> {

pub struct SetTilemapBindGroup<const I: usize>;
impl<const I: usize> RenderCommand<Transparent2d> for SetTilemapBindGroup<I> {
type Param = (
SRes<TilemapUniformDataBindGroup>,
SQuery<Read<DynamicUniformIndex<TilemapUniformData>>>,
);
type Param = SRes<TilemapUniformDataBindGroup>;
type ItemWorldQuery = Read<DynamicUniformIndex<TilemapUniformData>>;
type ViewWorldQuery = ();

#[inline]
fn render<'w>(
_view: Entity,
item: &Transparent2d,
(tilemap_bind_group, mesh_query): SystemParamItem<'w, '_, Self::Param>,
_item: &Transparent2d,
_view: (),
tilemap_uniform_index: ROQueryItem<'w, Self::ItemWorldQuery>,
tilemap_bind_group: SystemParamItem<'w, '_, Self::Param>,
pass: &mut TrackedRenderPass<'w>,
) -> RenderCommandResult {
let tilemap_uniform_index = mesh_query.get(item.entity).unwrap();
pass.set_bind_group(
I,
&tilemap_bind_group.into_inner().value,
Expand All @@ -93,15 +98,18 @@ impl<const I: usize> RenderCommand<Transparent2d> for SetTilemapBindGroup<I> {

pub struct SetMaterialBindGroup<const I: usize>;
impl<const I: usize> RenderCommand<Transparent2d> for SetMaterialBindGroup<I> {
type Param = (SRes<ImageBindGroups>, SQuery<Read<TilemapTexture>>);
type Param = SRes<ImageBindGroups>;
type ItemWorldQuery = Read<TilemapTexture>;
type ViewWorldQuery = ();

#[inline]
fn render<'w>(
_view: Entity,
item: &Transparent2d,
(image_bind_groups, entities_with_textures): SystemParamItem<'w, '_, Self::Param>,
_item: &Transparent2d,
_view: (),
texture: ROQueryItem<'w, Self::ItemWorldQuery>,
image_bind_groups: SystemParamItem<'w, '_, Self::Param>,
pass: &mut TrackedRenderPass<'w>,
) -> RenderCommandResult {
let texture = entities_with_textures.get(item.entity).unwrap();
let bind_group = image_bind_groups.into_inner().values.get(texture).unwrap();
pass.set_bind_group(I, bind_group, &[]);

Expand All @@ -112,10 +120,14 @@ impl<const I: usize> RenderCommand<Transparent2d> for SetMaterialBindGroup<I> {
pub struct SetItemPipeline;
impl RenderCommand<Transparent2d> for SetItemPipeline {
type Param = SRes<PipelineCache>;
type ViewWorldQuery = ();
type ItemWorldQuery = ();

#[inline]
fn render<'w>(
_view: Entity,
item: &Transparent2d,
_view: (),
_entity: (),
pipeline_cache: SystemParamItem<'w, '_, Self::Param>,
pass: &mut TrackedRenderPass<'w>,
) -> RenderCommandResult {
Expand All @@ -142,18 +154,18 @@ pub type DrawTilemap = (

pub struct DrawMesh;
impl RenderCommand<Transparent2d> for DrawMesh {
type Param = (
SRes<RenderChunk2dStorage>,
SQuery<(Read<ChunkId>, Read<TilemapId>)>,
);
type Param = SRes<RenderChunk2dStorage>;
type ItemWorldQuery = (Read<ChunkId>, Read<TilemapId>);
type ViewWorldQuery = ();

#[inline]
fn render<'w>(
_view: Entity,
item: &Transparent2d,
(chunk_storage, chunk_query): SystemParamItem<'w, '_, Self::Param>,
_item: &Transparent2d,
_view: (),
(chunk_id, tilemap_id): ROQueryItem<'w, Self::ItemWorldQuery>,
chunk_storage: SystemParamItem<'w, '_, Self::Param>,
pass: &mut TrackedRenderPass<'w>,
) -> RenderCommandResult {
let (chunk_id, tilemap_id) = chunk_query.get(item.entity).unwrap();
if let Some(chunk) = chunk_storage.into_inner().get(&UVec4::new(
chunk_id.0.x,
chunk_id.0.y,
Expand Down
3 changes: 2 additions & 1 deletion src/render/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ pub struct ExtractedFrustum {

impl ExtractedFrustum {
pub fn intersects_obb(&self, aabb: &Aabb, transform_matrix: &Mat4) -> bool {
self.frustum.intersects_obb(aabb, transform_matrix, false)
self.frustum
.intersects_obb(aabb, transform_matrix, true, false)
}
}

Expand Down
35 changes: 19 additions & 16 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use bevy::{
render_resource::{
FilterMode, SamplerDescriptor, SpecializedRenderPipelines, VertexFormat,
},
RenderApp, RenderStage,
RenderApp, RenderSet,
},
};

Expand Down Expand Up @@ -118,9 +118,8 @@ impl Plugin for TilemapRenderingPlugin {
#[cfg(not(feature = "atlas"))]
app.add_system(set_texture_to_copy_src);

app.add_system_to_stage(CoreStage::First, clear_removed);
app.add_system_to_stage(CoreStage::PostUpdate, removal_helper_tilemap);
app.add_system_to_stage(CoreStage::PostUpdate, removal_helper);
app.add_system(clear_removed.in_base_set(CoreSet::First));
app.add_systems((removal_helper_tilemap, removal_helper).in_base_set(CoreSet::PostUpdate));

// Extract the chunk size from the TilemapRenderSettings used to initialize the
// ChunkCoordinate resource to insert into the render pipeline
Expand Down Expand Up @@ -229,17 +228,18 @@ impl Plugin for TilemapRenderingPlugin {
.insert_resource(RenderChunk2dStorage::default())
.insert_resource(SecondsSinceStartup(0.0));
render_app
.add_system_to_stage(RenderStage::Extract, extract::extract)
.add_system_to_stage(RenderStage::Extract, extract::extract_removal);
.add_system(extract::extract.in_schedule(ExtractSchedule))
.add_system(extract::extract_removal.in_schedule(ExtractSchedule));
render_app
.add_system_to_stage(RenderStage::Prepare, prepare::prepare)
.add_system_to_stage(
RenderStage::Prepare,
prepare::prepare_removal.before(prepare::prepare),
.add_system(prepare::prepare.in_set(RenderSet::Prepare))
.add_system(
prepare::prepare_removal
.before(prepare::prepare)
.in_set(RenderSet::Prepare),
)
.add_system_to_stage(RenderStage::Queue, queue::queue_meshes)
.add_system_to_stage(RenderStage::Queue, queue::queue_transform_bind_group)
.add_system_to_stage(RenderStage::Queue, queue::queue_tilemap_bind_group)
.add_system(queue::queue_meshes.in_set(RenderSet::Queue))
.add_system(queue::queue_transform_bind_group.in_set(RenderSet::Queue))
.add_system(queue::queue_tilemap_bind_group.in_set(RenderSet::Queue))
.init_resource::<TilemapPipeline>()
.init_resource::<ImageBindGroups>()
.init_resource::<SpecializedRenderPipelines<TilemapPipeline>>()
Expand All @@ -251,7 +251,7 @@ impl Plugin for TilemapRenderingPlugin {
#[cfg(not(feature = "atlas"))]
render_app
.init_resource::<TextureArrayCache>()
.add_system_to_stage(RenderStage::Prepare, prepare_textures);
.add_system(prepare_textures.in_set(RenderSet::Prepare));
}
}

Expand Down Expand Up @@ -292,13 +292,16 @@ pub struct RemovedTileEntity(pub Entity);
#[derive(Component)]
pub struct RemovedMapEntity(pub Entity);

fn removal_helper(mut commands: Commands, removed_query: RemovedComponents<TilePos>) {
fn removal_helper(mut commands: Commands, mut removed_query: RemovedComponents<TilePos>) {
for entity in removed_query.iter() {
commands.spawn(RemovedTileEntity(entity));
}
}

fn removal_helper_tilemap(mut commands: Commands, removed_query: RemovedComponents<TileStorage>) {
fn removal_helper_tilemap(
mut commands: Commands,
mut removed_query: RemovedComponents<TileStorage>,
) {
for entity in removed_query.iter() {
commands.spawn(RemovedMapEntity(entity));
}
Expand Down
5 changes: 3 additions & 2 deletions src/render/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ impl SpecializedRenderPipeline for TilemapPipeline {
write_mask: ColorWrites::ALL,
})],
}),
layout: Some(vec![
layout: vec![
self.view_layout.clone(),
self.mesh_layout.clone(),
self.uniform_layout.clone(),
self.material_layout.clone(),
]),
],
primitive: PrimitiveState {
conservative: false,
cull_mode: Some(Face::Back),
Expand All @@ -241,6 +241,7 @@ impl SpecializedRenderPipeline for TilemapPipeline {
alpha_to_coverage_enabled: false,
},
label: Some("tilemap_pipeline".into()),
push_constant_ranges: Default::default(),
}
}
}
2 changes: 1 addition & 1 deletion src/render/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub fn queue_meshes(
});

let key = TilemapPipelineKey {
msaa: msaa.samples,
msaa: msaa.samples(),
map_type: chunk.get_map_type(),
hdr: view.hdr,
};
Expand Down
Loading