Searchlights with real spot lights and volumetric beams (#60); replay director: several angles per event, slow-motion kills, /airdef replay film and export to MP4 (#58) (fork patch 32)
build / mod (push) Successful in 3m32s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 09:28:13 +03:00
parent 8a12225ba1
commit 76f680eba6
40 changed files with 3827 additions and 52 deletions
+53 -5
View File
@@ -10,6 +10,13 @@ const FLARE_LIGHT: f64 = 90.0;
const FLARE_CLIMB: u32 = 28;
/// How far a searchlight's beam reaches.
pub const BEAM: f64 = 450.0;
/// A searchlight's cone: full strength inside the inner half angle, none past the outer (radians).
pub const BEAM_INNER: f64 = 0.03;
pub const BEAM_OUTER: f64 = 0.075;
/// A target is lit once the axis is this close to it (inside the cone's soft edge).
const LIT_ANGLE: f64 = 0.05;
/// Ticks between casts of the beam's axis against the land.
const CAST_EVERY: u64 = 4;
/// Guns' hits at night on an unlit target.
pub const DARK_HITS: f64 = 0.4;
/// Ticks between a gun's own flares.
@@ -35,7 +42,7 @@ impl Sim {
}
/// The flares and the searchlights, and what they light; the guns' own flares.
pub(super) fn step_lights(&mut self, out: &mut Out) {
pub(super) fn step_lights(&mut self, ground: &mut Ground, out: &mut Out) {
self.lit.clear();
let now = self.tick;
// Flares: up, a burst, then down slowly, swaying, lighting all round.
@@ -71,12 +78,14 @@ impl Sim {
let gun_targets: Vec<u32> = self.sams.iter().filter_map(|s| s.gun_target).collect();
for i in 0..self.sams.len() {
if self.sams[i].kind != SamKind::Light || !self.sams[i].alive() || self.sams[i].moving() {
self.sams[i].beam_on = false;
continue;
}
let (pos, id) = (self.sams[i].pos, self.sams[i].id);
if !self.night {
let sam = &mut self.sams[i];
sam.target = None;
sam.beam_on = false;
sam.pitch += (0.0 - sam.pitch) * 0.05;
continue;
}
@@ -103,15 +112,34 @@ impl Sim {
sam.yaw = slew(sam.yaw, want_yaw, 0.12);
sam.pitch = slew(sam.pitch, want_pitch.clamp(0.05, 1.5), 0.08);
sam.target = target.map(|t| t.0);
// The beam: segments widening with distance, out to the target.
// The beam: a spot light from the head (see `Sam::beam`); the axis is cast against the land
// now and then, and the light and the lit mark stop where the land does.
let (head, rot) = self.sams[i].mount();
let dir = rot * DVec3::NEG_Z;
// The target is lit once the beam is on it, not while it still swings round.
let sam = &mut self.sams[i];
sam.beam_on = true;
if now.saturating_sub(sam.beam_cast) >= CAST_EVERY || sam.beam_free <= 0.0 {
sam.beam_cast = now;
sam.beam_free = match ground.world.probe(head + dir, head + dir * BEAM, now) {
world::Sweep::Hit { point, .. } => point.distance(head).max(1.0),
_ => BEAM,
};
}
let free = sam.beam_free;
// The target is lit once the beam is on it and nothing of the land is between, not while
// it still swings round.
if let Some((t, at)) = target
&& dir.angle_between(at - head) < 0.08
&& dir.angle_between(at - head) < LIT_ANGLE
&& (at - head).length() <= free + 2.0
{
self.lit.push(t);
}
// Without the renderer's spot light: segments widening with distance, thin; none with
// the effects off.
if self.spot_hd || !self.shader {
continue;
}
let reach = reach.min(free);
let mut along = 1.0;
// Up to 14 segments (the unit's part ids 2..15), each longer than the last: one
// reaches about 550 blocks, past the beam's reach, about 9 blocks wide out there.
@@ -119,7 +147,7 @@ impl Sim {
if along >= reach {
break;
}
let size = 0.8 + along * 0.12;
let size = 0.5 + along * 0.1;
let len = 3.0 * size;
out.model(id + 2 + k, "airdef:beam", head + dir * (along + len / 2.0), rot, size, true);
along += len;
@@ -147,3 +175,23 @@ impl Sim {
}
}
}
/// A searchlight's beam for the renderer: where it starts, which way it points and how far it runs free.
pub struct Beam {
pub id: u32,
pub origin: DVec3,
pub dir: DVec3,
pub free: f64,
}
impl Sam {
/// The beam of a lit searchlight, from the lens of its head.
pub fn spot_beam(&self) -> Option<Beam> {
if self.kind != SamKind::Light || !self.alive() || !self.beam_on {
return None;
}
let (head, rot) = self.mount();
let dir = rot * DVec3::NEG_Z;
Some(Beam { id: self.id, origin: head + dir * 1.0, dir, free: self.beam_free })
}
}
+13 -2
View File
@@ -16,7 +16,7 @@ pub mod record;
mod sight;
mod terrain;
mod ew;
mod lights;
pub mod lights;
mod logistics;
mod orders;
mod units;
@@ -1231,6 +1231,11 @@ pub struct Sam {
pub ew_lock: bool,
/// Ticks till a gun fires its next illumination flare.
flare_cd: u32,
/// A searchlight: lit up (night), how far its beam runs free along the axis (the land stops it),
/// and the tick that was last cast.
beam_on: bool,
beam_free: f64,
beam_cast: u64,
/// Shots the land ruled out, by target: when it was judged and why (`terrain::MASKED`, `terrain::PATH_BLOCKED`).
pub(super) terrain: HashMap<u32, (u64, u8)>,
/// Targets whose land hasn't been answered yet, and since when it has been waited for.
@@ -1286,6 +1291,9 @@ impl Sam {
heat: 0.0,
ew_lock: false,
flare_cd: 0,
beam_on: false,
beam_free: 0.0,
beam_cast: 0,
terrain: HashMap::new(),
waits: HashMap::new(),
}
@@ -1431,6 +1439,8 @@ pub struct Sim {
/// Illumination flares in the sky, and the drones lit this tick.
pub flares: Vec<lights::Flare>,
pub lit: Vec<u32>,
/// The renderer draws the searchlights' spot lights and beams (HD); else the beam models do.
pub spot_hd: bool,
}
/// Ids: objects get multiples of 16, their parts the low bits.
@@ -1475,6 +1485,7 @@ impl Sim {
day_time: None,
flares: Vec::new(),
lit: Vec::new(),
spot_hd: false,
}
}
pub fn id(&mut self) -> u32 {
@@ -1579,7 +1590,7 @@ impl Sim {
self.step_supply(out);
self.step_ew(out);
self.update_sight(ground);
self.step_lights(out);
self.step_lights(ground, out);
self.step_sams(ground, out);
self.step_missiles(ground, out);
self.step_fx(ground, out);
+10
View File
@@ -35,6 +35,16 @@ impl Ground {
}
}
/// For a planner: None while the game has not answered, Some(None) where it has no land to
/// tell of, else Some(Some(height)).
pub fn land_state(&mut self, p: DVec3) -> Option<Option<f64>> {
match self.rise(p) {
Rise::Pending => None,
Rise::Void => Some(None),
Rise::At(g) => Some(Some(g)),
}
}
/// The same, saying whether the game has not answered yet or has no land there to tell of.
pub(super) fn rise(&mut self, p: DVec3) -> Rise {
let key = (