Skip to content

Commit

Permalink
chore: clean up dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
lukexor committed Jun 16, 2024
1 parent 0bc5231 commit 254fe54
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 39 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions tetanes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ anyhow.workspace = true
bincode.workspace = true
bytemuck = "1.15"
cfg-if.workspace = true
clap.workspace = true
crossbeam = "0.8"
# TODO: Remove once https://github.com/emilk/egui/pull/4372 is released
color-hex = "0.2"
Expand All @@ -56,29 +55,32 @@ gilrs = { version = "0.10", features = ["serde-serialize"] }
hound = "3.5"
image.workspace = true
parking_lot = "0.12"
puffin_egui = { version = "0.27", optional = true }
rfd = "0.14"
ringbuf = "0.4"
serde.workspace = true
serde_json.workspace = true
sysinfo = "0.30"
tetanes-core = { version = "0.11", path = "../tetanes-core" }
thingbuf = "0.1"
thiserror.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
tracing-appender = "0.2"
uuid = { version = "1.8", features = ["v4", "fast-rng", "serde"] }
# Only here to define features for egui-winit "links" feature, hence the "*"
webbrowser = { version = "*", features = ["hardened", "disable-wsl"] }
winit = { version = "0.29", features = ["serde"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
clap.workspace = true
cpal = "0.15"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
egui-winit = "0.27"
pollster = "0.3"
puffin = { workspace = true, optional = true }
puffin_egui = { version = "0.27", optional = true }
reqwest = { version = "0.12", features = ["blocking"] }
rfd = "0.14"
semver = "1"
sysinfo = "0.30"
tracing-appender = "0.2"
wgpu = "0.19"

[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
78 changes: 44 additions & 34 deletions tetanes/src/nes/renderer/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use std::{
collections::BTreeMap,
ops::{Deref, DerefMut},
};
use sysinfo::{Pid, ProcessRefreshKind, RefreshKind, System};
use tetanes_core::{
action::Action as DeckAction,
apu::Channel,
Expand Down Expand Up @@ -169,7 +168,9 @@ pub struct Gui {
pub loaded_rom: Option<LoadedRom>,
pub about_homebrew_rom_open: Option<RomAsset>,
pub start: Instant,
pub sys: Option<System>,
#[cfg(not(target_arch = "wasm32"))]
pub sys: Option<sysinfo::System>,
#[cfg(not(target_arch = "wasm32"))]
pub sys_updated: Instant,
pub error: Option<String>,
}
Expand All @@ -190,26 +191,31 @@ impl Gui {

/// Create a `Gui` instance.
pub fn new(tx: EventLoopProxy<NesEvent>, texture: SizedTexture, cfg: &Config) -> Self {
let sys = if sysinfo::IS_SUPPORTED_SYSTEM {
let mut sys = System::new_with_specifics(
RefreshKind::new().with_processes(
ProcessRefreshKind::new()
.with_cpu()
.with_memory()
.with_disk_usage(),
),
);
sys.refresh_specifics(
RefreshKind::new().with_processes(
ProcessRefreshKind::new()
.with_cpu()
.with_memory()
.with_disk_usage(),
),
);
Some(sys)
} else {
None
#[cfg(not(target_arch = "wasm32"))]
let sys = {
use sysinfo::{ProcessRefreshKind, RefreshKind, System};

if sysinfo::IS_SUPPORTED_SYSTEM {
let mut sys = System::new_with_specifics(
RefreshKind::new().with_processes(
ProcessRefreshKind::new()
.with_cpu()
.with_memory()
.with_disk_usage(),
),
);
sys.refresh_specifics(
RefreshKind::new().with_processes(
ProcessRefreshKind::new()
.with_cpu()
.with_memory()
.with_disk_usage(),
),
);
Some(sys)
} else {
None
}
};

Self {
Expand Down Expand Up @@ -247,7 +253,9 @@ impl Gui {
loaded_rom: None,
about_homebrew_rom_open: None,
start: Instant::now(),
#[cfg(not(target_arch = "wasm32"))]
sys,
#[cfg(not(target_arch = "wasm32"))]
sys_updated: Instant::now(),
error: None,
}
Expand Down Expand Up @@ -1730,15 +1738,16 @@ impl Gui {
grid.show(ui, |ui| {
ui.ctx().request_repaint_after(Duration::from_secs(1));

#[cfg(not(target_arch = "wasm32"))]
if let Some(sys) = &mut self.sys {
// NOTE: refreshing sysinfo is cpu-intensive if done too frequently and skews the
// results
let sys_update_interval = Duration::from_secs(1);
assert!(sys_update_interval > sysinfo::MINIMUM_CPU_UPDATE_INTERVAL);
if self.sys_updated.elapsed() >= sys_update_interval {
sys.refresh_specifics(
RefreshKind::new().with_processes(
ProcessRefreshKind::new()
sysinfo::RefreshKind::new().with_processes(
sysinfo::ProcessRefreshKind::new()
.with_cpu()
.with_memory()
.with_disk_usage(),
Expand All @@ -1765,11 +1774,6 @@ impl Gui {
time if time <= 1000.0 * 1.0 / 30.0 => warn_color,
_ => bad_color,
};
let cpu_color = |cpu| match cpu {
cpu if cpu <= 25.0 => good_color,
cpu if cpu <= 50.0 => warn_color,
_ => bad_color,
};

let fps = self.frame_stats.fps;
ui.strong("FPS:");
Expand Down Expand Up @@ -1814,11 +1818,21 @@ impl Gui {
ui.label(format!("{}", self.frame_stats.frame_count));
ui.end_row();

#[cfg(not(target_arch = "wasm32"))]
if let Some(ref sys) = self.sys {
let cpu_color = |cpu| match cpu {
cpu if cpu <= 25.0 => good_color,
cpu if cpu <= 50.0 => warn_color,
_ => bad_color,
};
const fn bytes_to_mb(bytes: u64) -> u64 {
bytes / 0x100000
}

ui.label("");
ui.end_row();

match sys.process(Pid::from_u32(std::process::id())) {
match sys.process(sysinfo::Pid::from_u32(std::process::id())) {
Some(proc) => {
ui.strong("CPU:");
let cpu_usage = proc.cpu_usage();
Expand Down Expand Up @@ -3108,10 +3122,6 @@ impl Gui {
}
}

const fn bytes_to_mb(bytes: u64) -> u64 {
bytes / 0x100000
}

fn cursor_to_zapper(x: f32, y: f32, rect: Rect) -> Option<Pos2> {
let width = Ppu::WIDTH as f32;
let height = Ppu::HEIGHT as f32;
Expand Down

0 comments on commit 254fe54

Please sign in to comment.