aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 21:44:16 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 21:44:16 +0300
commit8d775c601f492e8f1e2ec1a28835f1ab3a37b076 (patch)
treea33e243b4ed36befe08be8940a6b813a58847d2d /apps/fparkan-game/src
parentb48fb2caccc7a72b85f07e6ab652081af57c7855 (diff)
downloadfparkan-8d775c601f492e8f1e2ec1a28835f1ab3a37b076.tar.xz
fparkan-8d775c601f492e8f1e2ec1a28835f1ab3a37b076.zip
feat(ui): show owned buildings on the satellite map
Use the original landscape projection and building sprites. Resolve ownership from live registered objects so a captured building appears at its existing location. Checked the original DLL and verified the factory and storage icons in the stock Field Camp window.
Diffstat (limited to 'apps/fparkan-game/src')
-rw-r--r--apps/fparkan-game/src/main.rs26
-rw-r--r--apps/fparkan-game/src/satellite_map.rs123
2 files changed, 131 insertions, 18 deletions
diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs
index 328aff46..7f6a98f9 100644
--- a/apps/fparkan-game/src/main.rs
+++ b/apps/fparkan-game/src/main.rs
@@ -9593,14 +9593,17 @@ fn run_static_vulkan_mode(
} else {
None
};
- let satellite_map = if mission_engine.is_some() && demo_camera.is_none() {
- satellite_map::SatelliteMap::load(root, mission, &mut preview).unwrap_or_else(|error| {
- eprintln!("satellite_map_unavailable mission={mission} reason={error}");
+ let satellite_map =
+ if let Some(engine) = mission_engine.as_ref().filter(|_| demo_camera.is_none()) {
+ satellite_map::SatelliteMap::load(root, mission, engine, &mut preview).unwrap_or_else(
+ |error| {
+ eprintln!("satellite_map_unavailable mission={mission} reason={error}");
+ None
+ },
+ )
+ } else {
None
- })
- } else {
- None
- };
+ };
let cockpit_geometry = mission_engine
.as_ref()
.map(|engine| cockpit_geometry::CockpitGeometry::prepare(engine, &mut preview))
@@ -11666,8 +11669,13 @@ impl StaticVulkanApp {
let Some(renderer) = self.renderer.as_mut() else {
return Ok(());
};
- if let Some(map) = &self.satellite_map {
- map.draw(renderer, &mut self.mesh, frame.viewport)?;
+ if let Some(map) = &mut self.satellite_map {
+ map.draw(
+ renderer,
+ &mut self.mesh,
+ frame.viewport,
+ self.mission_engine.as_ref().zip(self.cockpit),
+ )?;
}
#[cfg(windows)]
if let Some(hints) = &mut self.mission_hints {
diff --git a/apps/fparkan-game/src/satellite_map.rs b/apps/fparkan-game/src/satellite_map.rs
index 6fbbbcc1..83071a52 100644
--- a/apps/fparkan-game/src/satellite_map.rs
+++ b/apps/fparkan-game/src/satellite_map.rs
@@ -5,6 +5,7 @@ use super::{
VulkanStaticTexture,
};
use fparkan_assets::{satellite_map::load_satellite_map, RgbaImage};
+use fparkan_runtime::{satellite_contacts, Engine, StartingCockpit};
use fparkan_vfs::DirectoryVfs;
use std::{path::Path, sync::Arc};
@@ -12,11 +13,16 @@ const UV: [[f32; 2]; 4] = [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]];
// Native initial background colour, iron3d+0x74cf0.
const MAP_TINT: [f32; 3] = [55.0 / 255.0, 1.0, 55.0 / 255.0];
const MAP_ALPHA: f32 = 128.0 / 255.0;
+const MAP_SIZE: usize = 256;
pub(super) struct SatelliteMap {
background: EnvironmentGpuRange,
compass: EnvironmentGpuRange,
compass_size: [f32; 2],
+ building_layer: EnvironmentGpuRange,
+ icons: RgbaImage,
+ extent: Option<f32>,
+ buildings: Vec<satellite_contacts::BuildingContact>,
visible: bool,
}
@@ -24,6 +30,7 @@ impl SatelliteMap {
pub(super) fn load(
root: &Path,
mission: &str,
+ engine: &Engine,
preview: &mut StaticPreviewScene,
) -> Result<Option<Self>, String> {
let Some(assets) = load_satellite_map(Arc::new(DirectoryVfs::new(root)), mission)? else {
@@ -34,12 +41,20 @@ impl SatelliteMap {
background: add_sprite(preview, assets.background)?,
compass: add_sprite(preview, assets.compass)?,
compass_size,
+ building_layer: add_sprite(preview, empty_layer())?,
+ icons: assets.icons,
+ extent: satellite_contacts::landscape_extent(engine),
+ buildings: Vec::new(),
visible: false,
}))
}
- pub(super) fn ranges(&self) -> [usize; 2] {
- [self.background.range_index, self.compass.range_index]
+ pub(super) fn ranges(&self) -> [usize; 3] {
+ [
+ self.background.range_index,
+ self.compass.range_index,
+ self.building_layer.range_index,
+ ]
}
pub(super) fn toggle(&mut self) {
@@ -47,10 +62,11 @@ impl SatelliteMap {
}
pub(super) fn draw(
- &self,
+ &mut self,
renderer: &mut VulkanSmokeRenderer,
mesh: &mut VulkanStaticMesh,
viewport: [f32; 2],
+ player: Option<(&Engine, StartingCockpit)>,
) -> Result<(), String> {
let count = if self.visible { 6 } else { 0 };
for index in self.ranges() {
@@ -77,6 +93,7 @@ impl SatelliteMap {
);
mesh.vertices[self.background.vertex_start..self.background.vertex_start + 4]
.copy_from_slice(&background);
+ self.draw_buildings(renderer, mesh, viewport, center, size, player)?;
let scale = size / 256.0;
let [width, height] = self.compass_size.map(|dimension| dimension * scale);
@@ -97,6 +114,99 @@ impl SatelliteMap {
.copy_from_slice(&compass);
Ok(())
}
+
+ fn draw_buildings(
+ &mut self,
+ renderer: &mut VulkanSmokeRenderer,
+ mesh: &mut VulkanStaticMesh,
+ viewport: [f32; 2],
+ center: [f32; 2],
+ size: f32,
+ player: Option<(&Engine, StartingCockpit)>,
+ ) -> Result<(), String> {
+ let buildings =
+ player
+ .zip(self.extent)
+ .map_or_else(Vec::new, |((engine, cockpit), extent)| {
+ satellite_contacts::owned_buildings(engine, cockpit, extent).collect()
+ });
+ if buildings != self.buildings {
+ let mut layer = empty_layer();
+ for building in &buildings {
+ paint_building(&self.icons, &mut layer, *building);
+ }
+ renderer
+ .update_material_texture(self.building_layer.material_index, 0, &texture(layer))
+ .map_err(|error| error.to_string())?;
+ self.buildings = buildings;
+ }
+ let vertices = screen_tl_quad_vertices_pixels(
+ center,
+ size * 0.5,
+ size * 0.5,
+ viewport,
+ [1.0; 3],
+ 1.0,
+ UV,
+ );
+ let start = self.building_layer.vertex_start;
+ mesh.vertices[start..start + 4].copy_from_slice(&vertices);
+ Ok(())
+ }
+}
+
+fn empty_layer() -> RgbaImage {
+ RgbaImage {
+ width: MAP_SIZE as u32,
+ height: MAP_SIZE as u32,
+ rgba8: vec![0; MAP_SIZE * MAP_SIZE * 4],
+ }
+}
+
+fn paint_building(
+ atlas: &RgbaImage,
+ layer: &mut RgbaImage,
+ building: satellite_contacts::BuildingContact,
+) {
+ let [left, top] = building.pixel.map(|center| center.saturating_sub(10));
+ // Native 24×24 icon tile at y=24, displayed as a 20×20 square.
+ for dy in 0..20 {
+ let y = top.saturating_add(dy);
+ if !(0..MAP_SIZE as i32).contains(&y) {
+ continue;
+ }
+ for dx in 0..20 {
+ let x = left.saturating_add(dx);
+ if !(0..MAP_SIZE as i32).contains(&x) {
+ continue;
+ }
+ let src_x = building.icon_x as usize + (dx as usize * 24 + 12) / 20;
+ let src_y = 24 + (dy as usize * 24 + 12) / 20;
+ let src = (src_y * atlas.width as usize + src_x) * 4;
+ let dst = (y as usize * MAP_SIZE + x as usize) * 4;
+ let alpha = u32::from(atlas.rgba8[src + 3]);
+ if alpha == 0 {
+ continue;
+ }
+ let retained = u32::from(layer.rgba8[dst + 3]) * (255 - alpha) / 255;
+ let coverage = alpha + retained;
+ for (axis, tint) in [128, 128, 255].into_iter().enumerate() {
+ let source = u32::from(atlas.rgba8[src + axis]) * tint / 255;
+ let under = u32::from(layer.rgba8[dst + axis]);
+ layer.rgba8[dst + axis] = ((source * alpha + under * retained) / coverage) as u8;
+ }
+ layer.rgba8[dst + 3] = coverage as u8;
+ }
+ }
+}
+
+fn texture(image: RgbaImage) -> VulkanStaticTexture {
+ VulkanStaticTexture {
+ width: image.width,
+ height: image.height,
+ rgba8: image.rgba8,
+ mip_levels: Vec::new(),
+ }
}
fn add_sprite(
@@ -106,12 +216,7 @@ fn add_sprite(
let material = append_environment_gradient_material(&mut preview.materials)?;
preview.materials[material].screen_tl = true;
preview.materials[material].sky_far_depth = false;
- preview.materials[material].texture = VulkanStaticTexture {
- width: image.width,
- height: image.height,
- rgba8: image.rgba8,
- mip_levels: Vec::new(),
- };
+ preview.materials[material].texture = texture(image);
append_environment_range(
&mut preview.mesh,
material,