Skip to content

Commit

Permalink
feat(cli): encode in parallel (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
elringus authored Sep 10, 2024
1 parent 4acc8fd commit 87b1b60
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ image = { version = "0.25", default-features = false, features = [
"jpeg",
"bmp"
] }
rayon = "1.10.0"
clap = { version = "4.5", features = ["derive"] }
clap_derive = "4.5"
indicatif = "0.17"
6 changes: 3 additions & 3 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod json;
pub mod models;

use crate::models::*;
use rayon::prelude::*;
use sprite_dicing::{DicedSprite, Prefs, Progress, SourceSprite, Texture};
use std::{fs, path::Path, path::PathBuf};

Expand Down Expand Up @@ -69,9 +70,8 @@ fn eval_sprite_id(root: &Path, path: &Path, separator: &str) -> String {
}

fn write_atlases(tex: Vec<Texture>, dir: &Path, fmt: &AtlasFormat, prefs: &Prefs) -> Result<()> {
let total = tex.len();
tex.into_iter().enumerate().try_for_each(|(idx, tex)| {
Progress::report(prefs, 4, idx, total, "Encoding atlas textures");
Progress::report(prefs, 4, 0, tex.len(), "Encoding atlas textures");
tex.into_par_iter().enumerate().try_for_each(|(idx, tex)| {
let name = format!("atlas_{idx}.{}", fmt.extension());
write_atlas(&dir.join(name), tex)
})
Expand Down

0 comments on commit 87b1b60

Please sign in to comment.