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

Update to 0.14.0 #537

Merged
merged 28 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cf3df98
Update to 0.14.0-rc.2
ChristopherBiscardi Jun 7, 2024
2bdc9f1
RenderAssets<Image> is now RenderAssets<GpuImage>
ChristopherBiscardi Jun 7, 2024
a92a680
FloatOrd is now in bevy_math
ChristopherBiscardi Jun 7, 2024
29f5818
convert Transparent2d::dynamic_offset to extra_index
ChristopherBiscardi Jun 7, 2024
d234b18
RenderPhase<Transparent2d> -> ViewSortedRenderPhases<Transparent2d>
ChristopherBiscardi Jun 7, 2024
b6fe345
get_sub_app_mut is now an Option
ChristopherBiscardi Jun 7, 2024
484e7c7
GpuImage::size f32 -> u32 via UVec2
ChristopherBiscardi Jun 7, 2024
684be42
GpuMesh::primitive_topology -> key_bits/BaseMeshPipeline
ChristopherBiscardi Jun 7, 2024
31e330e
RenderChunk2d::prepare requires &mut MeshVertexBufferLayouts now
ChristopherBiscardi Jun 7, 2024
ad615dc
into_linear_f32 -> color.0.linear().to_f32_array(),
ChristopherBiscardi Jun 7, 2024
4b14a61
Must specify type of VisibleEntities when accessing
ChristopherBiscardi Jun 7, 2024
3a11d99
app.world access is functions now
ChristopherBiscardi Jun 7, 2024
b679927
We don't need `World::cell`, and it doesn't exist anymore
ChristopherBiscardi Jun 7, 2024
1386dc2
examples error out unless this bevy bug is addressed with these featu…
ChristopherBiscardi Jun 7, 2024
1b087f4
check_visibility is required for the entity that is renderable
ChristopherBiscardi Jun 7, 2024
692d560
view.view_proj -> view.clip_from_world
ChristopherBiscardi Jun 7, 2024
5a58689
color changes to make tests runnable
ChristopherBiscardi Jun 7, 2024
82d74cf
clippy fix
ChristopherBiscardi Jun 7, 2024
e1a2a55
Update Cargo.toml
ChristopherBiscardi Jun 7, 2024
2ba45da
Update Cargo.toml
ChristopherBiscardi Jun 7, 2024
ff87555
final clippy fixes
ChristopherBiscardi Jun 7, 2024
2d22476
Update Cargo.toml
ChristopherBiscardi Jun 7, 2024
03158fe
Simplify async loading in ldtk/tiled helpers
rparrett Jun 8, 2024
d1d6438
remove second allow lint
ChristopherBiscardi Jun 11, 2024
0600b0b
Merge pull request #1 from rparrett/bevy-0.14-async-assets
ChristopherBiscardi Jun 11, 2024
92fca8f
rc.3 bump
ChristopherBiscardi Jun 18, 2024
9b26ae5
bump version for major release
ChristopherBiscardi Jul 4, 2024
ef20700
remove unused features
ChristopherBiscardi Jul 5, 2024
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
14 changes: 8 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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.12.0"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bevy_ecs_tilemap 13 never released to crates.io, so I moved this to 14 because I think versions track bevy versions?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the pattern in recent releases is a coincidence.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change the version to anything relevant. It seems like the Bevy project is hoping people will release rc candidates, although I don't know if anyone with publish access has the time for that at the moment for this crate.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think StarArawn generally handles release prep himself.

version = "0.14.0"
authors = ["John Mitchell"]
homepage = "https://github.com/StarArawn/bevy_ecs_tilemap"
repository = "https://github.com/StarArawn/bevy_ecs_tilemap"
Expand All @@ -16,7 +16,7 @@ render = []
serde = ["dep:serde"]

[dependencies]
bevy = { version = "0.13", default-features = false, features = [
bevy = { version = "0.14.0-rc.2", default-features = false, features = [
"bevy_core_pipeline",
"bevy_render",
"bevy_asset",
Expand All @@ -35,7 +35,7 @@ tiled = { version = "0.11.0", default-features = false }
thiserror = { version = "1.0" }

[dev-dependencies.bevy]
version = "0.13"
version = "0.14.0-rc.2"
default-features = false
features = [
"bevy_core_pipeline",
Expand All @@ -47,11 +47,13 @@ features = [
"bevy_text",
"bevy_sprite",
#"file_watcher",
"multi-threaded",
"multi_threaded",
ChristopherBiscardi marked this conversation as resolved.
Show resolved Hide resolved
"zstd",
ChristopherBiscardi marked this conversation as resolved.
Show resolved Hide resolved
"bevy_pbr",
]

[target.'cfg(unix)'.dev-dependencies.bevy]
version = "0.13"
version = "0.14.0-rc.2"
default-features = false
features = [
"bevy_core_pipeline",
Expand All @@ -63,7 +65,7 @@ features = [
"x11",
"bevy_text",
"bevy_sprite",
"multi-threaded",
"multi_threaded",
ChristopherBiscardi marked this conversation as resolved.
Show resolved Hide resolved
]


Expand Down
23 changes: 17 additions & 6 deletions src/render/chunk.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::hash::{Hash, Hasher};

use bevy::math::Mat4;
use bevy::prelude::{InheritedVisibility, Resource, Transform};
use bevy::render::primitives::Aabb;
use bevy::render::render_asset::RenderAssetUsages;
use bevy::render::{mesh::BaseMeshPipelineKey, primitives::Aabb};
use bevy::{math::Mat4, render::mesh::PrimitiveTopology};
use bevy::{
math::{UVec2, UVec3, UVec4, Vec2, Vec3Swizzles, Vec4, Vec4Swizzles},
prelude::{Component, Entity, GlobalTransform, Mesh, Vec3},
Expand All @@ -14,6 +13,10 @@ use bevy::{
},
utils::HashMap,
};
use bevy::{
prelude::{InheritedVisibility, Resource, Transform},
render::mesh::MeshVertexBufferLayouts,
};

use crate::prelude::helpers::transform::{chunk_aabb, chunk_index_to_world_space};
use crate::render::extract::ExtractedFrustum;
Expand Down Expand Up @@ -355,7 +358,11 @@ impl RenderChunk2d {
}
}

pub fn prepare(&mut self, device: &RenderDevice) {
pub fn prepare(
&mut self,
device: &RenderDevice,
mut mesh_vertex_buffer_layouts: &mut MeshVertexBufferLayouts,
) {
if self.dirty_mesh {
let size = ((self.size_in_tiles.x * self.size_in_tiles.y) * 4) as usize;
let mut positions: Vec<[f32; 4]> = Vec::with_capacity(size);
Expand Down Expand Up @@ -444,14 +451,18 @@ impl RenderChunk2d {
}
});

let mesh_vertex_buffer_layout = self.mesh.get_mesh_vertex_buffer_layout();
let mesh_vertex_buffer_layout = self
.mesh
.get_mesh_vertex_buffer_layout(&mut mesh_vertex_buffer_layouts);
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,
key_bits: BaseMeshPipelineKey::from_primitive_topology(
PrimitiveTopology::TriangleList,
),
});
self.dirty_mesh = false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/render/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ pub fn extract(
visible: visible.0,
position,
texture,
color: color.0.as_linear_rgba_f32(),
color: color.0.linear().to_f32_array(),
};

let data = tilemap_query.get(tilemap_id.0).unwrap();
Expand Down
42 changes: 22 additions & 20 deletions src/render/material.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
use bevy::{
core_pipeline::core_2d::Transparent2d,
math::FloatOrd,
prelude::*,
reflect::TypePath,
render::{
extract_component::ExtractComponentPlugin,
globals::GlobalsBuffer,
render_asset::RenderAssets,
render_phase::{AddRenderCommand, DrawFunctions, RenderPhase},
render_phase::{
AddRenderCommand, DrawFunctions, PhaseItemExtraIndex, ViewSortedRenderPhases,
},
render_resource::{
AsBindGroup, AsBindGroupError, BindGroup, BindGroupEntry, BindGroupLayout,
BindingResource, OwnedBindingResource, PipelineCache, RenderPipelineDescriptor,
ShaderRef, SpecializedRenderPipeline, SpecializedRenderPipelines,
},
renderer::RenderDevice,
texture::FallbackImage,
texture::{FallbackImage, GpuImage},
view::{ExtractedView, ViewUniforms, VisibleEntities},
Extract, Render, RenderApp, RenderSet,
},
utils::{FloatOrd, HashMap, HashSet},
utils::{HashMap, HashSet},
};
use std::{hash::Hash, marker::PhantomData};

#[cfg(not(feature = "atlas"))]
use bevy::render::renderer::RenderQueue;

use crate::prelude::TilemapId;
use crate::prelude::{TilemapId, TilemapRenderSettings};

use super::{
chunk::{ChunkId, RenderChunk2dStorage},
Expand Down Expand Up @@ -113,7 +116,7 @@ where
}

fn finish(&self, app: &mut App) {
if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
if let Some(render_app) = app.get_sub_app_mut(RenderApp) {
render_app
.add_render_command::<Transparent2d, DrawTilemapMaterial<M>>()
.init_resource::<MaterialTilemapPipeline<M>>()
Expand Down Expand Up @@ -303,7 +306,7 @@ fn prepare_materials_tilemap<M: MaterialTilemap>(
mut extracted_assets: ResMut<ExtractedMaterialsTilemap<M>>,
mut render_materials: ResMut<RenderMaterialsTilemap<M>>,
render_device: Res<RenderDevice>,
images: Res<RenderAssets<Image>>,
images: Res<RenderAssets<GpuImage>>,
fallback_image: Res<FallbackImage>,
pipeline: Res<MaterialTilemapPipeline<M>>,
) {
Expand Down Expand Up @@ -350,7 +353,7 @@ fn prepare_materials_tilemap<M: MaterialTilemap>(
fn prepare_material_tilemap<M: MaterialTilemap>(
material: &M,
render_device: &RenderDevice,
images: &RenderAssets<Image>,
images: &RenderAssets<GpuImage>,
fallback_image: &FallbackImage,
pipeline: &MaterialTilemapPipeline<M>,
) -> Result<PreparedMaterialTilemap<M>, AsBindGroupError> {
Expand Down Expand Up @@ -378,23 +381,20 @@ pub fn queue_material_tilemap_meshes<M: MaterialTilemap>(
),
pipeline_cache: Res<PipelineCache>,
view_uniforms: Res<ViewUniforms>,
gpu_images: Res<RenderAssets<Image>>,
gpu_images: Res<RenderAssets<GpuImage>>,
msaa: Res<Msaa>,
globals_buffer: Res<GlobalsBuffer>,
(standard_tilemap_meshes, materials): (
Query<(Entity, &ChunkId, &Transform, &TilemapId)>,
Query<&Handle<M>>,
),
mut views: Query<(
&ExtractedView,
&VisibleEntities,
&mut RenderPhase<Transparent2d>,
)>,
mut views: Query<(Entity, &ExtractedView, &VisibleEntities)>,
render_materials: Res<RenderMaterialsTilemap<M>>,
#[cfg(not(feature = "atlas"))] (mut texture_array_cache, render_queue): (
ResMut<TextureArrayCache>,
Res<RenderQueue>,
),
mut transparent_render_phases: ResMut<ViewSortedRenderPhases<Transparent2d>>,
) where
M::Data: PartialEq + Eq + Hash + Clone,
{
Expand All @@ -409,16 +409,19 @@ pub fn queue_material_tilemap_meshes<M: MaterialTilemap>(
return;
}

for (view, visible_entities, mut transparent_phase) in views.iter_mut() {
for (view_entity, view, visible_entities) in views.iter_mut() {
let Some(transparent_phase) = transparent_render_phases.get_mut(&view_entity) else {
continue;
};

let draw_tilemap = transparent_2d_draw_functions
.read()
.get_id::<DrawTilemapMaterial<M>>()
.unwrap();

for (entity, chunk_id, transform, tilemap_id) in standard_tilemap_meshes.iter() {
if !visible_entities
.entities
.iter()
.iter::<With<TilemapRenderSettings>>()
.any(|&entity| entity.index() == tilemap_id.0.index())
{
continue;
Expand Down Expand Up @@ -475,7 +478,7 @@ pub fn queue_material_tilemap_meshes<M: MaterialTilemap>(
pipeline: pipeline_id,
sort_key: FloatOrd(z),
batch_range: 0..1,
dynamic_offset: None,
extra_index: PhaseItemExtraIndex::NONE,
});
}
}
Expand All @@ -489,7 +492,7 @@ pub fn bind_material_tilemap_meshes<M: MaterialTilemap>(
render_device: Res<RenderDevice>,
tilemap_pipeline: Res<TilemapPipeline>,
view_uniforms: Res<ViewUniforms>,
gpu_images: Res<RenderAssets<Image>>,
gpu_images: Res<RenderAssets<GpuImage>>,
globals_buffer: Res<GlobalsBuffer>,
mut image_bind_groups: ResMut<ImageBindGroups>,
(standard_tilemap_meshes, materials): (Query<(&ChunkId, &TilemapId)>, Query<&Handle<M>>),
Expand Down Expand Up @@ -535,8 +538,7 @@ pub fn bind_material_tilemap_meshes<M: MaterialTilemap>(

for (chunk_id, tilemap_id) in standard_tilemap_meshes.iter() {
if !visible_entities
.entities
.iter()
.iter::<With<TilemapRenderSettings>>()
.any(|&entity| entity.index() == tilemap_id.0.index())
{
continue;
Expand Down
25 changes: 19 additions & 6 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ use bevy::{
render_phase::AddRenderCommand,
render_resource::{FilterMode, SpecializedRenderPipelines, VertexFormat},
texture::ImageSamplerDescriptor,
view::{check_visibility, VisibilitySystems},
Render, RenderApp, RenderSet,
},
};

#[cfg(not(feature = "atlas"))]
use bevy::render::renderer::RenderDevice;
#[cfg(not(feature = "atlas"))]
use bevy::render::texture::GpuImage;

use crate::tiles::{TilePos, TileStorage};
use crate::{
prelude::TilemapRenderSettings,
tiles::{TilePos, TileStorage},
};
use crate::{
prelude::TilemapTexture,
render::{
Expand Down Expand Up @@ -110,10 +116,10 @@ impl Plugin for TilemapRenderingPlugin {

app.add_plugins(MaterialTilemapPlugin::<StandardTilemapMaterial>::default());

app.world
app.world_mut()
.resource_mut::<Assets<StandardTilemapMaterial>>()
.insert(
Handle::<StandardTilemapMaterial>::default(),
Handle::<StandardTilemapMaterial>::default().id(),
StandardTilemapMaterial::default(),
);
}
Expand Down Expand Up @@ -209,9 +215,16 @@ impl Plugin for TilemapRenderingPlugin {
Shader::from_wgsl
);

app.add_systems(
PostUpdate,
(check_visibility::<With<TilemapRenderSettings>>)
.in_set(VisibilitySystems::CheckVisibility)
.after(VisibilitySystems::CalculateBounds),
);

let render_app = match app.get_sub_app_mut(RenderApp) {
Ok(render_app) => render_app,
Err(_) => return,
Some(render_app) => render_app,
None => return,
};

render_app.init_resource::<TilemapPipeline>();
Expand Down Expand Up @@ -319,7 +332,7 @@ fn prepare_textures(
render_device: Res<RenderDevice>,
mut texture_array_cache: ResMut<TextureArrayCache>,
extracted_tilemap_textures: Query<&ExtractedTilemapTexture>,
render_images: Res<bevy::render::render_asset::RenderAssets<Image>>,
render_images: Res<bevy::render::render_asset::RenderAssets<GpuImage>>,
) {
for extracted_texture in extracted_tilemap_textures.iter() {
texture_array_cache.add_extracted_texture(extracted_texture);
Expand Down
1 change: 0 additions & 1 deletion src/render/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub struct TilemapPipeline {

impl FromWorld for TilemapPipeline {
fn from_world(world: &mut World) -> Self {
let world = world.cell();
let render_device = world.get_resource::<RenderDevice>().unwrap();

let view_layout = render_device.create_bind_group_layout(
Expand Down
5 changes: 3 additions & 2 deletions src/render/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::render::extract::ExtractedFrustum;
use crate::{
prelude::TilemapGridSize, render::RenderChunkSize, render::SecondsSinceStartup, FrustumCulling,
};
use bevy::log::trace;
use bevy::prelude::{InheritedVisibility, Resource};
use bevy::{log::trace, render::mesh::MeshVertexBufferLayouts};
use bevy::{
math::{Mat4, UVec4},
prelude::{Commands, Component, Entity, GlobalTransform, Query, Res, ResMut, Vec2},
Expand Down Expand Up @@ -63,6 +63,7 @@ pub(crate) fn prepare(
render_device: Res<RenderDevice>,
render_queue: Res<RenderQueue>,
seconds_since_startup: Res<SecondsSinceStartup>,
mut mesh_vertex_buffer_layouts: ResMut<MeshVertexBufferLayouts>,
) {
for tile in extracted_tiles.iter() {
// First if the tile position has changed remove the tile from the old location.
Expand Down Expand Up @@ -188,7 +189,7 @@ pub(crate) fn prepare(
}
trace!("Preparing chunk: {:?}", chunk.get_index());

chunk.prepare(&render_device);
chunk.prepare(&render_device, &mut mesh_vertex_buffer_layouts);

let mut chunk_uniform: TilemapUniformData = chunk.into();
chunk_uniform.time = **seconds_since_startup;
Expand Down
2 changes: 1 addition & 1 deletion src/render/shaders/tilemap_vertex.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn vertex(vertex_input: VertexInput) -> MeshVertexOutput {
out.uv = atlas_uvs[vertex_input.v_index % 4u];
out.tile_id = i32(texture_index);
// out.uv = out.uv + 1e-5;
out.position = view.view_proj * mesh_data.world_position;
out.position = view.clip_from_world * mesh_data.world_position;
out.color = vertex_input.color;
out.storage_position = vec2<u32>(vertex_input.position.xy);
return out;
Expand Down
Loading
Loading