From ce7303cccab081833318aac5f74263061c1439dd Mon Sep 17 00:00:00 2001 From: Robin Candau Date: Mon, 9 Nov 2026 17:13:16 +0100 Subject: [PATCH] fix(compile): Show status before compiling Refactor the way to get and show compilation parameters and show the complete status before compiling so you don't need to interrupt compilation to consult the status of resources --- src/command.rs | 11 ++++++++++- src/compile.rs | 20 ++++++++++++-------- src/parameters.rs | 13 ++----------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/command.rs b/src/command.rs index 3f7ec27..ca93006 100644 --- a/src/command.rs +++ b/src/command.rs @@ -74,9 +74,18 @@ pub fn status(game_state: &GameState) { } ); println!(); + // Get compilation parameters + let (compile_time, credit_reward, failure_probability) = + parameters::get_compilation_parameters(game_state); println!("[COMPILATION]"); println!(); - parameters::show_compilation_parameters(game_state); + println!( + "Compile time {:02}:{:02}", + (compile_time / 60.0) as u64, + compile_time as u64 % 60 + ); + println!("Credit reward {credit_reward:.2}"); + println!("Failure probability {:.1}%", failure_probability * 100.0); } pub fn guide() { diff --git a/src/compile.rs b/src/compile.rs index 283a14a..2b7ce38 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -10,6 +10,7 @@ use std::thread; use std::time::{Duration, Instant}; use which::which; +use crate::command; use crate::parameters; use crate::statefile::{self, GameState}; use crate::upgrade; @@ -18,6 +19,17 @@ pub fn compile_process( game_state: &mut GameState, interrupt_rx: &Receiver<()>, ) -> anyhow::Result { + // Run auto-scaling if enabled + upgrade::auto_scale(game_state)?; + + // Get compilation parameters + let (compile_time, credit_reward, failure_probability) = + parameters::get_compilation_parameters(game_state); + + // Show status (to see the current numbers of resources and compilation parameters) + command::status(game_state); + println!(); + // Silly messages println!( "{} Synchronizing imaginary dependencies...", @@ -36,14 +48,6 @@ pub fn compile_process( println!(); - // Run auto-scaling if enabled - upgrade::auto_scale(game_state)?; - - // Get and show compilation parameters - let (compile_time, credit_reward, failure_probability) = - parameters::show_compilation_parameters(game_state); - println!(); - // Convert compile time to a Duration (used later to determine when the compilation is over) let compile_time = Duration::from_secs_f64(compile_time); diff --git a/src/parameters.rs b/src/parameters.rs index 4472f69..b817566 100644 --- a/src/parameters.rs +++ b/src/parameters.rs @@ -49,23 +49,14 @@ pub fn failure_probability(cpu: u64, disk: u64) -> f64 { probability.clamp(MIN_COMPILATION_FAILURE_PROB, MAX_COMPILATION_FAILURE_PROB) } -// Helper to retrieve and show the different compilation parameters: +// Helper to retrieve the different compilation parameters: // compile time, credit reward and failure percentage -pub fn show_compilation_parameters(game_state: &GameState) -> (f64, f64, f64) { +pub fn get_compilation_parameters(game_state: &GameState) -> (f64, f64, f64) { // Calculate values let compile_time = compile_time(game_state.cpu, game_state.ram); let credit_reward = credit_reward(game_state.ram, game_state.disk); let failure_probability = failure_probability(game_state.cpu, game_state.disk); - // Show values - println!( - "Compile time {:02}:{:02}", - (compile_time / 60.0) as u64, - compile_time as u64 % 60 - ); - println!("Credit reward {credit_reward:.2}"); - println!("Failure probability {:.1}%", failure_probability * 100.0); - // Return values (compile_time, credit_reward, failure_probability) }