Skip to content

Commit

Permalink
Changed: Passed all examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
443eb9 committed Mar 4, 2024
1 parent bcc0766 commit 3fb9dcd
Show file tree
Hide file tree
Showing 23 changed files with 139 additions and 113 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/macros/target
/.idea
Cargo.lock
/generated
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ required-features = ["algorithm", "ldtk", "physics"]
[[example]]
name = "chunk_unloading"
path = "examples/chunk_unloading.rs"
required-features = ["debug", "algorithm", "serializing", "physics"]
required-features = ["debug", "serializing", "physics"]

[[example]]
name = "tiled"
Expand Down
12 changes: 7 additions & 5 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# Examples

**Enable `multi-threaded` feature for better performance if possible.**

| Name | Description | Screenshot | Required Features (Add this after `--features=`) | Notice |
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- | ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `animation` | Introduces the way to use animated tiles on your tilemaps. | ![](../docs/imgs/animation.gif) | None | None |
| `baking` | Introduces the way to bake the tilemap into a static image to get better performance. | ![](../docs/imgs/baking.png) | None | None |
| `basic` | Introduces the way to create square/isometric/non-texture tilemaps. | ![](../docs/imgs/basic.png) | None | None |
| `chunk_unloading` | Introduces the way to detect if the camera is entered/left the chunk, and to load/unload chunks. | ![](../docs/imgs/chunk_unloading.gif) | `"debug, algorithm, serializing, physics"` | You need to save the tilemap to your disk first. Please follow the instructions in the file. |
| `chunk_unloading` | Introduces the way to detect if the camera is entered/left the chunk, and to load/unload chunks. | ![](../docs/imgs/chunk_unloading.gif) | `"debug, serializing, physics"` | You need to save the tilemap to your disk first. Please follow the instructions in the file. |
| `custom_material` | Introduces the way to use your custom material on the tilemap. | ![](../docs/imgs/custom_material.gif) | None | None |
| `ldtk_wfc` | Introduces the way to perform wave function collapse (wfc) algorithm using LDtk levels. | ![](../docs/imgs/ldtk_wfc.gif) | `"algorithm, ldtk, physics"` | The screenshot shows the `LdtkWfcMode::MultiMap` mode which requires you to move the little player around using arrow keys. But the actual example is using `LdtkWfcMode::SingleMap` as default so you will see the entire tilemap directly. |
| `ldtk` | Introduces the way to load/unload/switching between LDtk levels, and some extra functionalities including automatically generate the `PathTilemap` and `PhysicsTilemap` according to the specific int grid layers, map the `tile_id` to animations. | ![](../docs/imgs/ldtk.png) | `"debug, ldtk, physics"` | You need to rename the LDtk map filename first. Please follow the instructions in the file. You will see nothing until press the number keys. See `load` function for more info. |
| `pathfinding` | Introduces the way to perform asynchronous A* pathfinding on tilemaps. | ![](../docs/imgs/pathfinding.png) | `"algorithm, multi-threaded"` | None |
| `pathfinding_single_threaded` | Introduces the way to perform synchronous A* pathfinding on tilemaps. | ![](../docs/imgs/pathfinding.png) | `"algorithm, multi-threaded"` | Almost the same with `pathfinding`, but run this if targeting wasm, or with bevy `multi-threaded` disabled. |
| `pathfinding` | Introduces the way to perform asynchronous A* pathfinding on tilemaps. | ![](../docs/imgs/pathfinding.png) | `"algorithm multi-threaded"` | None |
| `pathfinding_single_threaded` | Introduces the way to perform synchronous A* pathfinding on tilemaps. | ![](../docs/imgs/pathfinding.png) | `"algorithm"` | Almost the same with `pathfinding`, but run this if targeting wasm, or with bevy `multi-threaded` disabled. |
| `physics` | Introduces the way to use `PhysicsTilemap` to add colliders to tiles, and the `DataTilemap` which allows you to represent the colliders in an array and `entitiles` will figure out the lease colliders to fill them | ![](../docs/imgs/physics.png) | `"physics"` | None |
| `save_and_load` | Introduces the way to save/load tilemaps from your disk. | ![](../docs/imgs/save_and_load.gif) | `"seriaizing, algorithm, physics"` | Press space to save and right-alt to load. |
| `tiled` | Introduces the way to load/unload/switching beteen Tiled tilemaps. This example is pretty simliar to `ldtk` | ![](../docs/imgs/tiled.gif) | `"tiled, physics"` | Press number keys to switch between tilemaps. |
| `wfc_pattern` | Introduces the way to perform wave function collapse (wfc) algorithm using tilemap patterns. | ![](../docs/imgs/wfc_pattern.png) | `algorithm, multi-threaded` | Youe need to save the patterns to your disk first. Please follow the instructions in the file. Disable `multi-threaded` feature if targeting wasm. |
| `wfc` | Introduces the way to perform wave function collapse (wfc) algorithm using single tiles generated according to texture indices. | ![](../docs/imgs/wfc.png) | `algorithm, multi-threaded` | Disable `multi-threaded` feature if targeting wasm. |
| `wfc_pattern` | Introduces the way to perform wave function collapse (wfc) algorithm using tilemap patterns. | ![](../docs/imgs/wfc_pattern.png) | `algorithm` | Youe need to save the patterns to your disk first. Please follow the instructions in the file. Disable `multi-threaded` feature if targeting wasm. |
| `wfc` | Introduces the way to perform wave function collapse (wfc) algorithm using single tiles generated according to texture indices. | ![](../docs/imgs/wfc.png) | `algorithm` | Disable `multi-threaded` feature if targeting wasm. |
4 changes: 2 additions & 2 deletions examples/baking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn setup(asset_server: Res<AssetServer>, mut commands: Commands) {
TileBuilder::new()
.with_layer(0, TileLayer::no_flip(0))
.with_layer(1, TileLayer::flip_h(1))
.with_color(Color::rgba_u8(68, 62, 185, 64).rgba_to_vec4()),
.with_tint(Color::rgba_u8(68, 62, 185, 64).rgba_to_vec4()),
);

tilemap.storage.fill_rect(
Expand All @@ -94,7 +94,7 @@ fn setup(asset_server: Res<AssetServer>, mut commands: Commands) {
.with_layer(1, TileLayer::no_flip(1))
.with_layer(2, TileLayer::no_flip(2))
.with_layer(3, TileLayer::no_flip(3))
.with_color(Color::ORANGE_RED.rgba_to_vec4()),
.with_tint(Color::ORANGE_RED.rgba_to_vec4()),
);

tilemap.storage.fill_rect(
Expand Down
6 changes: 3 additions & 3 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ fn setup(mut commands: Commands, assets_server: Res<AssetServer>) {
TileArea::new(IVec2 { x: 2, y: 2 }, UVec2 { x: 10, y: 7 }),
TileBuilder::new()
.with_layer(0, TileLayer::no_flip(1))
.with_color(Vec4::new(0.8, 1., 0.8, 0.5)),
.with_tint(Vec4::new(0.8, 1., 0.8, 0.5)),
);

tilemap.storage.set(
&mut commands,
IVec2 { x: 18, y: 8 },
TileBuilder::new()
.with_layer(0, TileLayer::no_flip(0))
.with_color(Color::BLUE.rgba_to_vec4()),
.with_tint(Color::BLUE.rgba_to_vec4()),
);

tilemap.storage.set(
Expand Down Expand Up @@ -169,7 +169,7 @@ fn setup(mut commands: Commands, assets_server: Res<AssetServer>) {
TileArea::new(IVec2::ZERO, UVec2 { x: 20, y: 10 }),
TileBuilder::new()
.with_layer(0, TileLayer::no_flip(0))
.with_color(Vec4::new(1., 1., 0., 1.)),
.with_tint(Vec4::new(1., 1., 0., 1.)),
);

commands.entity(entity).insert(tilemap);
Expand Down
47 changes: 23 additions & 24 deletions examples/chunk_unloading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ fn main() {
.add_systems(Startup, setup)
.add_systems(Update, on_update)
.insert_resource(ChunkSaveConfig {
path: "C:\\saves".to_string(),
path: "generated/chunk_unloading".to_string(),
chunks_per_frame: 1,
})
.insert_resource(ChunkLoadConfig {
path: "C:\\saves".to_string(),
path: "generated/chunk_unloading".to_string(),
chunks_per_frame: 1,
})
// We need to disable frustum culling to see the load/save process.
Expand Down Expand Up @@ -126,28 +126,27 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
// Then all the chunks will be saved to your disk.
// Or you can write your own code to make allow the chunks to be generated at runtime.

// tilemap.storage.fill_rect(
// &mut commands,
// bevy_entitiles::math::TileArea::new(IVec2 { x: -100, y: -100 }, UVec2 { x: 200, y: 200 }),
// TileBuilder::new().with_layer(0, TileLayer::new().with_texture_index(0)),
// );
tilemap.storage.fill_rect(
&mut commands,
bevy_entitiles::math::TileArea::new(IVec2 { x: -100, y: -100 }, UVec2 { x: 200, y: 200 }),
TileBuilder::new().with_layer(0, TileLayer::no_flip(0)),
);

#[allow(unused_mut)]
let mut physics_tilemap = PhysicsTilemap::new_with_chunk_size(16);
// physics_tilemap.fill_rect_custom(
// bevy_entitiles::math::TileArea::new(IVec2 { x: -100, y: -100 }, UVec2 { x: 200, y: 200 }),
// |_| {
// if rand::random::<u32>() % 10 == 0 {
// Some(PhysicsTile {
// rigid_body: true,
// friction: Some(0.2),
// })
// } else {
// None
// }
// },
// false,
// );
physics_tilemap.fill_rect_custom(
bevy_entitiles::math::TileArea::new(IVec2 { x: -100, y: -100 }, UVec2 { x: 200, y: 200 }),
|_| {
if rand::random::<u32>() % 10 == 0 {
Some(PhysicsTile {
rigid_body: true,
friction: Some(0.2),
})
} else {
None
}
},
false,
);
commands.entity(entity).insert(physics_tilemap);

commands.entity(entity).insert(tilemap);
Expand Down Expand Up @@ -176,7 +175,7 @@ fn on_update(
load_cache.schedule_many(
&mut commands,
tilemap,
TilemapLayer::all(),
TilemapLayer::COLOR | TilemapLayer::PHYSICS,
to_load.into_iter(),
);
}
Expand All @@ -185,7 +184,7 @@ fn on_update(
save_cache.schedule_many(
&mut commands,
tilemap,
TilemapLayer::all(),
TilemapLayer::COLOR | TilemapLayer::PHYSICS,
to_unload.into_iter(),
);
}
Expand Down
5 changes: 3 additions & 2 deletions examples/helpers/camera_movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ pub fn camera_control(

if input_mouse.pressed(MouseButton::Left) {
for ev in event_move.read() {
control.target_pos += projection.scale * ev.delta * Vec2::new(-1., 1.);
control.target_pos +=
projection.scale * ev.delta * time.delta_seconds() * 200. * Vec2::new(-1., 1.);
}
} else {
let mut step = 90. * time.delta_seconds();
let mut step = 270. * time.delta_seconds();
if input_keyboard.pressed(KeyCode::ShiftLeft) {
step *= 2.;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/pathfinding_single_threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn setup(
tilemap.storage.fill_rect(
&mut commands,
TileArea::new(IVec2::ZERO, UVec2 { x: 500, y: 500 }),
TileBuilder::new().with_layer(0, TileLayer::new().with_texture_index(0)),
TileBuilder::new().with_layer(0, TileLayer::no_flip(0)),
);

let mut path_tilemap = PathTilemap::new();
Expand Down
4 changes: 2 additions & 2 deletions examples/save_and_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn save_and_load(
if input.just_pressed(KeyCode::Space) {
for t in tilemap.iter() {
commands.entity(t).insert(TilemapSaver {
path: "C:\\saves".to_string(),
path: "generated/save_and_load".to_string(),
mode: TilemapSaverMode::Tilemap,
layers: TilemapLayer::all(),
texture_path: Some("test_isometric.png".to_string()),
Expand All @@ -139,7 +139,7 @@ fn save_and_load(
// load
if input.just_pressed(KeyCode::AltRight) {
commands.spawn(TilemapLoader {
path: "C:\\saves".to_string(),
path: "generated/save_and_load".to_string(),
map_name: "test_map".to_string(),
layers: TilemapLayer::all(),
});
Expand Down
Loading

0 comments on commit 3fb9dcd

Please sign in to comment.