aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/fparkan-game/src/main.rs7
-rw-r--r--apps/fparkan-game/src/satellite_map.rs66
2 files changed, 47 insertions, 26 deletions
diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs
index 7f6a98f9..1eb3d895 100644
--- a/apps/fparkan-game/src/main.rs
+++ b/apps/fparkan-game/src/main.rs
@@ -10789,6 +10789,7 @@ impl StaticVulkanApp {
{
self.cockpit = Some(hero);
self.boarded_hero_index = None;
+ self.boarding_target = None;
self.camera_mode = "starting-cockpit";
eprintln!(
"player_disembark object={} queue_time_ms={control_clock_ms}",
@@ -10964,7 +10965,6 @@ impl StaticVulkanApp {
.map_err(|error| error.to_string())?;
capture_notice = entry.capture_notice();
if let Some(target) = entry.captured {
- self.boarding_target = mission_object_handle(engine, target);
eprintln!(
"player_capture object={} queue_time_ms={control_clock_ms}",
target.0
@@ -11674,7 +11674,10 @@ impl StaticVulkanApp {
renderer,
&mut self.mesh,
frame.viewport,
- self.mission_engine.as_ref().zip(self.cockpit),
+ self.mission_engine
+ .as_ref()
+ .zip(self.cockpit)
+ .map(|(engine, cockpit)| (engine, cockpit, self.boarding_target)),
)?;
}
#[cfg(windows)]
diff --git a/apps/fparkan-game/src/satellite_map.rs b/apps/fparkan-game/src/satellite_map.rs
index 37d60fa9..c74e893a 100644
--- a/apps/fparkan-game/src/satellite_map.rs
+++ b/apps/fparkan-game/src/satellite_map.rs
@@ -7,6 +7,7 @@ use super::{
use fparkan_assets::{satellite_map::load_satellite_map, RgbaImage};
use fparkan_runtime::{satellite_contacts, Engine, StartingCockpit};
use fparkan_vfs::DirectoryVfs;
+use fparkan_world::ObjectHandle;
use std::{path::Path, sync::Arc};
const UV: [[f32; 2]; 4] = [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]];
@@ -68,7 +69,7 @@ impl SatelliteMap {
renderer: &mut VulkanSmokeRenderer,
mesh: &mut VulkanStaticMesh,
viewport: [f32; 2],
- player: Option<(&Engine, StartingCockpit)>,
+ player: Option<(&Engine, StartingCockpit, Option<ObjectHandle>)>,
) -> Result<(), String> {
let count = if self.visible { 6 } else { 0 };
for index in self.ranges() {
@@ -124,14 +125,14 @@ impl SatelliteMap {
viewport: [f32; 2],
center: [f32; 2],
size: f32,
- player: Option<(&Engine, StartingCockpit)>,
+ player: Option<(&Engine, StartingCockpit, Option<ObjectHandle>)>,
) -> Result<(), String> {
let (buildings, units) = player.zip(self.extent).map_or_else(
|| (Vec::new(), Vec::new()),
- |((engine, cockpit), extent)| {
+ |((engine, cockpit, selected), extent)| {
(
satellite_contacts::owned_buildings(engine, cockpit, extent).collect(),
- satellite_contacts::owned_units(engine, cockpit, extent).collect(),
+ satellite_contacts::owned_units(engine, cockpit, extent, selected).collect(),
)
},
);
@@ -141,7 +142,7 @@ impl SatelliteMap {
paint_building(&self.icons, &mut layer, *building);
}
for unit in &units {
- paint_unit(&mut layer, *unit);
+ paint_unit(&mut layer, unit);
}
renderer
.update_material_texture(self.contact_layer.material_index, 0, &texture(layer))
@@ -172,7 +173,17 @@ fn empty_layer() -> RgbaImage {
}
}
-fn paint_unit(layer: &mut RgbaImage, unit: satellite_contacts::UnitContact) {
+fn paint_unit(layer: &mut RgbaImage, unit: &satellite_contacts::UnitContact) {
+ let mut from = unit.pixel;
+ for &point in &unit.route {
+ paint_line(layer, from, point, [100, 200, 100, 255]);
+ for dy in -1..=1 {
+ for dx in -1..=1 {
+ paint_unit_pixel(layer, point, [dx, dy], [200, 200, 100, 255]);
+ }
+ }
+ from = point;
+ }
let radius = if unit.cross { 2 } else { 1 };
for dy in -radius..=radius {
for dx in -radius..=radius {
@@ -201,24 +212,31 @@ fn paint_unit(layer: &mut RgbaImage, unit: satellite_contacts::UnitContact) {
paint_unit_pixel(layer, unit.pixel, point, color);
}
}
- let [end_x, end_y] = heading.tip_offset;
- let [mut x, mut y] = [0, 0];
- let [dx, dy] = [end_x.abs(), -end_y.abs()];
- let mut error = dx + dy;
- loop {
- paint_unit_pixel(layer, unit.pixel, [x, y], color);
- if [x, y] == [end_x, end_y] {
- break;
- }
- let twice = 2 * error;
- if twice >= dy {
- error += dy;
- x += end_x.signum();
- }
- if twice <= dx {
- error += dx;
- y += end_y.signum();
- }
+ let tip = std::array::from_fn(|axis| unit.pixel[axis].saturating_add(heading.tip_offset[axis]));
+ paint_line(layer, unit.pixel, tip, color);
+}
+
+fn paint_line(layer: &mut RgbaImage, from: [i32; 2], to: [i32; 2], color: [u8; 4]) {
+ let [dx, dy] = std::array::from_fn(|axis| i128::from(to[axis]) - i128::from(from[axis]));
+ let major = usize::from(dy.abs() > dx.abs());
+ let minor = 1 - major;
+ let span = [dx, dy][major].abs();
+ if span == 0 {
+ paint_unit_pixel(layer, from, [0, 0], color);
+ return;
+ }
+ // Intersect the major-axis interval with the map before rasterizing. Off-map
+ // orders retain the direction of the original segment without a long loop.
+ let start = from[major].min(to[major]).max(0);
+ let end = from[major].max(to[major]).min(MAP_SIZE as i32 - 1);
+ let rise = [dx, dy][minor];
+ for coordinate in start..=end {
+ let step = (i128::from(coordinate) - i128::from(from[major])).abs();
+ let offset = ((step * rise.abs() + span / 2) / span) * rise.signum();
+ let mut point = from;
+ point[major] = coordinate;
+ point[minor] = (i128::from(from[minor]) + offset) as i32;
+ paint_unit_pixel(layer, point, [0, 0], color);
}
}