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

Upgade to bevy 0.12 #497

Merged
merged 28 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
20ee3c2
Mat4 is now Affine3A for intersects_obb in ExtractedFrustum.
divark Nov 7, 2023
bc6034a
Temporarily pointing to local copy of bevy.
divark Nov 7, 2023
dd34112
Adds multi-threaded flag as bevy dependency.
divark Nov 7, 2023
548adbf
Using new RenderSets from new Rendering Pipeline.
divark Nov 10, 2023
8ad25cc
ComputedVisibility references replaced with Inherited and View.
divark Nov 10, 2023
0dbfef1
Bevy Asset V2 migrations.
divark Nov 10, 2023
14b7a37
AssetPath now populates from from_path vs new.
divark Nov 11, 2023
911d97b
Batch size is now batch range again, with no dynamic offset.
divark Nov 11, 2023
4c9d4e2
Test scripts and modified Cargo.toml now included.
divark Nov 11, 2023
dab7170
anyhow now removed from project.
divark Nov 13, 2023
a5efa5d
Converts AssetPlugin to use mode variable in struct def.
divark Nov 13, 2023
9dd44a1
Bindings variable in PreparedMaterialTilemap now includes u32.
divark Nov 13, 2023
b3a1dab
Shader imports now rusty.
divark Nov 13, 2023
4351935
BindGroupDescriptor initialization now just arguments to create_bind_…
divark Nov 13, 2023
651cb50
image.size now image.size_f32
divark Nov 13, 2023
300ad88
SamplerDescriptor now ImageSamplerDescriptor and ImageFilterMode conv…
divark Nov 13, 2023
b6719ca
filesystem_watcher feature now file_watcher.
divark Nov 13, 2023
cb919e2
Crate version now v0.12.0 and cleans up code formatting.
divark Nov 13, 2023
7a2ab49
Test files gone for PR prep.
divark Nov 13, 2023
1932434
Updates Bevy compatibility table for v0.12.0 support.
divark Nov 13, 2023
6717113
Implements PR suggested changes from rparrett.
divark Nov 13, 2023
6bd512e
Implements 2nd set of PR suggested changes from rparrett.
divark Nov 13, 2023
50718d6
TypeUuid and uuid references removed.
divark Nov 13, 2023
dbc6b17
Change RenderSet for queue_material_tilemap_meshes from Queue to Prep…
divark Nov 26, 2023
658b6c1
Split queue_material_tilemap_meshes into queue and bind variants.
divark Nov 27, 2023
e20f46d
Fixed crash with no texture.
StarArawn Dec 17, 2023
583d6f6
Clippy + Format
StarArawn Dec 17, 2023
e61f0b2
Fixed custom shader warnings.
StarArawn Dec 17, 2023
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
17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[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.11.1"
version = "0.12.0"
authors = ["John Mitchell"]
homepage = "https://github.com/StarArawn/bevy_ecs_tilemap"
repository = "https://github.com/StarArawn/bevy_ecs_tilemap"
license = "MIT"
license-file = "LICENSE"
edition = "2021"
exclude = ["assets/*", "screenshots/*"]
Expand All @@ -16,7 +15,7 @@ atlas = []
render = []

[dependencies]
bevy = { version = "0.11", default-features = false, features = [
bevy = { version = "0.12", default-features = false, features = [
"bevy_core_pipeline",
"bevy_render",
"bevy_asset",
Expand All @@ -26,15 +25,15 @@ log = "0.4"
regex = "1.5.4"

[dev-dependencies]
anyhow = { version = "1.0" }
ldtk_rust = { version = "0.6" }
rand = "0.8"
env_logger = "0.10"
serde_json = { version = "1.0" }
tiled = { version = "0.11.0", default-features = false }
thiserror = { version = "1.0" }

[dev-dependencies.bevy]
version = "0.11"
version = "0.12"
default-features = false
features = [
"bevy_core_pipeline",
Expand All @@ -45,12 +44,13 @@ features = [
"bevy_winit",
"bevy_text",
"bevy_sprite",
"filesystem_watcher",
"webgl2"
"file_watcher",
"webgl2",
"multi-threaded"
]

[target.'cfg(unix)'.dev-dependencies.bevy]
version = "0.11"
version = "0.12"
default-features = false
features = [
"bevy_core_pipeline",
Expand All @@ -62,6 +62,7 @@ features = [
"x11",
"bevy_text",
"bevy_sprite",
"multi-threaded"
]


Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ cargo run --target wasm32-unknown-unknown --example animation --release --featur
|bevy|bevy_ecs_tilemap|
|---|---|
|`main`|`bevy-track`|
|0.12|0.12|
|0.11|0.11.*|
|0.10|0.10|
|0.9|0.9|
Expand Down
6 changes: 3 additions & 3 deletions assets/custom_shader.wgsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import bevy_ecs_tilemap::common process_fragment
#import bevy_ecs_tilemap::vertex_output MeshVertexOutput
#import bevy_sprite::mesh2d_view_bindings globals
#import bevy_ecs_tilemap::common::process_fragment
#import bevy_ecs_tilemap::vertex_output::MeshVertexOutput
#import bevy_sprite::mesh2d_view_bindings::globals

struct MyMaterial {
brightness: f32,
Expand Down
10 changes: 2 additions & 8 deletions examples/3d_iso.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use bevy::utils::Duration;

use bevy::{asset::ChangeWatcher, prelude::*};
use bevy::prelude::*;
use bevy_ecs_tilemap::prelude::*;

mod helpers;
Expand Down Expand Up @@ -33,11 +31,7 @@ fn main() {
}),
..default()
})
.set(ImagePlugin::default_nearest())
.set(AssetPlugin {
watch_for_changes: ChangeWatcher::with_delay(Duration::from_millis(200)),
..default()
}),
.set(ImagePlugin::default_nearest()),
)
.add_plugins((TilemapPlugin, helpers::tiled::TiledMapPlugin))
.add_systems(Startup, startup)
Expand Down
9 changes: 2 additions & 7 deletions examples/custom_shader.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
use bevy::{
prelude::*,
reflect::{TypePath, TypeUuid},
render::render_resource::AsBindGroup,
};
use bevy::{prelude::*, reflect::TypePath, render::render_resource::AsBindGroup};
use bevy_ecs_tilemap::prelude::*;
mod helpers;

#[derive(AsBindGroup, TypeUuid, TypePath, Debug, Clone, Default)]
#[uuid = "31575692-a956-4762-98e2-5d457f552d0a"]
#[derive(AsBindGroup, TypePath, Debug, Clone, Default, Asset)]
pub struct MyMaterial {
#[uniform(0)]
brightness: f32,
Expand Down
76 changes: 49 additions & 27 deletions examples/helpers/ldtk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ use bevy_ecs_tilemap::{
tiles::{TileBundle, TilePos, TileStorage, TileTextureIndex},
TilemapBundle,
};
use std::collections::HashMap;
use std::{collections::HashMap, io::ErrorKind};
use thiserror::Error;

use bevy::reflect::{TypePath, TypeUuid};
use bevy::{
asset::{AssetLoader, AssetPath, BoxedFuture, LoadContext, LoadedAsset},
asset::{io::Reader, AsyncReadExt},
reflect::TypePath,
};
use bevy::{
asset::{AssetLoader, AssetPath, LoadContext},
prelude::*,
utils::BoxedFuture,
};
use bevy_ecs_tilemap::map::TilemapType;

Expand All @@ -18,14 +23,13 @@ pub struct LdtkPlugin;

impl Plugin for LdtkPlugin {
fn build(&self, app: &mut App) {
app.add_asset::<LdtkMap>()
.add_asset_loader(LdtkLoader)
app.init_asset::<LdtkMap>()
.register_asset_loader(LdtkLoader)
.add_systems(Update, process_loaded_tile_maps);
}
}

#[derive(TypeUuid, TypePath)]
#[uuid = "abf9eaf2-f21c-4b46-89b0-8aa5c42199af"]
#[derive(TypePath, Asset)]
pub struct LdtkMap {
pub project: ldtk_rust::Project,
pub tilesets: HashMap<i64, Handle<Image>>,
Expand All @@ -46,14 +50,34 @@ pub struct LdtkMapBundle {

pub struct LdtkLoader;

#[derive(Debug, Error)]
pub enum LdtkAssetLoaderError {
/// An [IO](std::io) Error
#[error("Could not load LDTk file: {0}")]
Io(#[from] std::io::Error),
}

impl AssetLoader for LdtkLoader {
type Asset = LdtkMap;
type Settings = ();
type Error = LdtkAssetLoaderError;

fn load<'a>(
&'a self,
bytes: &'a [u8],
reader: &'a mut Reader,
_settings: &'a Self::Settings,
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<(), anyhow::Error>> {
) -> BoxedFuture<'a, Result<LdtkMap, Self::Error>> {
Box::pin(async move {
let project: ldtk_rust::Project = serde_json::from_slice(bytes)?;
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;

let project: ldtk_rust::Project = serde_json::from_slice(&bytes).map_err(|e| {
std::io::Error::new(
ErrorKind::Other,
format!("Could not read contents of Ldtk map: {e}"),
)
})?;
let dependencies: Vec<(i64, AssetPath)> = project
.defs
.tilesets
Expand All @@ -68,17 +92,14 @@ impl AssetLoader for LdtkLoader {
})
.collect();

let loaded_asset = LoadedAsset::new(LdtkMap {
let ldtk_map = LdtkMap {
project,
tilesets: dependencies
.iter()
.map(|dep| (dep.0, load_context.get_handle(dep.1.clone())))
.map(|dep| (dep.0, load_context.load(dep.1.clone())))
.collect(),
});
load_context.set_default_asset(
loaded_asset.with_dependencies(dependencies.iter().map(|x| x.1.clone()).collect()),
);
Ok(())
};
Ok(ldtk_map)
})
}

Expand All @@ -95,35 +116,36 @@ pub fn process_loaded_tile_maps(
mut query: Query<(Entity, &Handle<LdtkMap>, &LdtkMapConfig)>,
new_maps: Query<&Handle<LdtkMap>, Added<Handle<LdtkMap>>>,
) {
let mut changed_maps = Vec::<Handle<LdtkMap>>::default();
for event in map_events.iter() {
let mut changed_maps = Vec::<AssetId<LdtkMap>>::default();
for event in map_events.read() {
match event {
AssetEvent::Created { handle } => {
AssetEvent::Added { id } => {
log::info!("Map added!");
changed_maps.push(handle.clone());
changed_maps.push(*id);
}
AssetEvent::Modified { handle } => {
AssetEvent::Modified { id } => {
log::info!("Map changed!");
changed_maps.push(handle.clone());
changed_maps.push(*id);
}
AssetEvent::Removed { handle } => {
AssetEvent::Removed { id } => {
log::info!("Map removed!");
// if mesh was modified and removed in the same update, ignore the modification
// events are ordered so future modification events are ok
changed_maps.retain(|changed_handle| changed_handle == handle);
changed_maps.retain(|changed_handle| changed_handle == id);
}
_ => continue,
}
}

// If we have new map entities, add them to the changed_maps list
for new_map_handle in new_maps.iter() {
changed_maps.push(new_map_handle.clone());
changed_maps.push(new_map_handle.id());
}

for changed_map in changed_maps.iter() {
for (entity, map_handle, map_config) in query.iter_mut() {
// only deal with currently changed map
if map_handle != changed_map {
if map_handle.id() != *changed_map {
continue;
}
if let Some(ldtk_map) = maps.get(map_handle) {
Expand Down
Loading