diff options
Diffstat (limited to 'apps/fparkan-game/src/main.rs')
| -rw-r--r-- | apps/fparkan-game/src/main.rs | 100 |
1 files changed, 11 insertions, 89 deletions
diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs index 4b53fdb0..121427ea 100644 --- a/apps/fparkan-game/src/main.rs +++ b/apps/fparkan-game/src/main.rs @@ -24,6 +24,7 @@ mod designer_projects; mod destruction_effects; mod effect_materials; mod factory_menu; +mod frame_rate; mod live_factory_scene; mod model_materials; mod object_render; @@ -9111,15 +9112,12 @@ struct StaticVulkanApp { selected_contact: Option<ObjectHandle>, player_build_pressed: bool, factory_menu: Option<FactoryMenu>, - factory_status: Option<String>, player_service_pressed: bool, player_mine_pressed: bool, player_disembark_pressed: bool, boarded_hero_index: Option<usize>, command_view: Option<strategic_view::ActiveCommandView>, remote_command_view: Option<strategic_view::ActiveCommandView>, - laboratory_status: Option<String>, - mission_title: String, overlay: mission_overlay::MissionOverlay, audio: Option<audio::GameAudio>, camera_mode: &'static str, @@ -9138,6 +9136,7 @@ struct StaticVulkanApp { window: Option<Window>, renderer: Option<VulkanSmokeRenderer>, frames_presented: u64, + frame_rate: frame_rate::FrameRate, output: Option<String>, error: Option<String>, } @@ -9281,15 +9280,12 @@ impl StaticVulkanApp { selected_contact: None, player_build_pressed: false, factory_menu: None, - factory_status: None, player_service_pressed: false, player_mine_pressed: false, player_disembark_pressed: false, boarded_hero_index: None, command_view: None, remote_command_view: None, - laboratory_status: None, - mission_title: String::new(), overlay: mission_overlay::MissionOverlay::default(), audio, camera_mode: preview.camera_mode, @@ -9308,6 +9304,7 @@ impl StaticVulkanApp { window: None, renderer: None, frames_presented: 0, + frame_rate: frame_rate::FrameRate::default(), output: None, error: None, } @@ -9798,70 +9795,6 @@ impl StaticVulkanApp { } } - fn update_mission_title(&mut self) { - let Some(window) = &self.window else { - return; - }; - let outcome = self - .mission_engine - .as_ref() - .and_then(fparkan_runtime::loaded_mission_script_outcome) - .unwrap_or_default(); - use fparkan_runtime::MissionScriptOutcome::{Completed, Failed}; - let title = match (outcome, self.mission_paused) { - (Completed, _) => "Миссия выполнена".into(), - (Failed, _) => "Миссия провалена".into(), - (_, true) => "FParkan mission — Пауза".into(), - _ if self.factory_menu.is_some() => self.factory_menu.as_ref().unwrap().title(), - _ => { - let mut title = "FParkan mission".to_owned(); - if let (Some(engine), Some(cockpit), None) = - (&self.mission_engine, self.cockpit, &self.demo_camera) - { - use std::fmt::Write as _; - let unit = if fparkan_runtime::bunker_control::aim(engine, cockpit).is_some() { - "Бункер" - } else if self.boarded_hero_index.is_some() { - "Варбот" - } else { - "Герой" - }; - let _ = write!(title, " — {unit}"); - if let Some(status) = fparkan_runtime::player_status(engine, cockpit.handle) { - if let Some(health) = status.health_percent { - let _ = write!(title, " · Здоровье {health}%"); - } - if let Some(ore) = status.ore_in_buffer { - let _ = write!(title, " · Руда {ore:.0}"); - } - if let Some((available, demand)) = status.power { - let _ = write!(title, " · Энергия {available:.0}/{demand:.0}"); - } - if let Some((current, maximum)) = status.factory_health { - if current < maximum { - let _ = - write!(title, " · Заводы {:.1}%", 100.0 * current / maximum); - } - } - } - } - if let Some(status) = &self.laboratory_status { - title.push_str(" — "); - title.push_str(status); - } - if let Some(status) = &self.factory_status { - title.push_str(" — "); - title.push_str(status); - } - title - } - }; - if self.mission_title != title { - window.set_title(&title); - self.mission_title = title; - } - } - fn update_shadow( mesh: &mut VulkanStaticMesh, shadow_cache: &mut ShadowPageCache, @@ -10057,11 +9990,7 @@ impl StaticVulkanApp { }) .collect::<Vec<_>>(); match choices.len() { - 0 => { - self.factory_status = - Some("Завод — нет подходящих схем".into()); - None - } + 0 => None, 1 if !remote && !self.overlay.factory_projects.as_ref().is_some_and( factory_menu::FactoryProjectPanel::designer_available, @@ -10101,11 +10030,9 @@ impl StaticVulkanApp { ); match order { Ok(duration) => { - self.factory_status = Some(format!("Завод — собирается {name}")); eprintln!("factory_order scheme={name} remote={} minimum_ms={duration} queue_time_ms={control_clock_ms}", factory.is_some()); } Err(error) => { - self.factory_status = Some("Завод — заказ отклонён".into()); eprintln!("factory_order_rejected {error}"); } } @@ -10225,17 +10152,9 @@ impl StaticVulkanApp { ); } if let Some(error) = &frame.production_failure { - self.factory_status = Some("Завод — сборка прервана".into()); eprintln!("sim_coverage factory_spawn_failed=1 reason={error}"); } - if frame - .produced_unit - .is_some_and(|unit| fparkan_runtime::is_player_clan(engine, unit.clan)) - { - self.factory_status = Some("Завод — робот готов".into()); - } if let Some(component) = &frame.researched_component { - self.laboratory_status = Some(format!("Лаборатория — разработано {component}")); eprintln!("laboratory_research_complete component={component} queue_time_ms={control_clock_ms}"); } if frame.autodemo_reinforcement_unavailable != 0 { @@ -10292,9 +10211,6 @@ impl StaticVulkanApp { self.window_focused && !self.mission_paused && self.cockpit.is_some(), ); } - if self.mission_engine.is_some() { - self.update_mission_title(); - } if let Some(frame) = &self.mission_frame { let objects = &frame.snapshot.transforms; for (index, root) in self.mission_render_roots.iter().enumerate() { @@ -11412,7 +11328,7 @@ impl ApplicationHandler for StaticVulkanApp { .map(|viewport| (viewport.extent[0], viewport.extent[1])) .unwrap_or((plan.width, plan.height)); let attributes = Window::default_attributes() - .with_title("FParkan mission") + .with_title("FParkan") .with_visible(!startup_window_visible) .with_inner_size(WinitPhysicalSize::new(width, height)) // The captured clip matrix is exact for the recorded viewport @@ -11814,6 +11730,12 @@ impl ApplicationHandler for StaticVulkanApp { match outcome { Ok(VulkanSmokeFrameOutcome::Presented) => { let frame_index = self.record_presented_scene_frame(); + if let Some((window, fps)) = self.window.as_ref().zip( + self.frame_rate + .presented(Instant::now(), self.frames_presented), + ) { + window.set_title(&format!("FParkan — {fps} FPS")); + } if frame_index == 0 { self.loading.finish(); } |
