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
/tmp
/Cargo.lock
/assets/data

20
Cargo.lock generated
View File

@ -663,7 +663,7 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]]
name = "eframe"
version = "0.18.0"
source = "git+https://github.com/Titaniumtown/egui.git#e9ed0e4b3ad7ca6e887edb013437077ea398d568"
source = "git+https://github.com/Titaniumtown/egui.git#8d3deeb02f7fd0b9a09a6fbbd08ab49c4d399133"
dependencies = [
"bytemuck",
"egui",
@ -683,7 +683,7 @@ dependencies = [
[[package]]
name = "egui"
version = "0.18.1"
source = "git+https://github.com/Titaniumtown/egui.git#e9ed0e4b3ad7ca6e887edb013437077ea398d568"
source = "git+https://github.com/Titaniumtown/egui.git#8d3deeb02f7fd0b9a09a6fbbd08ab49c4d399133"
dependencies = [
"ahash",
"epaint",
@ -694,7 +694,7 @@ dependencies = [
[[package]]
name = "egui-winit"
version = "0.18.0"
source = "git+https://github.com/Titaniumtown/egui.git#e9ed0e4b3ad7ca6e887edb013437077ea398d568"
source = "git+https://github.com/Titaniumtown/egui.git#8d3deeb02f7fd0b9a09a6fbbd08ab49c4d399133"
dependencies = [
"arboard",
"egui",
@ -707,7 +707,7 @@ dependencies = [
[[package]]
name = "egui_glow"
version = "0.18.1"
source = "git+https://github.com/Titaniumtown/egui.git#e9ed0e4b3ad7ca6e887edb013437077ea398d568"
source = "git+https://github.com/Titaniumtown/egui.git#8d3deeb02f7fd0b9a09a6fbbd08ab49c4d399133"
dependencies = [
"bytemuck",
"egui",
@ -727,7 +727,7 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "emath"
version = "0.18.0"
source = "git+https://github.com/Titaniumtown/egui.git#e9ed0e4b3ad7ca6e887edb013437077ea398d568"
source = "git+https://github.com/Titaniumtown/egui.git#8d3deeb02f7fd0b9a09a6fbbd08ab49c4d399133"
dependencies = [
"bytemuck",
"serde",
@ -736,7 +736,7 @@ dependencies = [
[[package]]
name = "epaint"
version = "0.18.1"
source = "git+https://github.com/Titaniumtown/egui.git#e9ed0e4b3ad7ca6e887edb013437077ea398d568"
source = "git+https://github.com/Titaniumtown/egui.git#8d3deeb02f7fd0b9a09a6fbbd08ab49c4d399133"
dependencies = [
"ab_glyph",
"ahash",
@ -2791,18 +2791,18 @@ dependencies = [
[[package]]
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"
checksum = "77a16b8414fde0414e90c612eba70985577451c4c504b99885ebed24762cb81a"
checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4"
dependencies = [
"zstd-safe",
]
[[package]]
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"
checksum = "7c12659121420dd6365c5c3de4901f97145b79651fb1d25814020ed2ed0585ae"
checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db"
dependencies = [
"libc",
"zstd-sys",

View File

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

View File

@ -22,3 +22,4 @@
12. Don't use json for text storage
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)
15. Add Url hashes loading and setting

View File

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

View File

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