Skip to content

Commit

Permalink
Reduce CPU usage while playing
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrGlad committed Nov 10, 2023
1 parent c7d8535 commit fd37656
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fs;
use std::path::PathBuf;
use std::sync::mpsc;
use std::time::Duration;

use crate::common::Time;
use eframe::egui::{Modifiers, Vec2};
Expand Down Expand Up @@ -48,12 +49,12 @@ impl EmApp {

let engine_receiver_ctx = ctx.egui_ctx.clone();
let engine_status_receiver = Box::new(move |ev| {
// TODO (optimization?) Throttle updates (30..60 times per second should be enough).
// Should not miss one-off updates, maybe skip only in same-event-type runs.
match ev {
StatusEvent::Time(t) => {
match message_sender.send(Message::UpdateTime(t)) {
Ok(_) => engine_receiver_ctx.request_repaint(),
Ok(_) => {
engine_receiver_ctx.request_repaint_after(Duration::from_micros(15_000))
}
_ => (), // Will try next time.
}
}
Expand Down

0 comments on commit fd37656

Please sign in to comment.