aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src
diff options
context:
space:
mode:
Diffstat (limited to 'apps/fparkan-game/src')
-rw-r--r--apps/fparkan-game/src/satellite_map.rs55
1 files changed, 41 insertions, 14 deletions
diff --git a/apps/fparkan-game/src/satellite_map.rs b/apps/fparkan-game/src/satellite_map.rs
index 83071a52..f5dabd6f 100644
--- a/apps/fparkan-game/src/satellite_map.rs
+++ b/apps/fparkan-game/src/satellite_map.rs
@@ -19,10 +19,11 @@ pub(super) struct SatelliteMap {
background: EnvironmentGpuRange,
compass: EnvironmentGpuRange,
compass_size: [f32; 2],
- building_layer: EnvironmentGpuRange,
+ contact_layer: EnvironmentGpuRange,
icons: RgbaImage,
extent: Option<f32>,
buildings: Vec<satellite_contacts::BuildingContact>,
+ units: Vec<satellite_contacts::UnitContact>,
visible: bool,
}
@@ -41,10 +42,11 @@ impl SatelliteMap {
background: add_sprite(preview, assets.background)?,
compass: add_sprite(preview, assets.compass)?,
compass_size,
- building_layer: add_sprite(preview, empty_layer())?,
+ contact_layer: add_sprite(preview, empty_layer())?,
icons: assets.icons,
extent: satellite_contacts::landscape_extent(engine),
buildings: Vec::new(),
+ units: Vec::new(),
visible: false,
}))
}
@@ -53,7 +55,7 @@ impl SatelliteMap {
[
self.background.range_index,
self.compass.range_index,
- self.building_layer.range_index,
+ self.contact_layer.range_index,
]
}
@@ -93,7 +95,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)?;
+ self.draw_contacts(renderer, mesh, viewport, center, size, player)?;
let scale = size / 256.0;
let [width, height] = self.compass_size.map(|dimension| dimension * scale);
@@ -115,7 +117,7 @@ impl SatelliteMap {
Ok(())
}
- fn draw_buildings(
+ fn draw_contacts(
&mut self,
renderer: &mut VulkanSmokeRenderer,
mesh: &mut VulkanStaticMesh,
@@ -124,21 +126,28 @@ impl SatelliteMap {
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 (buildings, units) = player.zip(self.extent).map_or_else(
+ || (Vec::new(), Vec::new()),
+ |((engine, cockpit), extent)| {
+ (
+ satellite_contacts::owned_buildings(engine, cockpit, extent).collect(),
+ satellite_contacts::owned_units(engine, cockpit, extent).collect(),
+ )
+ },
+ );
+ if buildings != self.buildings || units != self.units {
let mut layer = empty_layer();
for building in &buildings {
paint_building(&self.icons, &mut layer, *building);
}
+ for unit in &units {
+ paint_unit(&mut layer, *unit);
+ }
renderer
- .update_material_texture(self.building_layer.material_index, 0, &texture(layer))
+ .update_material_texture(self.contact_layer.material_index, 0, &texture(layer))
.map_err(|error| error.to_string())?;
self.buildings = buildings;
+ self.units = units;
}
let vertices = screen_tl_quad_vertices_pixels(
center,
@@ -149,7 +158,7 @@ impl SatelliteMap {
1.0,
UV,
);
- let start = self.building_layer.vertex_start;
+ let start = self.contact_layer.vertex_start;
mesh.vertices[start..start + 4].copy_from_slice(&vertices);
Ok(())
}
@@ -163,6 +172,24 @@ fn empty_layer() -> RgbaImage {
}
}
+fn paint_unit(layer: &mut RgbaImage, unit: satellite_contacts::UnitContact) {
+ let radius = if unit.cross { 2 } else { 1 };
+ for dy in -radius..=radius {
+ let y = unit.pixel[1].saturating_add(dy);
+ if !(0..MAP_SIZE as i32).contains(&y) {
+ continue;
+ }
+ for dx in -radius..=radius {
+ let x = unit.pixel[0].saturating_add(dx);
+ if !(0..MAP_SIZE as i32).contains(&x) || (unit.cross && dx != 0 && dy != 0) {
+ continue;
+ }
+ let dst = (y as usize * MAP_SIZE + x as usize) * 4;
+ layer.rgba8[dst..dst + 4].copy_from_slice(&[128, 128, 255, 255]);
+ }
+ }
+}
+
fn paint_building(
atlas: &RgbaImage,
layer: &mut RgbaImage,