diff --git a/Cargo.lock b/Cargo.lock index 1caa840..476a17f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1594,6 +1594,16 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" +[[package]] +name = "libmimalloc-sys" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf88cd67e9de251c1781dbe2f641a1a3ad66eaae831b8a2c38fbdc5ddae16d4d" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "libredox" version = "0.1.9" @@ -1702,6 +1712,15 @@ dependencies = [ "paste", ] +[[package]] +name = "mimalloc" +version = "0.1.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1791cbe101e95af5764f06f20f6760521f7158f69dbf9d6baf941ee1bf6bc40" +dependencies = [ + "libmimalloc-sys", +] + [[package]] name = "miniz_oxide" version = "0.8.9" @@ -2649,6 +2668,7 @@ dependencies = [ "color-eyre", "eframe", "fastnbt", + "mimalloc", "rfd", "tracing", "tracing-subscriber", diff --git a/slimeball-gui/Cargo.toml b/slimeball-gui/Cargo.toml index 9ae74ef..b38af10 100644 --- a/slimeball-gui/Cargo.toml +++ b/slimeball-gui/Cargo.toml @@ -7,6 +7,7 @@ edition = "2024" color-eyre = "0.6.5" eframe = { version = "0.32.0", default-features = false, features = ["accesskit", "default_fonts", "wayland", "web_screen_reader", "wgpu", "x11"] } fastnbt = "2.5.0" +mimalloc = "0.1.47" rfd = "0.15.4" tracing = { version = "0.1.41", features = ["release_max_level_info", "max_level_debug"] } tracing-subscriber = { version = "0.3.19", features = ["env-filter"] } diff --git a/slimeball-gui/src/main.rs b/slimeball-gui/src/main.rs index 9d7d3e4..d43a94d 100644 --- a/slimeball-gui/src/main.rs +++ b/slimeball-gui/src/main.rs @@ -1,6 +1,7 @@ use std::path::PathBuf; use eframe::egui::{self, Color32, Frame}; +use mimalloc::MiMalloc; use rfd::FileDialog; use tracing::Level; use tracing_subscriber::{EnvFilter, prelude::*}; @@ -8,6 +9,9 @@ use tracing_subscriber::{EnvFilter, prelude::*}; #[macro_use] extern crate tracing; +#[global_allocator] +static GLOBAL: MiMalloc = MiMalloc; + mod anvil; fn main() { @@ -33,6 +37,15 @@ struct SlimeballGui { file: Option, } +impl eframe::App for SlimeballGui { + fn update(&mut self, ui: &egui::Context, frame: &mut eframe::Frame) { + match self.file { + None => self.show_welcome(ui), + Some(_) => self.show_main(ui), + } + } +} + impl SlimeballGui { fn new(_cc: &eframe::CreationContext<'_>) -> Self { // Customize egui here with cc.egui_ctx.set_fonts and cc.egui_ctx.set_visuals. @@ -41,39 +54,35 @@ impl SlimeballGui { // for e.g. egui::PaintCallback. Self::default() } -} -impl eframe::App for SlimeballGui { - fn update(&mut self, ui: &egui::Context, frame: &mut eframe::Frame) { - match self.file { - None => { - egui::CentralPanel::default().show(ui, |ui| { - ui.vertical_centered(|ui| { - ui.label("No world selected"); - if ui.button("Open a world...").clicked() { - self.file = FileDialog::new().pick_folder(); - } - }); + fn show_welcome(&mut self, ui: &egui::Context) { + egui::CentralPanel::default().show(ui, |ui| { + ui.vertical_centered(|ui| { + ui.label("No world selected"); + if ui.button("Open a world...").clicked() { + self.file = FileDialog::new().pick_folder(); + } + }); + }); + } + + fn show_main(&mut self, ui: &egui::Context) { + // asserted Some in match arm for render + let path = self.file.as_ref().unwrap(); + + egui::TopBottomPanel::top("top_panel") + .resizable(false) + .frame( + Frame::new() + .fill(ui.style().visuals.panel_fill) + .inner_margin(16), + ) + .show(ui, |ui| { + ui.vertical_centered(|ui| { + ui.heading("Settings"); }); - } - Some(ref file) => { - egui::TopBottomPanel::top("top_panel") - .resizable(false) - .frame( - Frame::new() - .fill(ui.style().visuals.panel_fill) - .inner_margin(16), - ) - .show(ui, |ui| { - ui.vertical_centered(|ui| { - ui.heading("Settings"); - }); - }); + }); - egui::CentralPanel::default() - .frame(egui::containers::Frame::NONE.fill(Color32::DARK_GRAY)) - .show(ui, |ui| {}); - } - } + egui::CentralPanel::default().show(ui, |ui| ui.heading(path.to_string_lossy())); } }