Skip to content

Commit

Permalink
keep project manager active during build process, but with reduced rate
Browse files Browse the repository at this point in the history
- saves CPU time for useful work, but still updates UI during the build indicating that the build is not stuck
  • Loading branch information
mrDIMAS committed Dec 28, 2024
1 parent 7dee419 commit 012633a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
17 changes: 14 additions & 3 deletions project-manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use fyrox::{
asset::{manager::ResourceManager, untyped::ResourceKind},
core::{
algebra::Matrix3,
instant::Instant,
log::{Log, MessageKind},
task::TaskPool,
},
Expand All @@ -52,7 +51,10 @@ use fyrox::{
utils::{translate_cursor_icon, translate_event},
window::WindowAttributes,
};
use std::sync::Arc;
use std::{
sync::Arc,
time::{Duration, Instant},
};

fn set_ui_scaling(ui: &UserInterface, scale: f32) {
// High-DPI screen support
Expand Down Expand Up @@ -108,7 +110,16 @@ fn main() {

event_loop
.run(move |event, window_target| {
window_target.set_control_flow(ControlFlow::Wait);
if project_manager.mode.is_build() {
// Keep updating with reduced rate to keep printing to the build log, but do not
// eat as much time as in normal update mode.
window_target.set_control_flow(ControlFlow::wait_duration(
Duration::from_secs_f32(1.0 / 10.0),
));
} else {
// Wait for an event.
window_target.set_control_flow(ControlFlow::Wait);
}

match event {
Event::Resumed => {
Expand Down
14 changes: 11 additions & 3 deletions project-manager/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ use std::{
process::Stdio,
};

enum Mode {
pub enum Mode {
Normal,
Build {
queue: VecDeque<CommandDescriptor>,
Expand All @@ -72,6 +72,12 @@ enum Mode {
},
}

impl Mode {
pub fn is_build(&self) -> bool {
matches!(self, Mode::Build { .. })
}
}

pub struct UpdateLoopState(u32);

impl Default for UpdateLoopState {
Expand Down Expand Up @@ -124,7 +130,7 @@ pub struct ProjectManager {
project_wizard: Option<ProjectWizard>,
build_window: Option<BuildWindow>,
import_project_dialog: Handle<UiNode>,
mode: Mode,
pub mode: Mode,
search_text: String,
log: LogPanel,
open_log: Handle<UiNode>,
Expand Down Expand Up @@ -672,7 +678,9 @@ impl ProjectManager {
}

pub fn is_active(&self, ui: &UserInterface) -> bool {
!self.update_loop_state.is_suspended() && self.focused || ui.captured_node().is_some()
!self.update_loop_state.is_suspended() && self.focused
|| ui.captured_node().is_some()
|| self.mode.is_build()
}

fn refresh(&mut self, ui: &mut UserInterface) {
Expand Down

0 comments on commit 012633a

Please sign in to comment.