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 Bevy 0.8 #205

Closed
wants to merge 4 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
1,146 changes: 592 additions & 554 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ default = []
atlas = []

[dependencies]
bevy = { version = "0.7", default-features = false, features = ["bevy_render","bevy_core_pipeline","bevy_sprite"] }
bevy = { version = "0.8", default-features = false, features = ["bevy_asset","bevy_render","bevy_core_pipeline","bevy_sprite"] }
log = "0.4"
regex = "1.5.4"
bytemuck = "1.7.2"

[dev-dependencies]
anyhow = { version = "1.0" }
bevy = { version = "0.7" }
bevy = { version = "0.8" }
ldtk_rust = { version = "0.5" }
rand = "0.8"
env_logger = "0.9"
Expand All @@ -41,4 +41,4 @@ name = "tiled_rotate"
path = "examples/tiled/tiled_rotate.rs"

[target.wasm32-unknown-unknown]
runner = "wasm-server-runner"
runner = "wasm-server-runner"
2 changes: 1 addition & 1 deletion examples/accessing_tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct CurrentColor(u16);
struct LastUpdate(f64);

fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query: MapQuery) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let texture_handle = asset_server.load("tiles.png");

Expand Down
4 changes: 2 additions & 2 deletions examples/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use rand::{thread_rng, Rng};
mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query: MapQuery) {
commands.spawn_bundle(OrthographicCameraBundle {
commands.spawn_bundle(Camera2dBundle {
transform: Transform::from_xyz(1042.0, 1024.0, 1000.0 - 0.1),
..OrthographicCameraBundle::new_2d()
..Camera2dBundle::default()
});

let texture_handle = asset_server.load("tiles.png");
Expand Down
2 changes: 1 addition & 1 deletion examples/atlas_spacing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bevy_ecs_tilemap::prelude::*;
mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query: MapQuery) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let texture_handle = asset_server.load("tiles_with_spacing.png");

Expand Down
2 changes: 1 addition & 1 deletion examples/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn startup(
asset_server: Res<AssetServer>,
mut meshes: ResMut<Assets<Mesh>>,
) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let texture_handle = asset_server.load("tiles.png");

Expand Down
2 changes: 1 addition & 1 deletion examples/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bevy_ecs_tilemap::prelude::*;
mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query: MapQuery) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let texture_handle = asset_server.load("tiles.png");

Expand Down
2 changes: 1 addition & 1 deletion examples/dynamic_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct LastUpdate {
}

fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query: MapQuery) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let texture_handle = asset_server.load("tiles.png");

Expand Down
2 changes: 1 addition & 1 deletion examples/game_of_life.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bevy_ecs_tilemap::prelude::*;
mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query: MapQuery) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let texture_handle = asset_server.load("tiles.png");

Expand Down
2 changes: 1 addition & 1 deletion examples/helpers/camera.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::{core::Time, input::Input, math::Vec3, prelude::*, render::camera::Camera};
use bevy::{input::Input, math::Vec3, prelude::*, render::camera::Camera};

// A simple camera system for moving and zooming the camera.
pub fn movement(
Expand Down
2 changes: 1 addition & 1 deletion examples/hex_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rand::{thread_rng, Rng};
mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query: MapQuery) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let texture_handle = asset_server.load("flat_hex_tiles.png");

Expand Down
2 changes: 1 addition & 1 deletion examples/hex_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rand::{thread_rng, Rng};
mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query: MapQuery) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let texture_handle = asset_server.load("pointy_hex_tiles.png");

Expand Down
4 changes: 2 additions & 2 deletions examples/improved_iso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use rand::{thread_rng, Rng};
mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query: MapQuery) {
let mut camera_bundle = OrthographicCameraBundle::new_2d();
camera_bundle.orthographic_projection.scale = 0.5;
let mut camera_bundle = Camera2dBundle::default();
camera_bundle.projection.scale = 0.5;
commands.spawn_bundle(camera_bundle);

let texture_handle = asset_server.load("isometric-sheet.png");
Expand Down
2 changes: 1 addition & 1 deletion examples/iso_diamond.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rand::{thread_rng, Rng};
mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query: MapQuery) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let texture_handle = asset_server.load("iso_color.png");

Expand Down
2 changes: 1 addition & 1 deletion examples/iso_staggered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rand::{thread_rng, Rng};
mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query: MapQuery) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let texture_handle = asset_server.load("iso_color.png");

Expand Down
2 changes: 1 addition & 1 deletion examples/layers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rand::{thread_rng, Rng};
mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query: MapQuery) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let texture_handle = asset_server.load("tiles.png");

Expand Down
2 changes: 1 addition & 1 deletion examples/ldtk/ldtk_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod helpers;
mod ldtk;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let handle: Handle<LdtkMap> = asset_server.load("map.ldtk");

Expand Down
2 changes: 1 addition & 1 deletion examples/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bevy_ecs_tilemap::prelude::*;
mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query: MapQuery) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let texture_handle = asset_server.load("tiles.png");

Expand Down
4 changes: 1 addition & 3 deletions examples/random_map.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::collections::HashSet;

use bevy::{
core::Time,
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*,
render::camera::OrthographicCameraBundle,
window::WindowDescriptor,
};
use bevy_ecs_tilemap::prelude::*;
Expand All @@ -13,7 +11,7 @@ use rand::{thread_rng, Rng};
mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query: MapQuery) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let texture_handle = asset_server.load("tiles.png");

Expand Down
4 changes: 2 additions & 2 deletions examples/remove_tiles.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::{core::Time, prelude::*};
use bevy::prelude::*;
use bevy_ecs_tilemap::prelude::*;
use rand::{thread_rng, Rng};

Expand All @@ -10,7 +10,7 @@ struct LastUpdate {
}

fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query: MapQuery) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let texture_handle = asset_server.load("tiles.png");

Expand Down
2 changes: 1 addition & 1 deletion examples/replace_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct Materials {
}

fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query: MapQuery) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let texture_handle_a = asset_server.load("tiles.png");
let texture_handle_b = asset_server.load("tiles2.png");
Expand Down
2 changes: 1 addition & 1 deletion examples/sparse_tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rand::{thread_rng, Rng};
mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query: MapQuery) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let texture_handle = asset_server.load("tiles.png");

Expand Down
4 changes: 2 additions & 2 deletions examples/texture_atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ fn startup(
mut textures: ResMut<Assets<Image>>,
mut map_query: MapQuery,
) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let tile_size = Vec2::new(16.0, 16.0);

let mut atlas_builder = TileAtlasBuilder::new(tile_size);
for handle in texture_handles.handles.iter() {
let texture = textures.get(handle).unwrap();
let texture = textures.get(&handle.clone().typed()).unwrap();
atlas_builder
.add_texture(handle.clone_weak().typed::<Image>(), texture)
.unwrap();
Expand Down
6 changes: 1 addition & 5 deletions examples/tiled/tiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,7 @@ pub fn process_loaded_tile_maps(
&mut commands,
map_settings.clone(),
&mut meshes,
tiled_map
.tilesets
.get(&tileset_index)
.unwrap()
.clone_weak(),
tiled_map.tilesets.get(&tileset_index).unwrap().clone_weak(),
0u16,
layer_index as u16,
move |mut tile_pos| {
Expand Down
2 changes: 1 addition & 1 deletion examples/tiled/tiled_rotate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod helpers;
mod tiled;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

// `rotate.tmx` is generated by Tiled (map editor).
// The map consists of a single tile, flipped and rotated in various ways.
Expand Down
2 changes: 1 addition & 1 deletion examples/tiled/tiled_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod helpers;
mod tiled;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let handle: Handle<TiledMap> = asset_server.load("map.tmx");

Expand Down
4 changes: 2 additions & 2 deletions examples/visibility.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::{core::Time, prelude::*};
use bevy::prelude::*;
use bevy_ecs_tilemap::prelude::*;
use rand::{thread_rng, Rng};

Expand All @@ -10,7 +10,7 @@ struct LastUpdate {
}

fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query: MapQuery) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(Camera2dBundle::default());

let texture_handle = asset_server.load("tiles.png");

Expand Down
24 changes: 9 additions & 15 deletions src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ use crate::{
ChunkPos, IsoType, LayerSettings, LocalTilePos, MapTileError, TilePos, TilemapMeshType,
};
use bevy::{
core::Time,
math::{Vec2, Vec4},
prelude::*,
render::camera::Camera2d,
tasks::AsyncComputeTaskPool,
};
use std::sync::Mutex;

Expand Down Expand Up @@ -187,7 +184,6 @@ impl Chunk {
}

pub(crate) fn update_chunk_mesh(
task_pool: Res<AsyncComputeTaskPool>,
meshes: ResMut<Assets<Mesh>>,
tile_query: Query<(&TilePos, &Tile, Option<&GPUAnimated>)>,
mut changed_chunks: Query<
Expand All @@ -197,7 +193,7 @@ pub(crate) fn update_chunk_mesh(
) {
let threaded_meshes = Mutex::new(meshes);

changed_chunks.par_for_each_mut(&task_pool, 5, |(mut chunk, visibility)| {
changed_chunks.par_for_each_mut(5, |(mut chunk, visibility)| {
if chunk.needs_remesh && visibility.is_visible {
log::trace!(
"Re-meshing chunk at: {:?} layer id of: {}",
Expand Down Expand Up @@ -238,20 +234,18 @@ pub(crate) fn update_chunk_visibility(
continue;
}

let (scale, _rotation, translation) = global_transform.to_scale_rotation_translation();

let bounds_size = Vec2::new(
chunk.settings.chunk_size.0 as f32
* chunk.settings.tile_size.0
* global_transform.scale.x,
chunk.settings.chunk_size.1 as f32
* chunk.settings.tile_size.1
* global_transform.scale.y,
chunk.settings.chunk_size.0 as f32 * chunk.settings.tile_size.0 * scale.x,
chunk.settings.chunk_size.1 as f32 * chunk.settings.tile_size.1 * scale.y,
);

let bounds = Vec4::new(
global_transform.translation.x,
global_transform.translation.x + bounds_size.x,
global_transform.translation.y,
global_transform.translation.y + bounds_size.y,
translation.x,
translation.x + bounds_size.x,
translation.y,
translation.y + bounds_size.y,
);

let padded_camera_bounds = Vec4::new(
Expand Down
5 changes: 3 additions & 2 deletions src/map_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,10 @@ impl<'w, 's> MapQuery<'w, 's> {
let grid_size = layer.settings.grid_size;
let layer_size_in_tiles: Vec2 = layer.get_layer_size_in_tiles().into();
let map_size: Vec2 = layer_size_in_tiles * grid_size;
let (_scale, _rotation, translation) =
transform.to_scale_rotation_translation();
let local_z =
(transform.translation.y + (grid_size.y / 2.0) + pixel_position.y)
/ map_size.y;
(translation.y + (grid_size.y / 2.0) + pixel_position.y) / map_size.y;
return pixel_position.z + (1.0 - local_z);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mesher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl ChunkMesher {
tile_query: &Query<(&TilePos, &Tile, Option<&GPUAnimated>)>,
meshes: &mut ResMut<Assets<Mesh>>,
) {
let mesh = meshes.get_mut(chunk.mesh_handle.clone()).unwrap();
let mesh = meshes.get_mut(&chunk.mesh_handle).unwrap();
let size = ((chunk.settings.chunk_size.0 * chunk.settings.chunk_size.1) * 4) as usize;
let mut positions: Vec<[f32; 3]> = Vec::with_capacity(size);
let mut textures: Vec<[i32; 4]> = Vec::with_capacity(size);
Expand Down
4 changes: 2 additions & 2 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use bevy::{
core_pipeline::Transparent2d,
core_pipeline::core_2d::Transparent2d,
prelude::*,
render::{
extract_component::UniformComponentPlugin,
mesh::MeshVertexAttribute,
render_component::UniformComponentPlugin,
render_phase::AddRenderCommand,
render_resource::{FilterMode, SpecializedRenderPipelines, VertexFormat},
RenderApp, RenderStage,
Expand Down
Loading