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
+174 -8
View File
@@ -4,7 +4,9 @@
//! world and a director's camera (a full-screen camera view) follows them —
//! behind the drone, then behind the interceptor or from the side — slowing
//! time round the moment itself.
use crate::film::{self, Film};
use crate::panel::distance;
use crate::sim::Ground;
use crate::sim::record::{EventKind, Recording, STEP, What};
use std::cell::Cell;
use crate::sim::{Class, DroneKind, Out, Sim};
@@ -23,6 +25,8 @@ pub enum Mode {
Full,
/// Clips one after another (the wheel skips): one event, or the highlight reel.
Clips { list: Vec<Clip>, at: usize, reel: bool },
/// The director's film: planned shots from several angles with cuts and slow motion.
Film(Box<Film>),
}
pub struct Clip {
@@ -55,6 +59,20 @@ pub struct Player {
heard: f64,
/// Time stands still (Space, or the end reached).
paused: bool,
/// The film's own clock in seconds (the replay's moment follows from the plan).
tau: f64,
/// The film waits for the recorder to start (an export).
pub wait: bool,
/// Titles and bars only: no keys, clock or help on the screen (an export).
pub clean: bool,
/// The film stops at this many seconds (a short test export).
pub limit: Option<f64>,
/// The film reached its end.
pub ended: bool,
/// Which of the two sets of ghost ids is in use (a cut changes it, so nothing glides across it).
alt: bool,
/// The film's shot, caption and blackness this tick.
cut: Option<(usize, f32, f32)>,
/// Ticks the controls stay on screen.
help: u32,
pub done: bool,
@@ -131,7 +149,7 @@ pub fn row(rec: &Recording, i: usize) -> String {
}
/// How worth watching an event is: the reel takes the best.
fn interest(rec: &Recording, i: usize) -> f64 {
pub fn interest(rec: &Recording, i: usize) -> f64 {
let e = &rec.events[i];
match e.kind {
EventKind::Kill { kind, missile, .. } => {
@@ -206,7 +224,7 @@ impl Player {
let speed = match mode {
Mode::Map => 8.0,
Mode::Full => 2.0,
Mode::Clips { .. } => 1.0,
Mode::Clips { .. } | Mode::Film(_) => 1.0,
};
let _ = sim;
Player {
@@ -226,6 +244,13 @@ impl Player {
fov: 50.0,
heard: start,
paused: false,
tau: 0.0,
wait: false,
clean: false,
limit: None,
ended: false,
alt: false,
cut: None,
help: 100,
done: false,
}
@@ -264,6 +289,13 @@ impl Player {
self.heard = self.t;
self.shot = (usize::MAX, 0);
}
Mode::Film(f) => {
// To the next or the previous plan.
let now = self.cut.map_or(0, |c| c.0);
let to = (now as i32 + dir).clamp(0, f.shots() as i32 - 1) as usize;
self.tau = f.start_of(to);
self.paused = false;
}
Mode::Clips { list, at, reel } => {
let next = (*at as i32 + dir).clamp(0, list.len() as i32 - 1) as usize;
// Back on the first moment: from its start again.
@@ -283,6 +315,7 @@ impl Player {
match &self.mode {
Mode::Map | Mode::Full => self.t >= rec.len as f64,
Mode::Clips { list, at, .. } => *at + 1 >= list.len() && self.t >= list[*at].to,
Mode::Film(_) => self.ended,
}
}
@@ -295,6 +328,8 @@ impl Player {
}
_ => 0.0,
};
self.tau = 0.0;
self.ended = false;
self.heard = self.t;
self.card = if reel { 50 } else { 0 };
self.fade = 6;
@@ -326,11 +361,15 @@ impl Player {
}
/// One tick: time runs, the ghosts fly, the director films. Models and sounds go to `out`.
pub fn tick(&mut self, sim: &Sim, listener: DVec3, out: &mut Out) {
pub fn tick(&mut self, sim: &Sim, ground: &mut Ground, listener: DVec3, out: &mut Out) {
let Some(rec) = sim.replay(self.rec) else {
self.done = true;
return;
};
if matches!(self.mode, Mode::Film(_)) {
self.tick_film(sim, ground, listener, out, rec);
return;
}
self.fade = self.fade.saturating_sub(1);
if self.card > 0 {
self.card -= 1;
@@ -360,6 +399,7 @@ impl Player {
self.paused = true;
}
}
Mode::Film(_) => {}
Mode::Clips { list, at, reel } => {
if self.t >= list[*at].to {
if *at + 1 < list.len() {
@@ -380,7 +420,11 @@ impl Player {
}
sim.draw_ghosts(rec, self.t, GHOSTS, out);
self.direct(rec);
// Sounds as the camera hears them: moved so the player stands where the camera is.
self.sounds(rec, listener, out);
}
/// Sounds as the camera hears them: moved so the player stands where the camera is.
fn sounds(&mut self, rec: &Recording, listener: DVec3, out: &mut Out) {
let heard = |p: DVec3| listener + (p - self.eye);
for e in rec.events.iter().filter(|e| (self.heard..self.t).contains(&(e.at as f64))) {
let event = match e.kind {
@@ -402,7 +446,125 @@ impl Player {
self.heard = self.t;
}
/// The event the camera films now, and how it shoots it: (eye, look, fov, shot).
/// One tick of the film: its clock runs, the plan gives the camera and the replay's moment.
fn tick_film(&mut self, sim: &Sim, ground: &mut Ground, listener: DVec3, out: &mut Out, rec: &Recording) {
let Mode::Film(mut film) = std::mem::replace(&mut self.mode, Mode::Map) else { return };
self.fade = self.fade.saturating_sub(1);
self.help = self.help.saturating_sub(1);
if !film.prepare(rec, ground) {
self.rate = 0.0;
self.mode = Mode::Film(film);
return;
}
let end = self.limit.map_or(film.len, |l| l.min(film.len));
if !self.paused && !self.wait && !self.ended {
self.tau += film::TICK_S;
}
if self.tau >= end {
self.tau = end;
self.ended = true;
// A live film stops on its last frame (Space plays it again); an export is ended by the caller.
if !self.clean {
self.paused = true;
}
}
let f = film.frame(rec, self.tau);
let changed = self.cut.is_none_or(|c| c.0 != f.shot);
if changed {
self.view = self.view.wrapping_add(1).max(VIEW);
self.alt = !self.alt;
self.heard = f.t;
self.fade = if self.cut.is_some() { 2 } else { 0 };
}
self.rate = if changed { 1.0 } else { (f.t - self.t).clamp(0.0, 1.0) };
self.t = f.t;
self.eye = f.eye;
self.look = f.look;
self.fov = f.fov;
self.shot = (f.event, f.shot.min(255) as u8);
self.cut = Some((f.shot, f.caption, f.black));
let base = GHOSTS + if self.alt { 0x0100_0000 } else { 0 };
sim.draw_ghosts(rec, self.t, base, out);
if !self.wait {
self.sounds(rec, listener, out);
} else {
self.heard = self.t;
}
self.mode = Mode::Film(film);
}
/// The film's length in seconds (what an export records), after the limit.
pub fn film_len(&self) -> Option<f64> {
match &self.mode {
Mode::Film(f) => Some(self.limit.map_or(f.len, |l| l.min(f.len))),
_ => None,
}
}
/// Whether the film's shots are placed (an export waits for it).
pub fn film_ready(&self) -> bool {
matches!(&self.mode, Mode::Film(f) if f.ready)
}
/// The film's clock, in seconds.
pub fn film_time(&self) -> f64 {
self.tau
}
/// A line about the film, for the chat.
pub fn film_summary(&self) -> String {
match &self.mode {
Mode::Film(f) => f.summary(),
_ => String::new(),
}
}
/// The film's screen: bars, captions, the black of its start and end.
fn film_hud(&self, rec: &Recording, film: &Film, sim: &Sim, gw: f32, gh: f32) -> Vec<Shape> {
let mut s: Vec<Shape> = Vec::new();
let bar = (gh * 0.09).round();
if !film.ready {
s.push(fill(0.0, 0.0, gw, gh, 0xFF000000));
s.push(text(format!("Готовлю кадры… {:.0}%", film.progress() * 100.0), gw / 2.0, gh / 2.0 - 4.0, 0xFFC0C0C0, true));
return s;
}
s.push(fill(0.0, 0.0, gw, bar, 0xFF000000));
s.push(fill(0.0, gh - bar, gw, bar, 0xFF000000));
let (shot, caption, black) = self.cut.unwrap_or((0, 0.0, 1.0));
if !self.clean {
let blink = (sim.tick / 10) % 2 == 0;
s.push(fill(8.0, bar / 2.0 - 3.0, 6.0, 6.0, if blink { 0xFFFF2020 } else { 0x60FF2020 }));
s.push(text(format!("ФИЛЬМ · налёт №{} · план {}/{}", rec.number, shot + 1, film.shots()), 18.0, bar / 2.0 - 4.0, 0xFFFFFFFF, false));
let time = format!("{} / {}{}", clock(self.tau * 20.0), clock(film.len * 20.0), if self.paused { " ПАУЗА" } else { "" });
let tw = horizon_mod_sdk::render::text_width(&time);
s.push(text(time, gw - 8.0 - tw, bar / 2.0 - 4.0, 0xFFC0C0C0, false));
// Progress.
s.push(fill(0.0, gh - bar - 2.0, gw * (self.tau / film.len.max(0.01)) as f32, 2.0, 0xC0FFD040));
}
// The caption: a lower third that comes in after the cut and goes before the next.
let (head, sub) = film.caption(shot);
if caption > 0.01 {
let a = (caption * 255.0) as u32;
let x = (gw * 0.07).round();
let y = gh - bar - 52.0;
let w = horizon_mod_sdk::render::text_width(head).max(horizon_mod_sdk::render::text_width(sub)) + 22.0;
s.push(fill(x - 8.0, y, 3.0, if sub.is_empty() { 18.0 } else { 30.0 }, (a << 24) | 0xFFD040));
s.push(fill(x - 5.0, y, w, if sub.is_empty() { 18.0 } else { 30.0 }, ((a * 140 / 255) << 24) | 0x000000));
s.push(text(head, x + 4.0, y + 5.0, (a << 24) | 0xFFFFFF, false));
if !sub.is_empty() {
s.push(text(sub, x + 4.0, y + 17.0, (a << 24) | 0xC0C0C0, false));
}
}
if self.fade > 0 {
s.push(fill(0.0, 0.0, gw, gh, ((self.fade.min(6) * 42) as u32) << 24));
}
if black > 0.003 {
s.push(fill(0.0, 0.0, gw, gh, (((black * 255.0) as u32).min(255)) << 24));
}
if !self.clean {
self.controls(&mut s, gw, gh, bar);
}
s
}
/// The event the camera films now: (eye, look, fov, shot).
fn shoot(&mut self, rec: &Recording, i: usize) -> (DVec3, DVec3, f32, u8) {
let e = rec.events[i];
let t = self.t;
@@ -478,7 +640,7 @@ impl Player {
.iter()
.position(|e| (self.t - 30.0..self.t + 120.0).contains(&(e.at as f64)))
.or(if self.shot.0 != usize::MAX && (rec.events[self.shot.0].at as f64) > self.t - 60.0 { Some(self.shot.0) } else { None }),
Mode::Map => None,
Mode::Map | Mode::Film(_) => None,
};
let (eye, look, fov, shot) = match focus {
Some(i) => {
@@ -522,9 +684,10 @@ impl Player {
let d = (self.look - self.eye).normalize_or(DVec3::NEG_Z);
let yaw = (-d.x).atan2(d.z).to_degrees() as f32;
let pitch = (-d.y).asin().to_degrees() as f32;
let width = 1280u32;
// The main view takes the window's size; the picture size only matters to the small views.
let width = 1920u32;
let height = ((width as f32) * gh / gw.max(1.0)) as u32;
vec![CameraView { id: self.view, x: self.eye.x, y: self.eye.y, z: self.eye.z, yaw, pitch, fov: self.fov, width, height: height.clamp(240, 1080) }]
vec![CameraView { id: self.view, x: self.eye.x, y: self.eye.y, z: self.eye.z, yaw, pitch, fov: self.fov, width, height: height.clamp(240, 2160) }]
}
/// The replay's screen: the film with its titles, or the map.
@@ -533,6 +696,9 @@ impl Player {
if matches!(self.mode, Mode::Map) {
return self.map(rec, gw, gh);
}
if let Mode::Film(f) = &self.mode {
return self.film_hud(rec, f, sim, gw, gh);
}
// The world itself is the camera's (`set-main-view`): the HUD only frames it.
let mut s: Vec<Shape> = Vec::new();
// Letterbox, the recording's marks.