code improvements and updates

This commit is contained in:
Simon Gardling 2022-05-11 14:44:25 -04:00
parent 66a05adefc
commit d9100c64cc
7 changed files with 35 additions and 30 deletions

1
.gitignore vendored
View File

@ -2,4 +2,3 @@
/pkg /pkg
/tmp /tmp
/Cargo.lock /Cargo.lock
/assets/data

20
Cargo.lock generated
View File

@ -663,7 +663,7 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]] [[package]]
name = "eframe" name = "eframe"
version = "0.18.0" version = "0.18.0"
source = "git+https://github.com/Titaniumtown/egui.git#e9ed0e4b3ad7ca6e887edb013437077ea398d568" source = "git+https://github.com/Titaniumtown/egui.git#8d3deeb02f7fd0b9a09a6fbbd08ab49c4d399133"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"egui", "egui",
@ -683,7 +683,7 @@ dependencies = [
[[package]] [[package]]
name = "egui" name = "egui"
version = "0.18.1" version = "0.18.1"
source = "git+https://github.com/Titaniumtown/egui.git#e9ed0e4b3ad7ca6e887edb013437077ea398d568" source = "git+https://github.com/Titaniumtown/egui.git#8d3deeb02f7fd0b9a09a6fbbd08ab49c4d399133"
dependencies = [ dependencies = [
"ahash", "ahash",
"epaint", "epaint",
@ -694,7 +694,7 @@ dependencies = [
[[package]] [[package]]
name = "egui-winit" name = "egui-winit"
version = "0.18.0" version = "0.18.0"
source = "git+https://github.com/Titaniumtown/egui.git#e9ed0e4b3ad7ca6e887edb013437077ea398d568" source = "git+https://github.com/Titaniumtown/egui.git#8d3deeb02f7fd0b9a09a6fbbd08ab49c4d399133"
dependencies = [ dependencies = [
"arboard", "arboard",
"egui", "egui",
@ -707,7 +707,7 @@ dependencies = [
[[package]] [[package]]
name = "egui_glow" name = "egui_glow"
version = "0.18.1" version = "0.18.1"
source = "git+https://github.com/Titaniumtown/egui.git#e9ed0e4b3ad7ca6e887edb013437077ea398d568" source = "git+https://github.com/Titaniumtown/egui.git#8d3deeb02f7fd0b9a09a6fbbd08ab49c4d399133"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"egui", "egui",
@ -727,7 +727,7 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]] [[package]]
name = "emath" name = "emath"
version = "0.18.0" version = "0.18.0"
source = "git+https://github.com/Titaniumtown/egui.git#e9ed0e4b3ad7ca6e887edb013437077ea398d568" source = "git+https://github.com/Titaniumtown/egui.git#8d3deeb02f7fd0b9a09a6fbbd08ab49c4d399133"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"serde", "serde",
@ -736,7 +736,7 @@ dependencies = [
[[package]] [[package]]
name = "epaint" name = "epaint"
version = "0.18.1" version = "0.18.1"
source = "git+https://github.com/Titaniumtown/egui.git#e9ed0e4b3ad7ca6e887edb013437077ea398d568" source = "git+https://github.com/Titaniumtown/egui.git#8d3deeb02f7fd0b9a09a6fbbd08ab49c4d399133"
dependencies = [ dependencies = [
"ab_glyph", "ab_glyph",
"ahash", "ahash",
@ -2791,18 +2791,18 @@ dependencies = [
[[package]] [[package]]
name = "zstd" name = "zstd"
version = "0.11.1+zstd.1.5.2" version = "0.11.2+zstd.1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a16b8414fde0414e90c612eba70985577451c4c504b99885ebed24762cb81a" checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4"
dependencies = [ dependencies = [
"zstd-safe", "zstd-safe",
] ]
[[package]] [[package]]
name = "zstd-safe" name = "zstd-safe"
version = "5.0.1+zstd.1.5.2" version = "5.0.2+zstd.1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c12659121420dd6365c5c3de4901f97145b79651fb1d25814020ed2ed0585ae" checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db"
dependencies = [ dependencies = [
"libc", "libc",
"zstd-sys", "zstd-sys",

View File

@ -48,7 +48,6 @@ const_format = { version = "0.2", default-features = false, features = ["fmt"] }
cfg-if = "1" cfg-if = "1"
lazy_static = "1" lazy_static = "1"
ruzstd = { git = "https://github.com/Titaniumtown/zstd-rs.git", branch = "ringbuffer" } ruzstd = { git = "https://github.com/Titaniumtown/zstd-rs.git", branch = "ringbuffer" }
serde_json = "1.0"
tracing = "0.1" tracing = "0.1"
itertools = "0.10" itertools = "0.10"
static_assertions = "1.1" static_assertions = "1.1"

View File

@ -22,3 +22,4 @@
12. Don't use json for text storage 12. Don't use json for text storage
13. Write custom plotter 13. Write custom plotter
14. Cache decompressed data in browser's [Local Storage](https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Storage.html) 14. Cache decompressed data in browser's [Local Storage](https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Storage.html)
15. Add Url hashes loading and setting

View File

@ -1,7 +1,9 @@
use std::{ use std::{
collections::BTreeMap, collections::BTreeMap,
env,
fs::File, fs::File,
io::{BufWriter, Write}, io::{BufWriter, Write},
path::Path,
}; };
use epaint::{ use epaint::{
@ -51,25 +53,24 @@ fn main() {
]), ]),
}; };
let mut file = BufWriter::new(File::create("./assets/data").expect("Could not create file")); let text_json: serde_json::Value =
serde_json::from_str(include_str!("assets/text.json")).unwrap();
let aa: serde_json::Value = serde_json::from_str(include_str!("assets/text.json")).unwrap(); let mut json_file_array = text_json.as_object().unwrap().clone();
let mut json_file_array = aa.as_object().unwrap().clone();
for value in json_file_array.iter_mut() { for value in json_file_array.iter_mut() {
if let serde_json::Value::Array(values) = value.1 { if let serde_json::Value::Array(values) = value.1 {
let values_copy = values.clone(); let values_copy = values.clone();
*value.1 = serde_json::Value::String( *value.1 = serde_json::Value::String(
values_copy values_copy
.iter() .iter()
.map(|s| s.as_str().unwrap()) .map(|s| s.as_str().expect("failed to make a string"))
.collect::<Vec<&str>>() .collect::<Vec<&str>>()
.join("\n"), .join("\n"),
); );
} }
} }
let text_data: TextData = let text_data: TextData = serde_json::from_value(serde_json::Value::Object(json_file_array))
serde_json::from_value(serde_json::Value::Object(json_file_array)).unwrap(); .expect("Failed to convert data to TextData");
let data = bincode::serialize(&TotalData { let data = bincode::serialize(&TotalData {
text: text_data, text: text_data,
@ -77,8 +78,13 @@ fn main() {
}) })
.unwrap(); .unwrap();
let data_compressed = zstd::encode_all(data.as_slice(), 22).unwrap(); let max_zstd_level = zstd::compression_level_range();
println!("{:?}", data_compressed); let data_compressed =
zstd::encode_all(data.as_slice(), *max_zstd_level.end()).expect("Could not compress data");
file.write_all(data_compressed.as_slice()).unwrap(); let path = Path::new(&env::var("OUT_DIR").unwrap()).join("compressed_data");
let mut file = BufWriter::new(File::create(&path).expect("Could not save compressed_data"));
file.write_all(data_compressed.as_slice())
.expect("Failed to save compressed data");
} }

View File

@ -11,7 +11,7 @@ pub struct TextData {
pub welcome: String, pub welcome: String,
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct TotalData { pub struct TotalData {
pub text: TextData, pub text: TextData,
pub fonts: epaint::text::FontDefinitions, pub fonts: epaint::text::FontDefinitions,

View File

@ -17,7 +17,6 @@ use std::{io::Read, ops::BitXorAssign};
use rayon::iter::{IndexedParallelIterator, ParallelIterator}; use rayon::iter::{IndexedParallelIterator, ParallelIterator};
/// Stores current settings/state of [`MathApp`] /// Stores current settings/state of [`MathApp`]
// TODO: find a better name for this
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct AppSettings { pub struct AppSettings {
/// Stores the type of Rienmann sum that should be calculated /// Stores the type of Rienmann sum that should be calculated
@ -46,8 +45,7 @@ pub struct AppSettings {
} }
impl const Default for AppSettings { impl const Default for AppSettings {
/// Default implementation of `AppSettings`, this is how the application /// Default implementation of `AppSettings`, this is how the application starts up
/// starts up
fn default() -> Self { fn default() -> Self {
Self { Self {
riemann_sum: DEFAULT_RIEMANN, riemann_sum: DEFAULT_RIEMANN,
@ -144,7 +142,9 @@ impl MathApp {
let mut data = Vec::new(); let mut data = Vec::new();
let _ = unsafe { let _ = unsafe {
ruzstd::StreamingDecoder::new(&mut include_bytes!("../assets/data").as_slice()) ruzstd::StreamingDecoder::new(
&mut include_bytes!(concat!(env!("OUT_DIR"), "/compressed_data")).as_slice(),
)
.unwrap_unchecked() .unwrap_unchecked()
.read_to_end(&mut data) .read_to_end(&mut data)
.unwrap_unchecked() .unwrap_unchecked()