Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions crates/mako/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
use std::sync::Arc;

use mako::compiler::{self, Args};
#[cfg(not(feature = "profile"))]
use mako::dev;
use mako::utils::logger::init_logger;
#[cfg(feature = "profile")]
use mako::utils::profile_gui::ProfileApp;
use mako::utils::tokio_runtime;
use mako::{cli, config, dev};
use mako::{cli, config};
use mako_core::anyhow::{anyhow, Result};
use mako_core::clap::Parser;
#[cfg(feature = "profile")]
use mako_core::tokio::sync::Notify;
use mako_core::tracing::debug;

#[cfg(not(target_os = "linux"))]
Expand Down Expand Up @@ -77,28 +77,13 @@ async fn run() -> Result<()> {

#[cfg(feature = "profile")]
{
let notify = Arc::new(Notify::new());
let to_be_notify = notify.clone();

tokio_runtime::spawn(async move {
let compiler = compiler.clone();

to_be_notify.notified().await;

compiler.compile().unwrap();

if cli.watch {
let d = crate::dev::DevServer::new(root.clone(), compiler.clone());
d.serve(move |_params| {}).await;
}
});

mako_core::puffin::set_scopes_on(true);
let native_options = Default::default();
let for_profile = compiler.clone();
let _ = mako_core::eframe::run_native(
"puffin egui eframe",
native_options,
Box::new(move |_cc| Box::new(ProfileApp::new(notify))),
Box::new(move |_cc| Box::new(ProfileApp::new(for_profile))),
);
}

Expand Down
1 change: 1 addition & 0 deletions crates/mako/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod logger;
#[cfg(feature = "profile")]
pub mod profile_gui;
#[cfg(test)]
pub(crate) mod test_helper;
Expand Down
36 changes: 20 additions & 16 deletions crates/mako/src/utils/profile_gui.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
#[cfg(feature = "profile")]
use std::sync::Arc;

#[cfg(feature = "profile")]
use mako_core::eframe::egui;
#[cfg(feature = "profile")]
use mako_core::tokio::sync::Notify;

#[cfg(feature = "profile")]
use crate::compiler::Compiler;
use crate::utils::tokio_runtime;

pub struct ProfileApp {
notified: bool,
notify: Arc<Notify>,
inited: bool,
compiler: Arc<Compiler>,
}

#[cfg(feature = "profile")]
impl ProfileApp {
#[allow(dead_code)]
pub fn new(notify: Arc<Notify>) -> Self {
pub fn new(compiler: Arc<Compiler>) -> Self {
Self {
notified: false,
notify,
inited: false,
compiler,
}
}
}

#[cfg(feature = "profile")]
impl mako_core::eframe::App for ProfileApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut mako_core::eframe::Frame) {
mako_core::puffin::GlobalProfiler::lock().new_frame(); // call once per frame!

if !self.notified {
self.notified = true;
self.notify.notify_one();
if !self.inited {
self.compiler.compile().unwrap();

if self.compiler.context.args.watch {
let for_spawn = self.compiler.clone();
tokio_runtime::spawn(async move {
let root = for_spawn.context.root.clone();
let d = crate::dev::DevServer::new(root, for_spawn);
d.serve(move |_params| {}).await;
});
}
self.inited = true;
}
mako_core::puffin_egui::profiler_window(ctx);
}
Expand Down