From 49225599f2eeb3b68d687505362f730277fde0e7 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Wed, 9 Mar 2022 10:28:18 -0500 Subject: [PATCH] much improved asset handling (now using zstd) --- .gitignore | 2 +- Cargo.toml | 3 ++- pack_assets.sh | 6 ++---- src/egui_app.rs | 19 +++++++++++++------ 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 7c6d80e..c3f8ef8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ Cargo.lock /pkg /tmp -/data.tar \ No newline at end of file +/data.tar.zst \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index ff82354..ccc9655 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,13 +23,14 @@ lto = false [dependencies] eframe = { git = "https://github.com/Titaniumtown/egui", default-features = false, features = ["egui_glow"] } -include-flate = { git = "https://github.com/Titaniumtown/include-flate.git" } +# include-flate = { git = "https://github.com/Titaniumtown/include-flate.git" } shadow-rs = { version = "0.9", default-features = false } const_format = { version = "0.2.22", default-features = false, features = ["fmt"] } cfg-if = "1.0.0" exmex = { git = "https://github.com/Titaniumtown/exmex.git", branch = "main", features = ["partial"] } lazy_static = "1.4.0" tar = "0.4.38" +ruzstd = { git = "https://github.com/KillingSpark/zstd-rs.git" } [build-dependencies] shadow-rs = "0.9" diff --git a/pack_assets.sh b/pack_assets.sh index d2f151f..a56c37e 100755 --- a/pack_assets.sh +++ b/pack_assets.sh @@ -1,5 +1,3 @@ #!/bin/bash -cd assets -rm -fr data.tar | true -tar -cvf data.tar *.* -mv data.tar ../ \ No newline at end of file +rm -fr data.tar.zst | true +tar -I 'zstd --ultra -22' -cf data.tar.zst assets/*.* \ No newline at end of file diff --git a/src/egui_app.rs b/src/egui_app.rs index a93e1f8..dd9f717 100644 --- a/src/egui_app.rs +++ b/src/egui_app.rs @@ -1,5 +1,5 @@ use crate::function::{FunctionEntry, RiemannSum, EMPTY_FUNCTIONENTRY}; -use crate::misc::digits_precision; +use crate::misc::{digits_precision, log_helper}; use crate::parsing::{add_asterisks, test_func}; use const_format::formatc; @@ -10,7 +10,6 @@ use egui::{ RichText, SidePanel, Slider, TopBottomPanel, Vec2, Visuals, Window, }; use epi::{Frame, Storage}; -use include_flate::flate; use instant::Duration; use shadow_rs::shadow; use std::collections::BTreeMap; @@ -43,9 +42,6 @@ const DEFAULT_MIN_X: f64 = -10.0; const DEFAULT_MAX_X: f64 = 10.0; const DEFAULT_INTEGRAL_NUM: usize = 100; -// Font Data -flate!(static DATA_FILE: [u8] from "data.tar"); - // Stores data loaded from files struct FileData { // Stores fonts @@ -64,7 +60,16 @@ struct FileData { lazy_static::lazy_static! { // Load all of the data from the compressed tarballe static ref FILE_DATA: FileData = { - let mut tar_archive = tar::Archive::new(&**DATA_FILE); + let start = instant::Instant::now(); + log_helper("Loading tarball..."); + let mut tar_file_raw = include_bytes!("../data.tar.zst").as_slice(); + log_helper("Decompressing..."); + let mut tar_file = ruzstd::StreamingDecoder::new(&mut tar_file_raw).unwrap(); + let mut tar_file_data = Vec::new(); + log_helper("Reading tarball...."); + tar_file.read_to_end(&mut tar_file_data).unwrap(); + + let mut tar_archive = tar::Archive::new(&*tar_file_data); // Stores fonts let mut font_ubuntu_light: Option = None; @@ -119,6 +124,8 @@ lazy_static::lazy_static! { } } + log_helper(&format!("Done loading assets! Took: {:?}", start.elapsed())); + // Create and return FileData struct FileData { font_ubuntu_light: font_ubuntu_light.expect("Ubuntu Light font not found!"),