Skip to content

Commit aee4779

Browse files
Update to 0.14.0 (#537)
* Update to 0.14.0-rc.2 * [12997](bevyengine/bevy#12997): rename `multi-threaded` to `multi_threaded` * RenderAssets<Image> is now RenderAssets<GpuImage> Implemented in [12827](bevyengine/bevy#12827) * FloatOrd is now in bevy_math implemented in [12732](bevyengine/bevy#12732) * convert Transparent2d::dynamic_offset to extra_index [12889](bevyengine/bevy#12889) Gpu Frustum Culling removed the dynamic_offset of Transparent2d and it became `extra_index` with the special value `PhaseItemExtraIndex::NONE`, which indicates the `None` that was here previously * RenderPhase<Transparent2d> -> ViewSortedRenderPhases<Transparent2d> [12453](https://github.com/StarArawn/bevy_ecs_tilemap/pull/bevyengine/bevy#12453): Render phases are now binned or sorted. Following the changes in the `mesh2d_manual` [example](https://github.com/bevyengine/bevy/blob/ecdd1624f302c5f71aaed95b0984cbbecf8880b7/examples/2d/mesh2d_manual.rs#L357-L358): use the `ViewSortedRenderPhases` resource. * get_sub_app_mut is now an Option in [9202](https://github.com/StarArawn/bevy_ecs_tilemap/pull/bevyengine/bevy/pull/9202) SubApp access has changed * GpuImage::size f32 -> u32 via UVec2 [11698](bevyengine/bevy#11698) changed `GpuImage::size` to `UVec2`. Right above this, `Extent3d` does the same thing, so I'm taking a small leap and assuming can `as`. * GpuMesh::primitive_topology -> key_bits/BaseMeshPipeline [12791](bevyengine/bevy#12791) the `primitive_topology` field on `GpuMesh` was removed in favor of `key_bits` which can be constructed using `BaseMeshPipeline::from_primitive_topology` * RenderChunk2d::prepare requires &mut MeshVertexBufferLayouts now [12216](bevyengine/bevy#12216) introduced an argument `&mut MeshVertexBufferLayouts` to `get_mesh_vertex_buffer_layout`, which bevy_ecs_tilemap calls in `RenderChunk2d::prepare` * into_linear_f32 -> color.0.linear().to_f32_array(), [12163](bevyengine/bevy#12163) bevy_color was created and Color handling has changed. Specifically Color::as_linear_rgba_f32 has been removed. LinearRgba is now its own type that can be accessed via [`linear()`](https://docs.rs/bevy/0.14.0-rc.2/bevy/color/enum.Color.html#method.linear) and then converted. * Must specify type of VisibleEntities when accessing [12582](bevyengine/bevy#12582) divided `VisibleEntities` into separate lists. So now we have to specify which kind of entity we want. I think we want the Mesh here, and I think we can get rid of the `.index` calls on Entity since Entity [already compares bits](https://docs.rs/bevy_ecs/0.14.0-rc.2/src/bevy_ecs/entity/mod.rs.html#173) for optimized codegen purposes. Waiting to do that until the other changes are in though so as to not change functionality until post-upgrade. * app.world access is functions now - [9202](bevyengine/bevy#9202) changed world access to functions. [relevent line](https://github.com/bevyengine/bevy/pull/9202/files#diff-b2fba3a0c86e496085ce7f0e3f1de5960cb754c7d215ed0f087aa556e529f97fR640) - This also surfaced [12655](bevyengine/bevy#12655) which removed `Into<AssetId<T>>` for `Handle<T>`. using a reference or .id() is the solution here. * We don't need `World::cell`, and it doesn't exist anymore In [12551](bevyengine/bevy#12551) `WorldCell` was removed. ...but it turns out we don't need it or its replacement anyway. * examples error out unless this bevy bug is addressed with these features being added bevyengine/bevy#13728 * check_visibility is required for the entity that is renderable As a result of [12582](bevyengine/bevy#12582) `check_visibility` must be implemented for the "renderable" tilemap entities. Doing this is trivial by taking advantage of the existing `check_visibility` type arguments, which accept a [`QF: QueryFilter + 'static`](https://docs.rs/bevy/0.14.0-rc.2/bevy/render/view/fn.check_visibility.html). The same `QueryFilter`` is used when checking `VisibleEntities`. I've chosen `With<TilemapRenderSettings` because presumably if the entity doesn't have a `TilemapRenderSettings` then it will not be rendering, but this could be as sophisticated or simple as we want. For example `WithLight` is currently implemented as ```rust pub type WithLight = Or<(With<PointLight>, With<SpotLight>, With<DirectionalLight>)>; ``` * view.view_proj -> view.clip_from_world [13289](bevyengine/bevy#13489) introduced matrix naming changes, including `view_proj` which becomes `clip_from_world` * color changes to make tests runnable * clippy fix * Update Cargo.toml Co-authored-by: Rob Parrett <robparrett@gmail.com> * Update Cargo.toml Co-authored-by: Rob Parrett <robparrett@gmail.com> * final clippy fixes * Update Cargo.toml Co-authored-by: Rob Parrett <robparrett@gmail.com> * Simplify async loading in ldtk/tiled helpers See Bevy #12550 * remove second allow lint * rc.3 bump * bump version for major release * remove unused features --------- Co-authored-by: Rob Parrett <robparrett@gmail.com>
1 parent e4f3cc6 commit aee4779

15 files changed

+197
-172
lines changed

Cargo.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "bevy_ecs_tilemap"
33
description = "A tilemap rendering plugin for bevy which is more ECS friendly by having an entity per tile."
4-
version = "0.12.0"
4+
version = "0.14.0"
55
authors = ["John Mitchell"]
66
homepage = "https://github.com/StarArawn/bevy_ecs_tilemap"
77
repository = "https://github.com/StarArawn/bevy_ecs_tilemap"
@@ -16,7 +16,7 @@ render = []
1616
serde = ["dep:serde"]
1717

1818
[dependencies]
19-
bevy = { version = "0.13", default-features = false, features = [
19+
bevy = { version = "0.14.0", default-features = false, features = [
2020
"bevy_core_pipeline",
2121
"bevy_render",
2222
"bevy_asset",
@@ -35,7 +35,7 @@ tiled = { version = "0.11.0", default-features = false }
3535
thiserror = { version = "1.0" }
3636

3737
[dev-dependencies.bevy]
38-
version = "0.13"
38+
version = "0.14.0"
3939
default-features = false
4040
features = [
4141
"bevy_core_pipeline",
@@ -47,11 +47,12 @@ features = [
4747
"bevy_text",
4848
"bevy_sprite",
4949
#"file_watcher",
50-
"multi-threaded",
50+
"multi_threaded",
51+
"webgl2",
5152
]
5253

5354
[target.'cfg(unix)'.dev-dependencies.bevy]
54-
version = "0.13"
55+
version = "0.14.0"
5556
default-features = false
5657
features = [
5758
"bevy_core_pipeline",
@@ -63,7 +64,8 @@ features = [
6364
"x11",
6465
"bevy_text",
6566
"bevy_sprite",
66-
"multi-threaded",
67+
"multi_threaded",
68+
"webgl2",
6769
]
6870

6971

examples/colors.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
2929
TileTextureIndex(5),
3030
TilePos { x: 0, y: 0 },
3131
quadrant_size,
32-
Color::rgba(1.0, 0.0, 0.0, 1.0),
32+
Color::srgba(1.0, 0.0, 0.0, 1.0),
3333
tilemap_id,
3434
&mut commands,
3535
&mut tile_storage,
@@ -42,7 +42,7 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
4242
y: 0,
4343
},
4444
quadrant_size,
45-
Color::rgba(0.0, 1.0, 0.0, 1.0),
45+
Color::srgba(0.0, 1.0, 0.0, 1.0),
4646
tilemap_id,
4747
&mut commands,
4848
&mut tile_storage,
@@ -55,7 +55,7 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
5555
y: QUADRANT_SIDE_LENGTH,
5656
},
5757
quadrant_size,
58-
Color::rgba(0.0, 0.0, 1.0, 1.0),
58+
Color::srgba(0.0, 0.0, 1.0, 1.0),
5959
tilemap_id,
6060
&mut commands,
6161
&mut tile_storage,
@@ -68,7 +68,7 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
6868
y: QUADRANT_SIDE_LENGTH,
6969
},
7070
quadrant_size,
71-
Color::rgba(1.0, 1.0, 0.0, 1.0),
71+
Color::srgba(1.0, 1.0, 0.0, 1.0),
7272
tilemap_id,
7373
&mut commands,
7474
&mut tile_storage,

examples/helpers/ldtk.rs

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use bevy::{
1414
use bevy::{
1515
asset::{AssetLoader, AssetPath, LoadContext},
1616
prelude::*,
17-
utils::BoxedFuture,
1817
};
1918
use bevy_ecs_tilemap::map::TilemapType;
2019

@@ -62,45 +61,43 @@ impl AssetLoader for LdtkLoader {
6261
type Settings = ();
6362
type Error = LdtkAssetLoaderError;
6463

65-
fn load<'a>(
64+
async fn load<'a>(
6665
&'a self,
67-
reader: &'a mut Reader,
66+
reader: &'a mut Reader<'_>,
6867
_settings: &'a Self::Settings,
69-
load_context: &'a mut LoadContext,
70-
) -> BoxedFuture<'a, Result<LdtkMap, Self::Error>> {
71-
Box::pin(async move {
72-
let mut bytes = Vec::new();
73-
reader.read_to_end(&mut bytes).await?;
74-
75-
let project: ldtk_rust::Project = serde_json::from_slice(&bytes).map_err(|e| {
76-
std::io::Error::new(
77-
ErrorKind::Other,
78-
format!("Could not read contents of Ldtk map: {e}"),
79-
)
80-
})?;
81-
let dependencies: Vec<(i64, AssetPath)> = project
82-
.defs
83-
.tilesets
84-
.iter()
85-
.filter_map(|tileset| {
86-
tileset.rel_path.as_ref().map(|rel_path| {
87-
(
88-
tileset.uid,
89-
load_context.path().parent().unwrap().join(rel_path).into(),
90-
)
91-
})
68+
load_context: &'a mut LoadContext<'_>,
69+
) -> Result<Self::Asset, Self::Error> {
70+
let mut bytes = Vec::new();
71+
reader.read_to_end(&mut bytes).await?;
72+
73+
let project: ldtk_rust::Project = serde_json::from_slice(&bytes).map_err(|e| {
74+
std::io::Error::new(
75+
ErrorKind::Other,
76+
format!("Could not read contents of Ldtk map: {e}"),
77+
)
78+
})?;
79+
let dependencies: Vec<(i64, AssetPath)> = project
80+
.defs
81+
.tilesets
82+
.iter()
83+
.filter_map(|tileset| {
84+
tileset.rel_path.as_ref().map(|rel_path| {
85+
(
86+
tileset.uid,
87+
load_context.path().parent().unwrap().join(rel_path).into(),
88+
)
9289
})
93-
.collect();
90+
})
91+
.collect();
9492

95-
let ldtk_map = LdtkMap {
96-
project,
97-
tilesets: dependencies
98-
.iter()
99-
.map(|dep| (dep.0, load_context.load(dep.1.clone())))
100-
.collect(),
101-
};
102-
Ok(ldtk_map)
103-
})
93+
let ldtk_map = LdtkMap {
94+
project,
95+
tilesets: dependencies
96+
.iter()
97+
.map(|dep| (dep.0, load_context.load(dep.1.clone())))
98+
.collect(),
99+
};
100+
Ok(ldtk_map)
104101
}
105102

106103
fn extensions(&self) -> &[&str] {

examples/helpers/tiled.rs

Lines changed: 73 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use bevy::{
2525
Res, Transform, Update,
2626
},
2727
reflect::TypePath,
28-
utils::{BoxedFuture, HashMap},
28+
utils::HashMap,
2929
};
3030
use bevy_ecs_tilemap::prelude::*;
3131

@@ -104,90 +104,87 @@ impl AssetLoader for TiledLoader {
104104
type Settings = ();
105105
type Error = TiledAssetLoaderError;
106106

107-
fn load<'a>(
107+
async fn load<'a>(
108108
&'a self,
109-
reader: &'a mut Reader,
109+
reader: &'a mut Reader<'_>,
110110
_settings: &'a Self::Settings,
111-
load_context: &'a mut bevy::asset::LoadContext,
112-
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
113-
Box::pin(async move {
114-
let mut bytes = Vec::new();
115-
reader.read_to_end(&mut bytes).await?;
116-
117-
let mut loader = tiled::Loader::with_cache_and_reader(
118-
tiled::DefaultResourceCache::new(),
119-
BytesResourceReader::new(&bytes),
120-
);
121-
let map = loader.load_tmx_map(load_context.path()).map_err(|e| {
122-
std::io::Error::new(ErrorKind::Other, format!("Could not load TMX map: {e}"))
123-
})?;
124-
125-
let mut tilemap_textures = HashMap::default();
126-
#[cfg(not(feature = "atlas"))]
127-
let mut tile_image_offsets = HashMap::default();
128-
129-
for (tileset_index, tileset) in map.tilesets().iter().enumerate() {
130-
let tilemap_texture = match &tileset.image {
131-
None => {
132-
#[cfg(feature = "atlas")]
133-
{
134-
log::info!("Skipping image collection tileset '{}' which is incompatible with atlas feature", tileset.name);
135-
continue;
136-
}
111+
load_context: &'a mut bevy::asset::LoadContext<'_>,
112+
) -> Result<Self::Asset, Self::Error> {
113+
let mut bytes = Vec::new();
114+
reader.read_to_end(&mut bytes).await?;
115+
116+
let mut loader = tiled::Loader::with_cache_and_reader(
117+
tiled::DefaultResourceCache::new(),
118+
BytesResourceReader::new(&bytes),
119+
);
120+
let map = loader.load_tmx_map(load_context.path()).map_err(|e| {
121+
std::io::Error::new(ErrorKind::Other, format!("Could not load TMX map: {e}"))
122+
})?;
123+
124+
let mut tilemap_textures = HashMap::default();
125+
#[cfg(not(feature = "atlas"))]
126+
let mut tile_image_offsets = HashMap::default();
127+
128+
for (tileset_index, tileset) in map.tilesets().iter().enumerate() {
129+
let tilemap_texture = match &tileset.image {
130+
None => {
131+
#[cfg(feature = "atlas")]
132+
{
133+
log::info!("Skipping image collection tileset '{}' which is incompatible with atlas feature", tileset.name);
134+
continue;
135+
}
137136

138-
#[cfg(not(feature = "atlas"))]
139-
{
140-
let mut tile_images: Vec<Handle<Image>> = Vec::new();
141-
for (tile_id, tile) in tileset.tiles() {
142-
if let Some(img) = &tile.image {
143-
// The load context path is the TMX file itself. If the file is at the root of the
144-
// assets/ directory structure then the tmx_dir will be empty, which is fine.
145-
let tmx_dir = load_context
146-
.path()
147-
.parent()
148-
.expect("The asset load context was empty.");
149-
let tile_path = tmx_dir.join(&img.source);
150-
let asset_path = AssetPath::from(tile_path);
151-
log::info!("Loading tile image from {asset_path:?} as image ({tileset_index}, {tile_id})");
152-
let texture: Handle<Image> =
153-
load_context.load(asset_path.clone());
154-
tile_image_offsets
155-
.insert((tileset_index, tile_id), tile_images.len() as u32);
156-
tile_images.push(texture.clone());
157-
}
137+
#[cfg(not(feature = "atlas"))]
138+
{
139+
let mut tile_images: Vec<Handle<Image>> = Vec::new();
140+
for (tile_id, tile) in tileset.tiles() {
141+
if let Some(img) = &tile.image {
142+
// The load context path is the TMX file itself. If the file is at the root of the
143+
// assets/ directory structure then the tmx_dir will be empty, which is fine.
144+
let tmx_dir = load_context
145+
.path()
146+
.parent()
147+
.expect("The asset load context was empty.");
148+
let tile_path = tmx_dir.join(&img.source);
149+
let asset_path = AssetPath::from(tile_path);
150+
log::info!("Loading tile image from {asset_path:?} as image ({tileset_index}, {tile_id})");
151+
let texture: Handle<Image> = load_context.load(asset_path.clone());
152+
tile_image_offsets
153+
.insert((tileset_index, tile_id), tile_images.len() as u32);
154+
tile_images.push(texture.clone());
158155
}
159-
160-
TilemapTexture::Vector(tile_images)
161156
}
157+
158+
TilemapTexture::Vector(tile_images)
162159
}
163-
Some(img) => {
164-
// The load context path is the TMX file itself. If the file is at the root of the
165-
// assets/ directory structure then the tmx_dir will be empty, which is fine.
166-
let tmx_dir = load_context
167-
.path()
168-
.parent()
169-
.expect("The asset load context was empty.");
170-
let tile_path = tmx_dir.join(&img.source);
171-
let asset_path = AssetPath::from(tile_path);
172-
let texture: Handle<Image> = load_context.load(asset_path.clone());
173-
174-
TilemapTexture::Single(texture.clone())
175-
}
176-
};
160+
}
161+
Some(img) => {
162+
// The load context path is the TMX file itself. If the file is at the root of the
163+
// assets/ directory structure then the tmx_dir will be empty, which is fine.
164+
let tmx_dir = load_context
165+
.path()
166+
.parent()
167+
.expect("The asset load context was empty.");
168+
let tile_path = tmx_dir.join(&img.source);
169+
let asset_path = AssetPath::from(tile_path);
170+
let texture: Handle<Image> = load_context.load(asset_path.clone());
171+
172+
TilemapTexture::Single(texture.clone())
173+
}
174+
};
177175

178-
tilemap_textures.insert(tileset_index, tilemap_texture);
179-
}
176+
tilemap_textures.insert(tileset_index, tilemap_texture);
177+
}
180178

181-
let asset_map = TiledMap {
182-
map,
183-
tilemap_textures,
184-
#[cfg(not(feature = "atlas"))]
185-
tile_image_offsets,
186-
};
179+
let asset_map = TiledMap {
180+
map,
181+
tilemap_textures,
182+
#[cfg(not(feature = "atlas"))]
183+
tile_image_offsets,
184+
};
187185

188-
log::info!("Loaded map: {}", load_context.path().display());
189-
Ok(asset_map)
190-
})
186+
log::info!("Loaded map: {}", load_context.path().display());
187+
Ok(asset_map)
191188
}
192189

193190
fn extensions(&self) -> &[&str] {

examples/hex_neighbors.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use bevy::math::Vec4Swizzles;
21
use bevy::prelude::*;
2+
use bevy::{color::palettes, math::Vec4Swizzles};
33
use bevy_ecs_tilemap::helpers::hex_grid::neighbors::{HexDirection, HexNeighbors};
44
use bevy_ecs_tilemap::prelude::*;
55
mod helpers;
@@ -315,7 +315,7 @@ fn hover_highlight_tile_label(
315315
if let Ok(label) = tile_label_q.get(tile_entity) {
316316
if let Ok(mut tile_text) = text_q.get_mut(label.0) {
317317
for section in tile_text.sections.iter_mut() {
318-
section.style.color = Color::RED;
318+
section.style.color = palettes::tailwind::RED_600.into();
319319
}
320320
commands.entity(tile_entity).insert(Hovered);
321321
}
@@ -371,7 +371,7 @@ fn highlight_neighbor_label(
371371
if let Ok(label) = tile_label_q.get(tile_entity) {
372372
if let Ok(mut tile_text) = text_q.get_mut(label.0) {
373373
for section in tile_text.sections.iter_mut() {
374-
section.style.color = Color::BLUE;
374+
section.style.color = palettes::tailwind::BLUE_600.into();
375375
}
376376
commands.entity(tile_entity).insert(NeighborHighlight);
377377
}
@@ -412,7 +412,7 @@ fn highlight_neighbor_label(
412412
if let Ok(label) = tile_label_q.get(tile_entity) {
413413
if let Ok(mut tile_text) = text_q.get_mut(label.0) {
414414
for section in tile_text.sections.iter_mut() {
415-
section.style.color = Color::GREEN;
415+
section.style.color = palettes::tailwind::GREEN_600.into();
416416
}
417417
commands.entity(tile_entity).insert(NeighborHighlight);
418418
}

0 commit comments

Comments
 (0)