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

feat(cli): encode in parallel #44

Merged
merged 1 commit into from
Sep 10, 2024
Merged
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 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