aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src/mission_loading.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 01:04:17 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 01:04:17 +0300
commiteab46d9be33596b6c689a7a34b90837a89400a89 (patch)
tree2afc2ca857882830247349c5db1708137d9772f4 /apps/fparkan-game/src/mission_loading.rs
parent6c9fe794cda795b101825091aee4644efd9422f8 (diff)
downloadfparkan-eab46d9be33596b6c689a7a34b90837a89400a89.tar.xz
fparkan-eab46d9be33596b6c689a7a34b90837a89400a89.zip
feat(ui): show the original mission loading screen
Diffstat (limited to 'apps/fparkan-game/src/mission_loading.rs')
-rw-r--r--apps/fparkan-game/src/mission_loading.rs115
1 files changed, 80 insertions, 35 deletions
diff --git a/apps/fparkan-game/src/mission_loading.rs b/apps/fparkan-game/src/mission_loading.rs
index 37c056dd..41f75c87 100644
--- a/apps/fparkan-game/src/mission_loading.rs
+++ b/apps/fparkan-game/src/mission_loading.rs
@@ -1,71 +1,116 @@
//! Lifecycle of the loader for a windowed mission launch.
+use std::path::Path;
+
+#[cfg(windows)]
+use {
+ fparkan_assets::mission_loader::MissionLoader,
+ fparkan_platform_winit::{
+ startup_window::StartupWindow, text::StringResources, WinitWindowPlan,
+ },
+ fparkan_vfs::DirectoryVfs,
+};
+
#[derive(Clone, Copy)]
pub(super) enum Stage {
- Map = 1,
- Scene,
- Renderer,
+ World,
+ Atmosphere,
+ Objects,
+ Camera,
+ Ready,
}
#[derive(Default)]
pub(super) struct MissionLoading {
#[cfg(windows)]
- window: Option<fparkan_platform_winit::startup_window::StartupWindow>,
- #[cfg(not(windows))]
- active: bool,
+ presentation: Option<Presentation>,
}
-const STAGES: &[&str] = &[
- "Чтение ресурсов миссии",
- "Подготовка карты и материалов",
- "Подготовка сцены и звука",
- "Запуск Vulkan",
-];
+#[cfg(windows)]
+struct Presentation {
+ window: StartupWindow,
+ screen: MissionLoader,
+ strings: StringResources,
+}
impl MissionLoading {
- pub(super) fn start(mission: &str) -> Self {
+ pub(super) fn start(_root: &Path) -> Self {
#[cfg(windows)]
{
- use fparkan_platform_winit::startup_window::StartupWindow;
- let title = mission.parse::<usize>().map_or_else(
- |_| mission.to_owned(),
- |number| format!("FParkan · Миссия {number}"),
- );
- let window = StartupWindow::open(&title, STAGES)
+ let presentation = Presentation::open(_root)
.map_err(|error| eprintln!("startup window: {error}"))
.ok();
- Self { window }
+ Self { presentation }
}
#[cfg(not(windows))]
- {
- eprintln!("{mission} — {}", STAGES[0]);
- Self { active: true }
- }
+ Self::default()
}
- pub(super) fn stage(&self, stage: Stage) {
+ pub(super) fn stage(&mut self, _stage: Stage) {
#[cfg(windows)]
- if let Some(window) = &self.window {
- window.set_stage(stage as usize);
- }
- #[cfg(not(windows))]
- if self.active {
- eprintln!("{}", STAGES[stage as usize]);
+ if let Some(presentation) = &mut self.presentation {
+ if let Err(error) = presentation.update(_stage) {
+ eprintln!("startup window: {error}");
+ }
}
}
pub(super) fn window_visible(&self) -> bool {
#[cfg(windows)]
{
- self.window.is_some()
+ self.presentation.is_some()
}
#[cfg(not(windows))]
- {
- false
- }
+ false
}
pub(super) fn finish(&mut self) {
*self = Self::default();
}
}
+
+#[cfg(windows)]
+impl Presentation {
+ fn open(root: &Path) -> Result<Self, String> {
+ let strings = StringResources::open(&root.join("iron3d.dll"))?;
+ let plan = WinitWindowPlan::smoke();
+ let extent = [plan.width, plan.height];
+ let mut screen = MissionLoader::new(
+ &DirectoryVfs::new(root),
+ extent,
+ &original_text(&strings, 0x13e3)?,
+ )?;
+ screen.append(&original_text(&strings, 0x1194)?)?;
+ let window =
+ StartupWindow::open(extent, screen.frame(10)).map_err(|error| error.to_string())?;
+ Ok(Self {
+ window,
+ screen,
+ strings,
+ })
+ }
+
+ fn update(&mut self, stage: Stage) -> Result<(), String> {
+ // The Rust loader prepares several original stages in one operation.
+ // Publish their messages together when that operation has completed.
+ let (ids, percent): (&[u32], u8) = match stage {
+ Stage::World => (&[0x1198, 0x1199, 0x119a], 45),
+ Stage::Atmosphere => (&[0x119b], 48),
+ Stage::Objects => (&[0x119c, 0x119d, 0x119e, 0x119f, 0x11a0, 0x11a2], 90),
+ Stage::Camera => (&[0x11a3], 95),
+ Stage::Ready => (&[0x11a4], 100),
+ };
+ for &id in ids {
+ self.screen.append(&original_text(&self.strings, id)?)?;
+ }
+ self.window.set_frame(self.screen.frame(percent));
+ Ok(())
+ }
+}
+
+#[cfg(windows)]
+fn original_text(strings: &StringResources, id: u32) -> Result<String, String> {
+ strings
+ .get(id)
+ .ok_or_else(|| format!("missing iron3d.dll string {id:#06x}"))
+}