Skip to content
Open
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
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ repository = "https://github.com/forbjok/bevy_simple_tilemap.git"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["rayon"]
rayon = ["dep:rayon"]

[dependencies]
bitflags = "2.3.3"
bytemuck = "1.13.1"
Expand All @@ -29,4 +33,4 @@ default-features = false
features = ["x11", "png"]

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
rayon = "1.7.0"
rayon = { version = "1.7.0", optional = true }
10 changes: 7 additions & 3 deletions src/render/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bevy::render::{texture::Image, view::ComputedVisibility};
use bevy::sprite::TextureAtlas;
use bevy::transform::components::GlobalTransform;

#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(not(target_arch = "wasm32"), feature = "rayon"))]
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};

use crate::tilemap::{row_major_pos, CHUNK_HEIGHT, CHUNK_WIDTH};
Expand Down Expand Up @@ -165,7 +165,9 @@ pub fn extract_tilemaps(

#[cfg(target_arch = "wasm32")]
let chunk_iter = chunks.iter();
#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(not(target_arch = "wasm32"), not(feature = "rayon")))]
let chunk_iter = chunks.iter();
#[cfg(all(not(target_arch = "wasm32"), feature = "rayon"))]
let chunk_iter = chunks.par_iter();

// Extract chunks
Expand All @@ -180,7 +182,9 @@ pub fn extract_tilemaps(

#[cfg(target_arch = "wasm32")]
let tile_iter = chunk.tiles.iter();
#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(not(target_arch = "wasm32"), not(feature = "rayon")))]
let tile_iter = chunk.tiles.iter();
#[cfg(all(not(target_arch = "wasm32"), feature = "rayon"))]
let tile_iter = chunk.tiles.par_iter();

let tiles: Vec<ExtractedTile> = tile_iter
Expand Down
6 changes: 4 additions & 2 deletions src/render/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use bevy::render::{

use bevy::utils::FloatOrd;

#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(not(target_arch = "wasm32"), feature = "rayon"))]
use rayon::iter::{IntoParallelIterator, ParallelIterator};

use crate::TileFlags;
Expand Down Expand Up @@ -141,7 +141,9 @@ pub fn queue_tilemaps(

#[cfg(target_arch = "wasm32")]
let chonk_iter = chonks.into_iter();
#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(not(target_arch = "wasm32"), not(feature = "rayon")))]
let chonk_iter = chonks.into_iter();
#[cfg(all(not(target_arch = "wasm32"), feature = "rayon"))]
let chonk_iter = chonks.into_par_iter();

// Process extracted chunks in parallel, updating their metadata.
Expand Down