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.15 #574

Merged
merged 52 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
9621ad0
Migrate up to af865e76a323fc87dd16157e7f4d7593d02c2b95
rparrett Nov 12, 2024
2f66d8f
Migrate up to bc34216
rparrett Nov 12, 2024
ee5cf96
Msaa has been moved to a component
bas-ie Oct 25, 2024
cdf17e5
Migrate up to 3faca1e
rparrett Nov 12, 2024
a896123
Migrate up to 5abc32c
rparrett Nov 12, 2024
1fdeec6
Migrate up to 6e2f96f
rparrett Nov 12, 2024
d678ab1
Migrate up to 739007f
rparrett Nov 12, 2024
1f31ed3
WIP: last commit that works before retained render world
rparrett Nov 12, 2024
ce982c9
WIP: RRW PoC - Needs bundle cleanup and visibility fix
rparrett Nov 13, 2024
15b5b42
WIP: plowing onward anyway
rparrett Nov 13, 2024
7bb7428
WIP: further plowing
rparrett Nov 13, 2024
7937dbc
wip: forward
rparrett Nov 20, 2024
5055c6e
Wrapper component for Handle<MaterialTilemap>
bas-ie Oct 24, 2024
7a85e08
Missed a Handle to wrap
bas-ie Oct 25, 2024
c81f0c8
WIP: another handle wrap
rparrett Nov 20, 2024
6d1480d
elapsed_seconds -> elapsed_secs
bas-ie Oct 25, 2024
277b42d
Render updates.
tychedelia Oct 26, 2024
f530646
Seemingly fix visibility
rparrett Nov 20, 2024
12557e1
Cleanup
rparrett Nov 20, 2024
fbe206d
get_or_spawn has been deprecated
bas-ie Oct 25, 2024
c877627
Cleanup
rparrett Nov 20, 2024
b624837
Cleanup
rparrett Nov 20, 2024
8cf327e
WIP: restore camera helper
rparrett Nov 21, 2024
d641d05
WIP: helpers compile
rparrett Nov 21, 2024
3fd4e16
WIP: custom_shader example compiles
rparrett Nov 21, 2024
fd51ab6
wip: frustum_cull_test compiles
rparrett Nov 21, 2024
206320c
wip: hex_neighbors_radius_chunks.rs compiles
rparrett Nov 21, 2024
9e0e5a7
wip: hex_neighbors compiles
rparrett Nov 21, 2024
ed898e6
wip: hexagon_generation
rparrett Nov 21, 2024
bf45c9d
wip: ldtk example compiles
rparrett Nov 21, 2024
11c15fa
WIP: tiled/ldtk examples compile
rparrett Nov 21, 2024
8b702ca
WIP: mouse_to_tile compiles
rparrett Nov 21, 2024
b93068b
Fix Camera2dBundle deprecation
rparrett Nov 21, 2024
e0c2267
Fix tiles/maps not syncing outside of the `basic` example
rparrett Nov 21, 2024
c1bde1a
WIP: don't use insert_or_spawn_batch for removals
rparrett Nov 21, 2024
3674bc8
fix: properly detect tilemap changes
adrien-bon Nov 25, 2024
d0762aa
Use Bevy 0.15
rparrett Dec 3, 2024
8fa2e38
Fix panic in 3d_iso example due to bevy issue 16525
rparrett Dec 3, 2024
a6f99de
Use observers and ExtractComponentPlugin for removal
rparrett Dec 3, 2024
958af07
Workaround for Bevy issue 16563
rparrett Dec 3, 2024
2531d0e
Clippy
rparrett Dec 3, 2024
f7fd017
fix: compilation with `serde` feature
adrien-bon Nov 25, 2024
17ff958
chore: fix unused var
adrien-bon Nov 25, 2024
ffaae04
Remove unused dep
rparrett Dec 3, 2024
fe2c8ac
Re-introduce traces for culling
rparrett Dec 4, 2024
e131640
Fix Extracted* not being cleared
rparrett Dec 4, 2024
e3e9d20
Benchmark shouldn't use vsync
rparrett Dec 4, 2024
e7dc0e7
SyncToRenderWorld was made copy, so this can be Copy again
rparrett Dec 4, 2024
fef88f1
Revert "Fix Extracted* not being cleared"
rparrett Dec 5, 2024
279ed17
Fix performance regression due to excessive preparing of tiles
rparrett Dec 5, 2024
05eb36a
Minor tidying
rparrett Dec 5, 2024
86235d6
Better workaround for bevy 16563
rparrett Dec 10, 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
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,26 @@ render = []
serde = ["dep:serde"]

[dependencies]
bevy = { version = "0.14.0", default-features = false, features = [
bevy = { version = "0.15", default-features = false, features = [
"bevy_core_pipeline",
"bevy_render",
"bevy_asset",
"bevy_sprite",
] }
# See Bevy#16563
bevy_internal = { version = "0.15", features = ["bevy_image"] }
log = "0.4"
serde = { version = "1", features = ["derive"], optional = true }

[dev-dependencies]
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.14.0"
version = "0.15"
default-features = false
features = [
"bevy_core_pipeline",
Expand All @@ -43,6 +44,7 @@ features = [
"png",
"ktx2",
"bevy_winit",
"bevy_window",
"bevy_text",
"bevy_sprite",
#"file_watcher",
Expand All @@ -51,7 +53,7 @@ features = [
]

[target.'cfg(unix)'.dev-dependencies.bevy]
version = "0.14.0"
version = "0.15"
default-features = false
features = [
"bevy_core_pipeline",
Expand All @@ -60,6 +62,7 @@ features = [
"png",
"ktx2",
"bevy_winit",
"bevy_window",
"wayland",
"x11",
"bevy_text",
Expand Down
4 changes: 2 additions & 2 deletions examples/3d_iso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use bevy_ecs_tilemap::prelude::*;
mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let map_handle: Handle<helpers::tiled::TiledMap> = asset_server.load("iso_map.tmx");
let map_handle = helpers::tiled::TiledMapHandle(asset_server.load("iso_map.tmx"));

commands.spawn(helpers::tiled::TiledMapBundle {
tiled_map: map_handle,
Expand Down
4 changes: 2 additions & 2 deletions examples/accessing_tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct CurrentColor(u16);
struct LastUpdate(f64);

fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let texture_handle: Handle<Image> = asset_server.load("tiles.png");

Expand Down Expand Up @@ -109,7 +109,7 @@ fn update_map(
)>,
mut tile_query: Query<&mut TileTextureIndex>,
) {
let current_time = time.elapsed_seconds_f64();
let current_time = time.elapsed_secs_f64();
for (mut current_color, mut last_update, tile_storage, map_size) in tilemap_query.iter_mut() {
if current_time - last_update.0 > 0.1 {
current_color.0 += 1;
Expand Down
2 changes: 1 addition & 1 deletion examples/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn create_animated_flowers(mut commands: Commands, asset_server: Res<AssetServer
}

fn startup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn startup(
ArrayTextureLoader,
>,
) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let texture_handle: Handle<Image> = asset_server.load("tiles.png");

Expand Down
4 changes: 3 additions & 1 deletion examples/bench.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*,
window::PresentMode,
};
use bevy_ecs_tilemap::prelude::*;

mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let texture_handle: Handle<Image> = asset_server.load("tiles.png");

Expand Down Expand Up @@ -50,6 +51,7 @@ fn main() {
.set(WindowPlugin {
primary_window: Some(Window {
title: String::from("Benchmark Example"),
present_mode: PresentMode::AutoNoVsync,
..Default::default()
}),
..default()
Expand Down
4 changes: 2 additions & 2 deletions examples/chunking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::{math::Vec3Swizzles, prelude::*, utils::HashSet};
use bevy_ecs_tilemap::prelude::*;
mod helpers;

/// Press WASD to move the camera around, and watch as chunks spawn/despawn in response.
// Press WASD to move the camera around, and watch as chunks spawn/despawn in response.

const TILE_SIZE: TilemapTileSize = TilemapTileSize { x: 16.0, y: 16.0 };
// For this example, don't choose too large a chunk size.
Expand Down Expand Up @@ -54,7 +54,7 @@ fn spawn_chunk(commands: &mut Commands, asset_server: &AssetServer, chunk_pos: I
}

fn startup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
}

fn camera_pos_to_chunk_pos(camera_pos: &Vec2) -> IVec2 {
Expand Down
2 changes: 1 addition & 1 deletion examples/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod helpers;
const QUADRANT_SIDE_LENGTH: u32 = 64;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let texture_handle: Handle<Image> = asset_server.load("tiles.png");

Expand Down
6 changes: 3 additions & 3 deletions examples/custom_shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ fn startup(
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<MyMaterial>>,
) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let my_material_handle = materials.add(MyMaterial {
let my_material_handle = MaterialTilemapHandle::from(materials.add(MyMaterial {
brightness: 0.5,
..default()
});
}));

let texture_handle: Handle<Image> = asset_server.load("tiles.png");

Expand Down
24 changes: 10 additions & 14 deletions examples/frustum_cull_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl FromWorld for FontHandle {

// Generates the initial tilemap, which is a square grid.
fn spawn_tilemap(mut commands: Commands, tile_handle_square: Res<TileHandleSquare>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let map_size = TilemapSize {
// Render chunks are of size 64, so let's create two render chunks
Expand Down Expand Up @@ -122,13 +122,6 @@ fn spawn_map_type_label(
windows: Query<&Window>,
map_type_q: Query<&TilemapType>,
) {
let text_style = TextStyle {
font: font_handle.clone(),
font_size: 20.0,
color: Color::BLACK,
};
let text_justify = JustifyText::Center;

for window in windows.iter() {
for map_type in map_type_q.iter() {
// Place the map type label somewhere in the top left side of the screen
Expand All @@ -138,12 +131,15 @@ fn spawn_map_type_label(
..Default::default()
};
commands.spawn((
Text2dBundle {
text: Text::from_section(format!("{map_type:?}"), text_style.clone())
.with_justify(text_justify),
transform,
Text2d::new(format!("{map_type:?}")),
TextFont {
font: font_handle.clone(),
font_size: 20.0,
..default()
},
TextColor(Color::BLACK),
TextLayout::new_with_justify(JustifyText::Center),
transform,
MapTypeLabel,
));
}
Expand All @@ -160,7 +156,7 @@ fn swap_map_type(
&mut TilemapTileSize,
)>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut map_type_label_q: Query<&mut Text, With<MapTypeLabel>>,
mut map_type_label_q: Query<&mut Text2d, With<MapTypeLabel>>,
tile_handle_square: Res<TileHandleSquare>,
tile_handle_hex_row: Res<TileHandleHexRow>,
tile_handle_hex_col: Res<TileHandleHexCol>,
Expand Down Expand Up @@ -216,7 +212,7 @@ fn swap_map_type(
}

for mut label_text in map_type_label_q.iter_mut() {
label_text.sections[0].value = format!("{:?}", map_type.as_ref());
label_text.0 = format!("{:?}", map_type.as_ref());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions 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>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let texture_handle: Handle<Image> = asset_server.load("tiles.png");

Expand Down Expand Up @@ -58,7 +58,7 @@ fn update(
mut tile_storage_query: Query<(&TileStorage, &TilemapSize, &mut LastUpdate)>,
tile_query: Query<(Entity, &TilePos, &TileVisible)>,
) {
let current_time = time.elapsed_seconds_f64();
let current_time = time.elapsed_secs_f64();
let (tile_storage, map_size, mut last_update) = tile_storage_query.single_mut();
if current_time - last_update.0 > 0.1 {
for (entity, position, visibility) in tile_query.iter() {
Expand Down
2 changes: 1 addition & 1 deletion examples/helpers/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn movement(
}

let z = transform.translation.z;
transform.translation += time.delta_seconds() * direction * 500.;
transform.translation += time.delta_secs() * direction * 500.;
// Important! We need to restore the Z values when moving the camera around.
// Bevy has a specific camera setup and this can mess with how our layers are shown.
transform.translation.z = z;
Expand Down
30 changes: 15 additions & 15 deletions examples/helpers/ldtk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use bevy_ecs_tilemap::{
use std::{collections::HashMap, io::ErrorKind};
use thiserror::Error;

use bevy::{
asset::{io::Reader, AsyncReadExt},
reflect::TypePath,
};
use bevy::{asset::io::Reader, reflect::TypePath};
use bevy::{
asset::{AssetLoader, AssetPath, LoadContext},
prelude::*,
Expand Down Expand Up @@ -39,9 +36,12 @@ pub struct LdtkMapConfig {
pub selected_level: usize,
}

#[derive(Default, Component)]
pub struct LdtkMapHandle(pub Handle<LdtkMap>);

#[derive(Default, Bundle)]
pub struct LdtkMapBundle {
pub ldtk_map: Handle<LdtkMap>,
pub ldtk_map: LdtkMapHandle,
pub ldtk_map_config: LdtkMapConfig,
pub transform: Transform,
pub global_transform: GlobalTransform,
Expand All @@ -61,11 +61,11 @@ impl AssetLoader for LdtkLoader {
type Settings = ();
type Error = LdtkAssetLoaderError;

async fn load<'a>(
&'a self,
reader: &'a mut Reader<'_>,
_settings: &'a Self::Settings,
load_context: &'a mut LoadContext<'_>,
async fn load(
&self,
reader: &mut dyn Reader,
_settings: &Self::Settings,
load_context: &mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
Expand Down Expand Up @@ -110,8 +110,8 @@ pub fn process_loaded_tile_maps(
mut commands: Commands,
mut map_events: EventReader<AssetEvent<LdtkMap>>,
maps: Res<Assets<LdtkMap>>,
mut query: Query<(Entity, &Handle<LdtkMap>, &LdtkMapConfig)>,
new_maps: Query<&Handle<LdtkMap>, Added<Handle<LdtkMap>>>,
mut query: Query<(Entity, &LdtkMapHandle, &LdtkMapConfig)>,
new_maps: Query<&LdtkMapHandle, Added<LdtkMapHandle>>,
) {
let mut changed_maps = Vec::<AssetId<LdtkMap>>::default();
for event in map_events.read() {
Expand All @@ -136,16 +136,16 @@ pub fn process_loaded_tile_maps(

// 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.id());
changed_maps.push(new_map_handle.0.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.id() != *changed_map {
if map_handle.0.id() != *changed_map {
continue;
}
if let Some(ldtk_map) = maps.get(map_handle) {
if let Some(ldtk_map) = maps.get(&map_handle.0) {
// Despawn all existing tilemaps for this LdtkMap
commands.entity(entity).despawn_descendants();

Expand Down
Loading
Loading