changes in serialization of data
This commit is contained in:
parent
e6bee04113
commit
a9a870ec2f
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@
|
|||||||
/tmp
|
/tmp
|
||||||
/assets.tar.zst
|
/assets.tar.zst
|
||||||
/Cargo.lock
|
/Cargo.lock
|
||||||
|
/assets/font_data
|
||||||
|
|||||||
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -41,6 +41,7 @@ checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom",
|
"getrandom",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
"serde",
|
||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -152,6 +153,15 @@ dependencies = [
|
|||||||
"pprof",
|
"pprof",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bincode"
|
||||||
|
version = "1.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "1.3.2"
|
||||||
@ -730,6 +740,7 @@ version = "0.18.0"
|
|||||||
source = "git+https://github.com/Titaniumtown/egui.git#e9ed0e4b3ad7ca6e887edb013437077ea398d568"
|
source = "git+https://github.com/Titaniumtown/egui.git#e9ed0e4b3ad7ca6e887edb013437077ea398d568"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -744,6 +755,7 @@ dependencies = [
|
|||||||
"emath",
|
"emath",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
"parking_lot 0.12.0",
|
"parking_lot 0.12.0",
|
||||||
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1981,6 +1993,9 @@ name = "serde"
|
|||||||
version = "1.0.137"
|
version = "1.0.137"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1"
|
checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1"
|
||||||
|
dependencies = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_cbor"
|
name = "serde_cbor"
|
||||||
@ -2798,6 +2813,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"async-lock",
|
"async-lock",
|
||||||
"benchmarks",
|
"benchmarks",
|
||||||
|
"bincode",
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"command-run",
|
"command-run",
|
||||||
"console_error_panic_hook",
|
"console_error_panic_hook",
|
||||||
|
|||||||
10
Cargo.toml
10
Cargo.toml
@ -38,7 +38,9 @@ strip = false
|
|||||||
parsing = { path = "./parsing" }
|
parsing = { path = "./parsing" }
|
||||||
eframe = { git = "https://github.com/Titaniumtown/egui.git", default-features = false }
|
eframe = { git = "https://github.com/Titaniumtown/egui.git", default-features = false }
|
||||||
egui = { git = "https://github.com/Titaniumtown/egui.git", default-features = false }
|
egui = { git = "https://github.com/Titaniumtown/egui.git", default-features = false }
|
||||||
epaint = { git = "https://github.com/Titaniumtown/egui.git", default-features = false }
|
epaint = { git = "https://github.com/Titaniumtown/egui.git", default-features = false, features = [
|
||||||
|
"serde",
|
||||||
|
] }
|
||||||
emath = { git = "https://github.com/Titaniumtown/egui.git", default-features = false }
|
emath = { git = "https://github.com/Titaniumtown/egui.git", default-features = false }
|
||||||
|
|
||||||
shadow-rs = { version = "0.11", default-features = false }
|
shadow-rs = { version = "0.11", default-features = false }
|
||||||
@ -52,6 +54,8 @@ tracing = "0.1"
|
|||||||
itertools = "0.10"
|
itertools = "0.10"
|
||||||
static_assertions = "1.1"
|
static_assertions = "1.1"
|
||||||
uuid = { version = "1", features = ["v4", "fast-rng", "js"] }
|
uuid = { version = "1", features = ["v4", "fast-rng", "js"] }
|
||||||
|
bincode = "1.3.3"
|
||||||
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
benchmarks = { path = "./benchmarks" }
|
benchmarks = { path = "./benchmarks" }
|
||||||
@ -59,6 +63,10 @@ benchmarks = { path = "./benchmarks" }
|
|||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
shadow-rs = "0.11"
|
shadow-rs = "0.11"
|
||||||
command-run = "1.1"
|
command-run = "1.1"
|
||||||
|
epaint = { git = "https://github.com/Titaniumtown/egui.git", default-features = false, features = [
|
||||||
|
"serde",
|
||||||
|
] }
|
||||||
|
bincode = "1.3.3"
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
instant = "0.1"
|
instant = "0.1"
|
||||||
|
|||||||
59
build.rs
59
build.rs
@ -1,11 +1,64 @@
|
|||||||
|
use std::{
|
||||||
|
collections::BTreeMap,
|
||||||
|
fs::File,
|
||||||
|
io::{BufWriter, Write},
|
||||||
|
};
|
||||||
|
|
||||||
|
use epaint::{
|
||||||
|
text::{FontData, FontDefinitions},
|
||||||
|
FontFamily,
|
||||||
|
};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// rebuild if new commit or contents of `assets` folder changed
|
// rebuild if new commit or contents of `assets` folder changed
|
||||||
println!("cargo:rerun-if-changed=.git/logs/HEAD");
|
println!("cargo:rerun-if-changed=.git/logs/HEAD");
|
||||||
println!("cargo:rerun-if-changed=assets/*");
|
println!("cargo:rerun-if-changed=assets/*");
|
||||||
|
|
||||||
let _ = command_run::Command::with_args("./pack_assets.sh", &[""])
|
shadow_rs::new().expect("Could not initialize shadow_rs");
|
||||||
|
|
||||||
|
let font_hack = FontData::from_static(include_bytes!("assets/Hack-Regular.ttf"));
|
||||||
|
let font_ubuntu_light = FontData::from_static(include_bytes!("assets/Ubuntu-Light.ttf"));
|
||||||
|
let font_notoemoji = FontData::from_static(include_bytes!("assets/NotoEmoji-Regular.ttf"));
|
||||||
|
let font_emoji_icon = FontData::from_static(include_bytes!("assets/emoji-icon-font.ttf"));
|
||||||
|
|
||||||
|
let fonts = FontDefinitions {
|
||||||
|
font_data: BTreeMap::from([
|
||||||
|
("Hack".to_owned(), font_hack),
|
||||||
|
("Ubuntu-Light".to_owned(), font_ubuntu_light),
|
||||||
|
("NotoEmoji-Regular".to_owned(), font_notoemoji),
|
||||||
|
("emoji-icon-font".to_owned(), font_emoji_icon),
|
||||||
|
]),
|
||||||
|
families: BTreeMap::from([
|
||||||
|
(
|
||||||
|
FontFamily::Monospace,
|
||||||
|
vec![
|
||||||
|
"Hack".to_owned(),
|
||||||
|
"Ubuntu-Light".to_owned(),
|
||||||
|
"NotoEmoji-Regular".to_owned(),
|
||||||
|
"emoji-icon-font".to_owned(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
FontFamily::Proportional,
|
||||||
|
vec![
|
||||||
|
"Ubuntu-Light".to_owned(),
|
||||||
|
"NotoEmoji-Regular".to_owned(),
|
||||||
|
"emoji-icon-font".to_owned(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
};
|
||||||
|
|
||||||
|
let path = "./assets/font_data";
|
||||||
|
|
||||||
|
let fonts_data = bincode::serialize(&fonts).unwrap();
|
||||||
|
// ::to_string(&fonts).expect("Failed to serialize fonts");
|
||||||
|
|
||||||
|
let mut file = BufWriter::new(File::create(&path).expect("Could not create file"));
|
||||||
|
|
||||||
|
file.write_all(fonts_data.as_slice()).unwrap();
|
||||||
|
|
||||||
|
let _ = command_run::Command::with_args("./pack_assets.sh", &[&path])
|
||||||
.enable_capture()
|
.enable_capture()
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
shadow_rs::new().expect("Could not initialize shadow_rs");
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
rm -fr assets.tar.zst | true
|
rm -fr assets.tar.zst | true
|
||||||
cd assets
|
tar -I 'zstd --ultra -22' --strip-components=9999 -cf ./assets.tar.zst assets/text.json $1
|
||||||
tar -I 'zstd --ultra -22' -cf ../assets.tar.zst *.*
|
|
||||||
|
|||||||
@ -3,16 +3,14 @@ use crate::function_entry::Riemann;
|
|||||||
use crate::function_manager::FunctionManager;
|
use crate::function_manager::FunctionManager;
|
||||||
use crate::misc::{dyn_mut_iter, option_vec_printer, TextData};
|
use crate::misc::{dyn_mut_iter, option_vec_printer, TextData};
|
||||||
use eframe::App;
|
use eframe::App;
|
||||||
use egui::FontTweak;
|
|
||||||
use egui::{
|
use egui::{
|
||||||
plot::Plot, style::Margin, vec2, Button, CentralPanel, Color32, ComboBox, Context, FontData,
|
plot::Plot, style::Margin, vec2, Button, CentralPanel, Color32, ComboBox, Context,
|
||||||
FontDefinitions, FontFamily, Frame, Key, Label, Layout, RichText, SidePanel, Slider,
|
FontDefinitions, Frame, Key, Label, Layout, RichText, SidePanel, Slider, TopBottomPanel, Vec2,
|
||||||
TopBottomPanel, Vec2, Visuals, Window,
|
Visuals, Window,
|
||||||
};
|
};
|
||||||
use emath::{Align, Align2};
|
use emath::{Align, Align2};
|
||||||
use epaint::Rounding;
|
use epaint::Rounding;
|
||||||
use instant::Duration;
|
use instant::Duration;
|
||||||
use std::collections::BTreeMap;
|
|
||||||
use std::{io::Read, ops::BitXorAssign, str};
|
use std::{io::Read, ops::BitXorAssign, str};
|
||||||
|
|
||||||
#[cfg(threading)]
|
#[cfg(threading)]
|
||||||
@ -156,10 +154,7 @@ impl MathApp {
|
|||||||
update_loading(&loading_element, 30);
|
update_loading(&loading_element, 30);
|
||||||
|
|
||||||
// Stores fonts
|
// Stores fonts
|
||||||
let mut font_ubuntu_light: Option<FontData> = None;
|
let mut font_data: Option<FontDefinitions> = None;
|
||||||
let mut font_notoemoji: Option<FontData> = None;
|
|
||||||
let mut font_hack: Option<FontData> = None;
|
|
||||||
let mut font_emoji_icon: Option<FontData> = None;
|
|
||||||
|
|
||||||
// Stores text
|
// Stores text
|
||||||
let mut text_data: Option<TextData> = None;
|
let mut text_data: Option<TextData> = None;
|
||||||
@ -179,43 +174,9 @@ impl MathApp {
|
|||||||
let path_string = path.to_string_lossy();
|
let path_string = path.to_string_lossy();
|
||||||
|
|
||||||
// Match the file extention
|
// Match the file extention
|
||||||
if path_string.ends_with(".ttf") {
|
if path_string.ends_with("font_data") {
|
||||||
// Parse font files
|
font_data = Some(bincode::deserialize(&data).unwrap());
|
||||||
let font_data = FontData::from_owned(data);
|
} else if path_string.ends_with("text.json") {
|
||||||
match path_string.as_ref() {
|
|
||||||
"Hack-Regular.ttf" => {
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
update_loading(&loading_element, 10);
|
|
||||||
|
|
||||||
font_hack = Some(font_data);
|
|
||||||
}
|
|
||||||
"NotoEmoji-Regular.ttf" => {
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
update_loading(&loading_element, 10);
|
|
||||||
|
|
||||||
font_notoemoji = Some(font_data);
|
|
||||||
}
|
|
||||||
"Ubuntu-Light.ttf" => {
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
update_loading(&loading_element, 10);
|
|
||||||
|
|
||||||
font_ubuntu_light = Some(font_data);
|
|
||||||
}
|
|
||||||
"emoji-icon-font.ttf" => {
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
update_loading(&loading_element, 10);
|
|
||||||
|
|
||||||
font_emoji_icon = Some(font_data.tweak(FontTweak {
|
|
||||||
scale: 0.8, // make it smaller
|
|
||||||
y_offset_factor: 0.07, // move it down slightly
|
|
||||||
y_offset: 0.0,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
panic!("Font File {} not expected!", path_string);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if path_string == "text.json" {
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
update_loading(&loading_element, 10);
|
update_loading(&loading_element, 10);
|
||||||
text_data = Some(TextData::from_json_str(unsafe {
|
text_data = Some(TextData::from_json_str(unsafe {
|
||||||
@ -226,49 +187,10 @@ impl MathApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let fonts = FontDefinitions {
|
|
||||||
font_data: BTreeMap::from([
|
|
||||||
(
|
|
||||||
"Hack".to_owned(),
|
|
||||||
font_hack.expect("Hack-Regular.ttf not found!"),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"Ubuntu-Light".to_owned(),
|
|
||||||
font_ubuntu_light.expect("Ubuntu-Light.ttf not found!"),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"NotoEmoji-Regular".to_owned(),
|
|
||||||
font_notoemoji.expect("NotoEmoji-Regular.ttf not found!"),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"emoji-icon-font".to_owned(),
|
|
||||||
font_emoji_icon.expect("emoji-icon-font.ttf not found!"),
|
|
||||||
),
|
|
||||||
]),
|
|
||||||
families: BTreeMap::from([
|
|
||||||
(
|
|
||||||
FontFamily::Monospace,
|
|
||||||
vec![
|
|
||||||
"Hack".to_owned(),
|
|
||||||
"Ubuntu-Light".to_owned(),
|
|
||||||
"NotoEmoji-Regular".to_owned(),
|
|
||||||
"emoji-icon-font".to_owned(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
(
|
|
||||||
FontFamily::Proportional,
|
|
||||||
vec![
|
|
||||||
"Ubuntu-Light".to_owned(),
|
|
||||||
"NotoEmoji-Regular".to_owned(),
|
|
||||||
"emoji-icon-font".to_owned(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Initialize fonts
|
// Initialize fonts
|
||||||
// This used to be in the `update` method, but (after a ton of digging) this actually caused OOMs. that was a pain to debug
|
// This used to be in the `update` method, but (after a ton of digging) this actually caused OOMs. that was a pain to debug
|
||||||
cc.egui_ctx.set_fonts(fonts);
|
cc.egui_ctx
|
||||||
|
.set_fonts(font_data.expect("Failed to load font_data"));
|
||||||
|
|
||||||
// Set dark mode by default
|
// Set dark mode by default
|
||||||
cc.egui_ctx.set_visuals(Visuals::dark());
|
cc.egui_ctx.set_visuals(Visuals::dark());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user