Replays: smoke rebuilt from the recording, recorded objects and searchlights, film cut in true order, export sessions guarded, gun camera above water; export keeps its last frames; hd_bench no longer excuses strong flicker (#76-#84, fork patch 35)
build / mod (push) Successful in 3m49s
build / mod (push) Successful in 3m49s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+190
-80
@@ -243,21 +243,42 @@ fn placements<F: Fn(f64, f64) -> Rig>(mk: F) -> Vec<Rig> {
|
||||
vec![mk(1.0, 0.0), mk(-1.0, 0.0), mk(1.0, 28.0), mk(-1.0, 28.0)]
|
||||
}
|
||||
|
||||
/// The shots of event `i`.
|
||||
fn plan_event(rec: &Recording, i: usize) -> Vec<Shot> {
|
||||
/// Shortest shot worth cutting to, in replay ticks.
|
||||
const MIN_SHOT: f64 = 8.0;
|
||||
|
||||
/// The replay tick a shot ends at.
|
||||
fn shot_end(s: &Shot) -> f64 {
|
||||
s.table.last().copied().unwrap_or(0.0)
|
||||
}
|
||||
|
||||
/// The shots of event `i`, with replay time never running back: no shot starts before `floor` (the
|
||||
/// end of the one before it, or of the previous event's last), a stage the real intervals leave no
|
||||
/// room for is merged into its neighbour or left out, and what happens in the story comes in the
|
||||
/// order it happened (a launch before its kill; an interceptor not before its first point).
|
||||
fn plan_event(rec: &Recording, i: usize, floor: f64) -> Vec<Shot> {
|
||||
let e = rec.events[i];
|
||||
let te = e.at as f64;
|
||||
let o = rec.origin;
|
||||
let end = rec.len as f64;
|
||||
let pos = e.pos;
|
||||
let mut shots: Vec<Shot> = Vec::new();
|
||||
let mut add = |shot: Shot| shots.push(shot);
|
||||
let cur = std::cell::Cell::new(floor);
|
||||
let mut add = |shot: Shot| {
|
||||
cur.set(shot_end(&shot));
|
||||
shots.push(shot);
|
||||
};
|
||||
// The interval a stage may use: not before the cursor, and long enough to be a shot.
|
||||
let span = |a: f64, b: f64| -> Option<(f64, f64)> {
|
||||
let a = a.max(0.0).max(cur.get());
|
||||
(b - a >= MIN_SHOT).then_some((a, b))
|
||||
};
|
||||
// The slow moment: half speed into it, a tenth through it, back to normal after.
|
||||
let slow = |lead: f64, after: f64| -> Vec<(f64, f64)> {
|
||||
vec![(te - lead, 0.6), (te - 4.0, 0.15), (te + 6.0, 0.15), (te + 22.0, 0.6), (te + after, 1.0)]
|
||||
};
|
||||
let kill_close = |from: DVec3, aim_id: Option<u32>, head: &str, sub: String| -> Shot {
|
||||
let a = (te - 10.0).max(0.0);
|
||||
// Never before the story so far; held to at least a few ticks.
|
||||
let a = (te - 10.0).max(0.0).max(cur.get());
|
||||
let b = (te + 48.0).min(end).max(a + 4.0);
|
||||
let variants = placements(|side, lift| {
|
||||
let s = across(pos, from) * side;
|
||||
@@ -272,8 +293,7 @@ fn plan_event(rec: &Recording, i: usize) -> Vec<Shot> {
|
||||
Shot::new(a, b, &slow(10.0, 48.0), variants, head, &sub, i)
|
||||
};
|
||||
let aftermath = |from: DVec3, head: &str| -> Option<Shot> {
|
||||
let a = (te + 48.0).min(end);
|
||||
let b = (te + 150.0).min(end);
|
||||
let (a, b) = span((te + 48.0).min(end), (te + 150.0).min(end))?;
|
||||
if b - a < 20.0 {
|
||||
return None;
|
||||
}
|
||||
@@ -295,60 +315,78 @@ fn plan_event(rec: &Recording, i: usize) -> Vec<Shot> {
|
||||
let mt = missile.and_then(|m| rec.track(m).map(|t| (m, t.first as f64)));
|
||||
match mt {
|
||||
Some((m, tl)) => {
|
||||
// The hero: the launcher, three-quarters, a little before the launch.
|
||||
let a = (tl - 60.0).max(0.0);
|
||||
let b = tl + 6.0;
|
||||
let launcher = sp + DVec3::Y * 4.0;
|
||||
let variants = placements(|side, lift| {
|
||||
let dir = (pos - sp).with_y(0.0).normalize_or(DVec3::X);
|
||||
let s = across(pos, sp) * side;
|
||||
let base = sp - dir * 38.0 + s * 34.0;
|
||||
Rig {
|
||||
eye: Eye::Dolly(base + DVec3::Y * (7.0 + lift), base + s * 6.0 - dir * 4.0 + DVec3::Y * (9.0 + lift)),
|
||||
aim: Aim::Point(launcher),
|
||||
fov: (46.0, 40.0),
|
||||
}
|
||||
});
|
||||
add(Shot::new(a, b.max(a + 20.0), &[(a, 1.0)], variants, &name, &sub, i));
|
||||
// The launch, from the side, the camera low and the interceptor climbing away.
|
||||
let a2 = b.max(a + 20.0);
|
||||
let b2 = (a2 + 44.0).min(te - 20.0).max(a2 + 10.0);
|
||||
let variants = placements(|side, lift| {
|
||||
let s = across(pos, sp) * side;
|
||||
Rig { eye: Eye::Static(sp + s * 46.0 + DVec3::Y * (3.0 + lift * 0.3)), aim: Aim::Track(m, sp), fov: (42.0, 24.0) }
|
||||
});
|
||||
add(Shot::new(a2, b2, &[(a2, 1.0)], variants, "Пуск", "", i));
|
||||
// The flight, from behind the interceptor with the target ahead; long flights run faster.
|
||||
let a3 = b2;
|
||||
let b3 = te - 32.0;
|
||||
if b3 - a3 > 14.0 {
|
||||
let sp3 = (((b3 - a3) / 6.0) / 20.0).clamp(1.0, 4.0);
|
||||
let variants = placements(|side, lift| Rig {
|
||||
eye: Eye::Behind { track: m, back: 15.0, up: 3.5 + lift * 0.2, side: 5.0 * side },
|
||||
aim: Aim::Track(drone, pos),
|
||||
fov: (56.0, 56.0),
|
||||
// The facts, in order: the launcher waits, the interceptor leaves it at `tl`, it
|
||||
// flies, it meets the target at `te`. Each stage gets the time the real flight
|
||||
// has for it; what has none is merged into the one before, or left out.
|
||||
let tl = tl.min(te);
|
||||
// The hero: the launcher, three-quarters, until the launch.
|
||||
if let Some((a, b)) = span(tl - 60.0, tl) {
|
||||
let launcher = sp + DVec3::Y * 4.0;
|
||||
let variants = placements(|side, lift| {
|
||||
let dir = (pos - sp).with_y(0.0).normalize_or(DVec3::X);
|
||||
let s = across(pos, sp) * side;
|
||||
let base = sp - dir * 38.0 + s * 34.0;
|
||||
Rig {
|
||||
eye: Eye::Dolly(base + DVec3::Y * (7.0 + lift), base + s * 6.0 - dir * 4.0 + DVec3::Y * (9.0 + lift)),
|
||||
aim: Aim::Point(launcher),
|
||||
fov: (46.0, 40.0),
|
||||
}
|
||||
});
|
||||
add(Shot::new(a3, b3, &[(a3, sp3)], variants, "Сближение", "", i));
|
||||
add(Shot::new(a, b, &[(a, 1.0)], variants, &name, &sub, i));
|
||||
}
|
||||
// The flight proper runs from the launch to ten ticks before the kill (where the
|
||||
// close-up begins); under 6 ticks of it there is no room for more than the close-up.
|
||||
let from = tl.max(cur.get());
|
||||
let ke = te - 10.0;
|
||||
let room = ke - from;
|
||||
if room >= 6.0 {
|
||||
let launch_len = (room * 0.4).clamp(6.0, 44.0);
|
||||
let mut b2 = from + launch_len;
|
||||
let rest = ke - b2;
|
||||
// The launch, from the side, the camera low and the interceptor climbing away.
|
||||
let launch_at = |b2: f64| {
|
||||
let variants = placements(|side, lift| {
|
||||
let s = across(pos, sp) * side;
|
||||
Rig { eye: Eye::Static(sp + s * 46.0 + DVec3::Y * (3.0 + lift * 0.3)), aim: Aim::Track(m, sp), fov: (42.0, 24.0) }
|
||||
});
|
||||
Shot::new(from, b2, &[(from, 1.0)], variants, "Пуск", "", i)
|
||||
};
|
||||
if rest < 14.0 {
|
||||
// Too short to fly on camera: the launch shot runs to the close-up.
|
||||
b2 = ke;
|
||||
add(launch_at(b2));
|
||||
} else {
|
||||
add(launch_at(b2));
|
||||
// The flight, from behind the interceptor with the target ahead; long flights run faster.
|
||||
let b3 = if rest >= 36.0 { te - 32.0 } else { ke };
|
||||
let sp3 = (((b3 - b2) / 6.0) / 20.0).clamp(1.0, 4.0);
|
||||
let variants = placements(|side, lift| Rig {
|
||||
eye: Eye::Behind { track: m, back: 15.0, up: 3.5 + lift * 0.2, side: 5.0 * side },
|
||||
aim: Aim::Track(drone, pos),
|
||||
fov: (56.0, 56.0),
|
||||
});
|
||||
add(Shot::new(b2, b3, &[(b2, sp3)], variants, "Сближение", "", i));
|
||||
// Ahead of the target, looking back at the interceptor closing.
|
||||
if rest >= 36.0 {
|
||||
let variants = placements(|side, lift| Rig {
|
||||
eye: Eye::Ahead { track: drone, ahead: 48.0, up: 6.0 + lift * 0.3, side: 14.0 * side },
|
||||
aim: Aim::Mid(m, drone, pos),
|
||||
fov: (46.0, 38.0),
|
||||
});
|
||||
add(Shot::new(b3, ke, &[(b3, 0.6)], variants, "", "", i));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Ahead of the target, looking back at the interceptor closing.
|
||||
let a4 = te - 32.0;
|
||||
let b4 = te - 10.0;
|
||||
let variants = placements(|side, lift| Rig {
|
||||
eye: Eye::Ahead { track: drone, ahead: 48.0, up: 6.0 + lift * 0.3, side: 14.0 * side },
|
||||
aim: Aim::Mid(m, drone, pos),
|
||||
fov: (46.0, 38.0),
|
||||
});
|
||||
add(Shot::new(a4.max(0.0), b4.max(a4 + 6.0), &[(a4, 0.6)], variants, "", "", i));
|
||||
}
|
||||
None => {
|
||||
// A gun kill: the gun's view of the target.
|
||||
let a = (te - 110.0).max(0.0);
|
||||
let b = te - 10.0;
|
||||
let variants = placements(|side, lift| {
|
||||
let s = across(pos, sp) * side;
|
||||
Rig { eye: Eye::Static(sp + s * 14.0 + DVec3::Y * (5.0 + lift * 0.3)), aim: Aim::Track(drone, pos), fov: (34.0, 18.0) }
|
||||
});
|
||||
add(Shot::new(a, b.max(a + 12.0), &[(a, 1.0)], variants, &name, &sub, i));
|
||||
// A gun kill: the gun's view of the target (if the recording has room before it).
|
||||
if let Some((a, b)) = span(te - 110.0, te - 10.0) {
|
||||
let variants = placements(|side, lift| {
|
||||
let s = across(pos, sp) * side;
|
||||
Rig { eye: Eye::Static(sp + s * 14.0 + DVec3::Y * (5.0 + lift * 0.3)), aim: Aim::Track(drone, pos), fov: (34.0, 18.0) }
|
||||
});
|
||||
add(Shot::new(a, b, &[(a, 1.0)], variants, &name, &sub, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
let high = (pos.y - sp.y).max(0.0);
|
||||
@@ -360,20 +398,21 @@ fn plan_event(rec: &Recording, i: usize) -> Vec<Shot> {
|
||||
EventKind::Hit { drone, .. } | EventKind::Crash { drone, .. } => {
|
||||
let from = rec.track(drone).and_then(|t| t.at(o, te - 60.0)).unwrap_or(o);
|
||||
let head = title(rec, i);
|
||||
let a = (te - 150.0).max(0.0);
|
||||
let b = te - 55.0;
|
||||
let variants = placements(|side, lift| Rig {
|
||||
eye: Eye::Behind { track: drone, back: 16.0, up: 4.0 + lift * 0.2, side: 6.0 * side },
|
||||
aim: Aim::Point(pos),
|
||||
fov: (55.0, 55.0),
|
||||
});
|
||||
add(Shot::new(a, b.max(a + 16.0), &[(a, 1.4)], variants, &head, "", i));
|
||||
let a2 = te - 55.0;
|
||||
let variants = placements(|side, lift| {
|
||||
let s = across(pos, from) * side;
|
||||
Rig { eye: Eye::Static(pos + s * 80.0 + DVec3::Y * (3.0 + lift * 0.3)), aim: Aim::Track(drone, pos), fov: (40.0, 28.0) }
|
||||
});
|
||||
add(Shot::new(a2.max(0.0), (te - 10.0).max(a2 + 8.0), &[(a2, 0.8)], variants, "", "", i));
|
||||
if let Some((a, b)) = span(te - 150.0, te - 55.0) {
|
||||
let variants = placements(|side, lift| Rig {
|
||||
eye: Eye::Behind { track: drone, back: 16.0, up: 4.0 + lift * 0.2, side: 6.0 * side },
|
||||
aim: Aim::Point(pos),
|
||||
fov: (55.0, 55.0),
|
||||
});
|
||||
add(Shot::new(a, b, &[(a, 1.4)], variants, &head, "", i));
|
||||
}
|
||||
if let Some((a2, b2)) = span(te - 55.0, te - 10.0) {
|
||||
let variants = placements(|side, lift| {
|
||||
let s = across(pos, from) * side;
|
||||
Rig { eye: Eye::Static(pos + s * 80.0 + DVec3::Y * (3.0 + lift * 0.3)), aim: Aim::Track(drone, pos), fov: (40.0, 28.0) }
|
||||
});
|
||||
add(Shot::new(a2, b2, &[(a2, 0.8)], variants, "", "", i));
|
||||
}
|
||||
let sub = match e.kind {
|
||||
EventKind::Hit { power, .. } | EventKind::Crash { power, .. } => {
|
||||
format!("сила взрыва: {}", ["хлопок", "средний", "сильный", "тяжёлый", "мощнейший"][(power as usize).min(4)])
|
||||
@@ -387,12 +426,13 @@ fn plan_event(rec: &Recording, i: usize) -> Vec<Shot> {
|
||||
}
|
||||
EventKind::SamLost { .. } => {
|
||||
let from = pos + DVec3::new(300.0, 0.0, 0.0);
|
||||
let a = (te - 70.0).max(0.0);
|
||||
let variants = placements(|side, lift| {
|
||||
let s = across(pos, from) * side;
|
||||
Rig { eye: Eye::Dolly(pos + s * 70.0 + DVec3::Y * (12.0 + lift), pos + s * 52.0 + DVec3::Y * (9.0 + lift)), aim: Aim::Point(pos + DVec3::Y * 3.0), fov: (50.0, 44.0) }
|
||||
});
|
||||
add(Shot::new(a, (te - 10.0).max(a + 10.0), &[(a, 1.0)], variants, &title(rec, i), "", i));
|
||||
if let Some((a, b)) = span(te - 70.0, te - 10.0) {
|
||||
let variants = placements(|side, lift| {
|
||||
let s = across(pos, from) * side;
|
||||
Rig { eye: Eye::Dolly(pos + s * 70.0 + DVec3::Y * (12.0 + lift), pos + s * 52.0 + DVec3::Y * (9.0 + lift)), aim: Aim::Point(pos + DVec3::Y * 3.0), fov: (50.0, 44.0) }
|
||||
});
|
||||
add(Shot::new(a, b, &[(a, 1.0)], variants, &title(rec, i), "", i));
|
||||
}
|
||||
add(kill_close(from, None, "Комплекс уничтожен", String::new()));
|
||||
if let Some(s) = aftermath(from, "") {
|
||||
add(s);
|
||||
@@ -400,14 +440,14 @@ fn plan_event(rec: &Recording, i: usize) -> Vec<Shot> {
|
||||
}
|
||||
EventKind::Split { .. } => {
|
||||
let ground = DVec3::new(pos.x, o.y, pos.z);
|
||||
let a = (te - 40.0).max(0.0);
|
||||
let b = (te + 170.0).min(end);
|
||||
let a = (te - 40.0).max(0.0).max(cur.get());
|
||||
let b = (te + 170.0).min(end).max(a + 20.0);
|
||||
let variants = placements(|side, lift| Rig {
|
||||
eye: Eye::Dolly(ground + DVec3::new(170.0 * side, 8.0 + lift, 40.0), ground + DVec3::new(150.0 * side, 14.0 + lift, 20.0)),
|
||||
aim: Aim::Point(pos.lerp(ground, 0.4)),
|
||||
fov: (60.0, 52.0),
|
||||
});
|
||||
add(Shot::new(a, b.max(a + 20.0), &[(a, 1.0), (te - 4.0, 0.3), (te + 40.0, 1.0)], variants, &title(rec, i), "", i));
|
||||
add(Shot::new(a, b, &[(a, 1.0), (te - 4.0, 0.3), (te + 40.0, 1.0)], variants, &title(rec, i), "", i));
|
||||
}
|
||||
}
|
||||
shots
|
||||
@@ -421,8 +461,14 @@ impl Film {
|
||||
return None;
|
||||
}
|
||||
let mut shots: Vec<Shot> = Vec::new();
|
||||
// Replay time only moves on through the film: an event's shots start where the last ended.
|
||||
let mut floor = 0.0;
|
||||
for i in events {
|
||||
shots.extend(plan_event(rec, i));
|
||||
let planned = plan_event(rec, i, floor);
|
||||
if let Some(last) = planned.last() {
|
||||
floor = shot_end(last);
|
||||
}
|
||||
shots.extend(planned);
|
||||
}
|
||||
let mut start = 0.0;
|
||||
for s in &mut shots {
|
||||
@@ -573,3 +619,67 @@ impl Film {
|
||||
format!("{} моментов, {} планов, {:.0} с", events.len(), self.shots.len(), self.len)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sim::record::{Event, What};
|
||||
use crate::sim::{DroneKind, MissileKind, SamKind};
|
||||
|
||||
/// A recording with one interception: the interceptor leaves at `launch`, the kill is at `kill`.
|
||||
fn intercept(len: u32, launch: u32, kill: u32, missile: bool) -> Recording {
|
||||
let mut rec = Recording::blank(len);
|
||||
let pos = DVec3::new(0.0, 100.0, 300.0);
|
||||
rec.sams.push((5, SamKind::S400, DVec3::new(0.0, 64.0, 0.0)));
|
||||
rec.straight(1, What::Drone(DroneKind::Geran3), 0, kill + 20, DVec3::new(0.0, 100.0, 900.0), pos);
|
||||
if missile {
|
||||
rec.straight(2, What::Missile(MissileKind::M48n6, 5), launch, kill, DVec3::new(0.0, 66.0, 0.0), pos);
|
||||
}
|
||||
rec.events.push(Event {
|
||||
at: kill,
|
||||
pos,
|
||||
kind: EventKind::Kill { drone: 1, kind: DroneKind::Geran3, sam: 5, sam_kind: SamKind::S400, sam_index: 0, missile: missile.then_some(2) },
|
||||
});
|
||||
rec
|
||||
}
|
||||
|
||||
/// (head, start, end) of each shot in replay ticks.
|
||||
fn spans(rec: &Recording, floor: f64) -> Vec<(String, f64, f64)> {
|
||||
plan_event(rec, 0, floor).iter().map(|s| (s.head.clone(), s.table[0], shot_end(s))).collect()
|
||||
}
|
||||
|
||||
// #77: the shots follow the real intervals: replay time never runs back, the launch is not after
|
||||
// the kill, nothing about the interceptor is shown before its first point.
|
||||
#[test]
|
||||
fn a_short_interception_is_cut_in_the_order_it_happened() {
|
||||
// The issue's case (flight 100 to 105), then 1, 5, 15 and 100+ ticks, the kill near the
|
||||
// start and near the end of the recording, and a gun kill.
|
||||
let cases = [(100, 105, true, 400), (100, 101, true, 400), (100, 105, true, 120), (100, 115, true, 400), (100, 260, true, 400), (3, 8, true, 400), (0, 4, true, 30), (0, 300, true, 300), (250, 255, false, 400), (5, 12, false, 400)];
|
||||
for (launch, kill, missile, len) in cases {
|
||||
let rec = intercept(len, launch, kill, missile);
|
||||
let sp = spans(&rec, 0.0);
|
||||
assert!(!sp.is_empty(), "{launch}->{kill}");
|
||||
let mut prev_end = 0.0;
|
||||
for (head, a, b) in &sp {
|
||||
assert!(b >= a, "{launch}->{kill} {head}: {a}..{b}");
|
||||
assert!(*a >= prev_end - 1e-9, "{launch}->{kill}: {head} starts at {a}, before the shot before it ended at {prev_end}: {sp:?}");
|
||||
prev_end = *b;
|
||||
if head == "Пуск" || head == "Сближение" {
|
||||
assert!(*a >= launch as f64 - 1e-9 && *b <= kill as f64, "{launch}->{kill}: {head} {a}..{b} outside the flight");
|
||||
}
|
||||
}
|
||||
// The launch comes before the close-up of the kill, which holds the kill itself.
|
||||
let close = sp.iter().position(|s| s.0 == "Поражение цели").expect("close-up");
|
||||
assert!(sp[..close].iter().all(|s| s.2 <= kill as f64 + 1e-9), "{launch}->{kill}: {sp:?}");
|
||||
assert!(sp[close].2 >= kill as f64 || sp[close].2 >= len as f64 - 1.0, "{launch}->{kill}: {sp:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_second_event_does_not_run_the_film_back() {
|
||||
let rec = intercept(600, 100, 300, true);
|
||||
// The previous event's last shot ended late: this one starts there.
|
||||
let sp = spans(&rec, 180.0);
|
||||
assert!(sp.iter().all(|s| s.1 >= 180.0 - 1e-9), "{sp:?}");
|
||||
}
|
||||
}
|
||||
|
||||
+69
-16
@@ -81,6 +81,8 @@ struct AirDef {
|
||||
export: Option<Export>,
|
||||
/// The effects preset a film replaced: (shader, hd).
|
||||
film_prev: Option<(bool, bool)>,
|
||||
/// Counts the replay/film sessions started; an export belongs to the one it began with.
|
||||
session: u64,
|
||||
/// The world drawn beyond the render distance (replays and cameras see far off).
|
||||
far: bool,
|
||||
/// The game's log of block changes (`render.world-log-start`): a replay shows the world as
|
||||
@@ -130,11 +132,22 @@ enum Stage {
|
||||
Finishing,
|
||||
}
|
||||
struct Export {
|
||||
/// The session (`AirDef::session`) whose film this export records.
|
||||
session: u64,
|
||||
opts: ExportOpts,
|
||||
stage: Stage,
|
||||
ticks: u32,
|
||||
}
|
||||
|
||||
/// Whether a replay or film may be started now: not while an export records (stop it first).
|
||||
fn switch_allowed(exporting: bool) -> Result<(), String> {
|
||||
if exporting {
|
||||
Err("Экспорт идёт: дождитесь конца или /airdef replay stop".into())
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// A sound heard later: when, what, where, and how loud and high it was.
|
||||
struct PendingSound {
|
||||
due: u64,
|
||||
@@ -426,13 +439,18 @@ impl AirDef {
|
||||
/// The searchlights' spot lights (HD): a cone from the head along its real direction, as far
|
||||
/// as the beam runs free; at most 16, the renderer draws the nearest.
|
||||
fn spots(&self) -> Vec<SpotLight> {
|
||||
if self.shown().replay {
|
||||
return Vec::new();
|
||||
}
|
||||
self.sim
|
||||
.sams
|
||||
.iter()
|
||||
.filter_map(|s| s.spot_beam())
|
||||
let shown = self.shown();
|
||||
// A replay lights with the recording's searchlights, where and as they pointed.
|
||||
let beams: Vec<sim::lights::Beam> = if shown.replay {
|
||||
match self.replay.as_ref().and_then(|r| self.sim.replay(r.rec).map(|rec| rec.beams(f64::from(shown.now)))) {
|
||||
Some(b) => b,
|
||||
None => Vec::new(),
|
||||
}
|
||||
} else {
|
||||
self.sim.sams.iter().filter_map(|s| s.spot_beam()).collect()
|
||||
};
|
||||
beams
|
||||
.into_iter()
|
||||
.take(16)
|
||||
.map(|b| SpotLight {
|
||||
id: b.id,
|
||||
@@ -536,13 +554,11 @@ impl AirDef {
|
||||
if !shown.replay {
|
||||
return (self.sim.tick as f64, self.smoke.segments(&self.sim));
|
||||
}
|
||||
let blasts = std::mem::replace(&mut self.sim.blasts, shown.blasts);
|
||||
let fires = std::mem::take(&mut self.sim.fires.list);
|
||||
let tick = std::mem::replace(&mut self.sim.tick, shown.now as u64);
|
||||
let segments = smoke::Smoke::default().segments(&self.sim);
|
||||
self.sim.blasts = blasts;
|
||||
self.sim.fires.list = fires;
|
||||
self.sim.tick = tick;
|
||||
// The recording alone, as a function of its time: the live Sim is not touched.
|
||||
let segments = match self.sim.replay(self.replay.as_ref().map_or(0, |r| r.rec)) {
|
||||
Some(rec) => smoke::replay_smoke(rec, f64::from(shown.now)),
|
||||
None => Vec::new(),
|
||||
};
|
||||
(f64::from(shown.now), segments)
|
||||
}
|
||||
|
||||
@@ -962,6 +978,7 @@ impl AirDef {
|
||||
|
||||
/// Plays the last recorded raid: "map", "full", "reel" or (with `event`) a clip.
|
||||
fn start_replay(&mut self, what: &str, event: Option<usize>) -> Result<(), String> {
|
||||
switch_allowed(self.export.is_some())?;
|
||||
let n = self.sim.replays.len();
|
||||
if n == 0 {
|
||||
return Err("Повторов пока нет: запишется первый же налёт (когда небо очистится)".into());
|
||||
@@ -980,7 +997,11 @@ impl AirDef {
|
||||
_ => replay::Mode::Map,
|
||||
};
|
||||
self.say_block_log(rec);
|
||||
self.replay = Some(replay::Player::new(rec.number, mode, &self.sim));
|
||||
let player = replay::Player::new(rec.number, mode, &self.sim);
|
||||
// A film (its quality and effects) or another replay ends properly before this one.
|
||||
self.end_session();
|
||||
self.session += 1;
|
||||
self.replay = Some(player);
|
||||
self.grid = false;
|
||||
input::claim_wheel(true);
|
||||
Ok(())
|
||||
@@ -991,6 +1012,12 @@ impl AirDef {
|
||||
render::capture_stop(true);
|
||||
say("Экспорт отменён");
|
||||
}
|
||||
self.end_session();
|
||||
}
|
||||
|
||||
/// Ends whatever replay or film shows, on every path: the film quality, the effects, the
|
||||
/// clean HUD, the views and the time and camera overrides go back to the live game's.
|
||||
fn end_session(&mut self) {
|
||||
render::set_film_quality(false);
|
||||
if let Some((shader, hd)) = self.film_prev.take() {
|
||||
self.set_effects(shader, hd);
|
||||
@@ -1007,6 +1034,9 @@ impl AirDef {
|
||||
|
||||
/// Plays the director's film of the last raid at the best quality: HD effects on (restored after).
|
||||
fn start_film(&mut self, which: &str, export: Option<&ExportOpts>) -> Result<(), String> {
|
||||
if export.is_none() {
|
||||
switch_allowed(self.export.is_some())?;
|
||||
}
|
||||
let n = self.sim.replays.len();
|
||||
if n == 0 {
|
||||
return Err("Повторов пока нет: запишется первый же налёт (когда небо очистится)".into());
|
||||
@@ -1025,6 +1055,9 @@ impl AirDef {
|
||||
player.clean = true;
|
||||
player.limit = o.seconds;
|
||||
}
|
||||
// What was shown ends first (its effects are remembered below, not lost).
|
||||
self.end_session();
|
||||
self.session += 1;
|
||||
self.replay = Some(player);
|
||||
self.grid = false;
|
||||
input::claim_wheel(true);
|
||||
@@ -1068,13 +1101,20 @@ impl AirDef {
|
||||
let which = o.which.clone();
|
||||
self.start_film(&which, Some(&o))?;
|
||||
say(&format!("Экспорт «{}»: {} fps, {}x{}; планирую кадры…", o.name, o.fps, o.size.0, o.size.1));
|
||||
self.export = Some(Export { opts: o, stage: Stage::Planning, ticks: 0 });
|
||||
self.export = Some(Export { session: self.session, opts: o, stage: Stage::Planning, ticks: 0 });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Drives an export: plan, start the recorder, wait for its first frame, report, stop at the end.
|
||||
fn export_step(&mut self, r: &mut replay::Player) {
|
||||
let Some(ex) = &mut self.export else { return };
|
||||
if ex.session != self.session {
|
||||
// The film this export recorded was replaced: the recorder stops, nothing else drives it.
|
||||
render::capture_stop(true);
|
||||
self.export = None;
|
||||
say("Экспорт отменён: показ заменён другим");
|
||||
return;
|
||||
}
|
||||
ex.ticks += 1;
|
||||
let st = render::capture_status();
|
||||
let failed = |s: &render::CaptureState| s.phase == render::CapturePhase::Failed;
|
||||
@@ -1349,6 +1389,7 @@ impl Mod for AirDef {
|
||||
time_view: false,
|
||||
export: None,
|
||||
film_prev: None,
|
||||
session: 0,
|
||||
smoke: Default::default(),
|
||||
far: true,
|
||||
moving: None,
|
||||
@@ -1913,3 +1954,15 @@ impl Mod for AirDef {
|
||||
}
|
||||
|
||||
horizon_mod_sdk::export_mod!(AirDef);
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// #83: while an export records no other replay or film replaces it; after it, they may.
|
||||
#[test]
|
||||
fn nothing_replaces_a_running_export() {
|
||||
assert!(switch_allowed(true).is_err());
|
||||
assert!(switch_allowed(false).is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,17 @@ use crate::sim::{Class, DroneKind, Out, Sim};
|
||||
use glam::DVec3;
|
||||
use horizon_mod_sdk::render::{CameraView, FillShape, Point, QuadShape, Rect, Shape, TextShape};
|
||||
|
||||
/// Metres the camera keeps above the surface (land or water) it stands over.
|
||||
const SURFACE_CLEAR: f64 = 2.5;
|
||||
|
||||
/// `eye` lifted above the surface under it (`Ground::land_state`: unanswered or no land: unchanged).
|
||||
fn above_surface(eye: DVec3, land: Option<Option<f64>>) -> DVec3 {
|
||||
match land {
|
||||
Some(Some(h)) if eye.y < h + SURFACE_CLEAR => DVec3::new(eye.x, h + SURFACE_CLEAR, eye.z),
|
||||
_ => eye,
|
||||
}
|
||||
}
|
||||
|
||||
/// Ghost models' ids, clear of the live ones.
|
||||
const GHOSTS: u32 = 0x5000_0000;
|
||||
/// The camera view's id (a new one each cut, so the game doesn't sweep between shots).
|
||||
@@ -419,7 +430,7 @@ impl Player {
|
||||
return;
|
||||
}
|
||||
sim.draw_ghosts(rec, self.t, GHOSTS, out);
|
||||
self.direct(rec);
|
||||
self.direct(rec, ground);
|
||||
self.sounds(rec, listener, out);
|
||||
}
|
||||
|
||||
@@ -565,7 +576,7 @@ impl Player {
|
||||
}
|
||||
|
||||
/// The event the camera films now: (eye, look, fov, shot).
|
||||
fn shoot(&mut self, rec: &Recording, i: usize) -> (DVec3, DVec3, f32, u8) {
|
||||
fn shoot(&mut self, rec: &Recording, i: usize, ground: &mut Ground) -> (DVec3, DVec3, f32, u8) {
|
||||
let e = rec.events[i];
|
||||
let t = self.t;
|
||||
let te = e.at as f64;
|
||||
@@ -602,6 +613,10 @@ impl Player {
|
||||
None => {
|
||||
// A gun kill, from the gun.
|
||||
let at = rec.sam(sam).map_or(e.pos + DVec3::Y * 20.0, |s| s.1 + DVec3::Y * 4.0);
|
||||
// A system on the sea floor (or a lake's) must not film from under the water:
|
||||
// the game's ground height is the top of the highest block that blocks motion
|
||||
// or holds a fluid, i.e. the water's surface there.
|
||||
let at = above_surface(at, ground.land_state(at));
|
||||
let dist = target.distance(at).max(1.0);
|
||||
let fov = (2.0 * (10.0 / dist).atan()).to_degrees().clamp(6.0, 60.0) as f32;
|
||||
(at, target, fov, 1)
|
||||
@@ -630,7 +645,7 @@ impl Player {
|
||||
}
|
||||
|
||||
/// Chooses the shot and moves the camera; a new shot is a cut.
|
||||
fn direct(&mut self, rec: &Recording) {
|
||||
fn direct(&mut self, rec: &Recording, ground: &mut Ground) {
|
||||
let focus = match &self.mode {
|
||||
Mode::Clips { list, at, .. } => Some(list[*at].event),
|
||||
// The full replay follows what comes next: the next event within 6 s, else the drone
|
||||
@@ -644,7 +659,7 @@ impl Player {
|
||||
};
|
||||
let (eye, look, fov, shot) = match focus {
|
||||
Some(i) => {
|
||||
let s = self.shoot(rec, i);
|
||||
let s = self.shoot(rec, i, ground);
|
||||
(s.0, s.1, s.2, (i, s.3))
|
||||
}
|
||||
None => {
|
||||
@@ -957,3 +972,21 @@ impl Player {
|
||||
Mode::Clips { list: vec![clip(rec, i)], at: 0, reel: false }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod surface_tests {
|
||||
use super::*;
|
||||
|
||||
/// A gun standing on the sea floor films from above the water, not from under it.
|
||||
#[test]
|
||||
fn the_gun_camera_is_lifted_above_the_water() {
|
||||
let eye = DVec3::new(10.0, 44.0, 5.0); // 4 above a Gepard on the floor at 40
|
||||
let lifted = above_surface(eye, Some(Some(62.0))); // the surface
|
||||
assert!(lifted.y >= 62.0 + SURFACE_CLEAR - 1e-9);
|
||||
assert_eq!((lifted.x, lifted.z), (10.0, 5.0));
|
||||
// On dry land, or with no answer yet, the camera stays where it was.
|
||||
assert_eq!(above_surface(DVec3::new(0.0, 74.0, 0.0), Some(Some(70.0))), DVec3::new(0.0, 74.0, 0.0));
|
||||
assert_eq!(above_surface(eye, None), eye);
|
||||
assert_eq!(above_surface(eye, Some(None)), eye);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ pub struct SamKey {
|
||||
pitch: f32,
|
||||
/// The antenna's turn.
|
||||
dish: f32,
|
||||
/// A searchlight's beam: how far it runs free (to 8 blocks), 0 when it is off.
|
||||
beam: f32,
|
||||
}
|
||||
|
||||
impl SamKey {
|
||||
@@ -30,6 +32,7 @@ impl SamKey {
|
||||
yaw: sam.yaw as f32,
|
||||
pitch: sam.pitch as f32,
|
||||
dish: sam.dish as f32,
|
||||
beam: if sam.beam_on { ((sam.beam_free / 8.0).round() * 8.0).max(8.0) as f32 } else { 0.0 },
|
||||
}
|
||||
}
|
||||
/// The same pose (to within what could be seen).
|
||||
@@ -40,6 +43,7 @@ impl SamKey {
|
||||
&& near(self.yaw, o.yaw, 0.002)
|
||||
&& near(self.pitch, o.pitch, 0.002)
|
||||
&& near(self.dish, o.dish, 0.002)
|
||||
&& self.beam == o.beam
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +83,7 @@ impl SamTrack {
|
||||
yaw: turn(a.yaw, b.yaw, f),
|
||||
pitch: l(a.pitch, b.pitch),
|
||||
dish: turn(a.dish, b.dish, f),
|
||||
beam: a.beam,
|
||||
})
|
||||
}
|
||||
/// The system as it stood at `t`, as a ghost to draw with the ids from `id`.
|
||||
@@ -89,11 +94,54 @@ impl SamTrack {
|
||||
sam.yaw = k.yaw as f64;
|
||||
sam.pitch = k.pitch as f64;
|
||||
sam.dish = k.dish as f64;
|
||||
sam.beam_on = k.beam > 0.0;
|
||||
sam.beam_free = k.beam as f64;
|
||||
sam.health = if self.lost.is_some_and(|l| t >= l as f64) { 0.0 } else { 1.0 };
|
||||
Some(sam)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl Recording {
|
||||
/// A recording of `len` ticks with nothing in it (for the planner's tests).
|
||||
pub(crate) fn blank(len: u32) -> Self {
|
||||
Recording {
|
||||
number: 1,
|
||||
origin: DVec3::ZERO,
|
||||
len,
|
||||
tracks: Vec::new(),
|
||||
index: HashMap::new(),
|
||||
events: Vec::new(),
|
||||
tally: Tally::default(),
|
||||
sams: Vec::new(),
|
||||
objects: Vec::new(),
|
||||
sam_tracks: Vec::new(),
|
||||
sam_index: HashMap::new(),
|
||||
ticks: Vec::new(),
|
||||
times: Vec::new(),
|
||||
quiet: 0,
|
||||
}
|
||||
}
|
||||
/// A straight track from `from` to `to` over the ticks `first..=last` (every `STEP`).
|
||||
pub(crate) fn straight(&mut self, id: u32, what: What, first: u32, last: u32, from: DVec3, to: DVec3) {
|
||||
let n = ((last - first) / STEP).max(1) as usize;
|
||||
let points = (0..=n).map(|k| {
|
||||
let p = from.lerp(to, k as f64 / n as f64);
|
||||
[p.x as f32, p.y as f32, p.z as f32]
|
||||
});
|
||||
self.index.insert(id, self.tracks.len());
|
||||
self.tracks.push(Track { id, what, first, points: points.collect(), fell: None });
|
||||
}
|
||||
}
|
||||
|
||||
impl Recording {
|
||||
/// The searchlights' beams at `t` as the recording had them (position and direction from the
|
||||
/// recorded poses, none for a lost light), never the live state.
|
||||
pub fn beams(&self, t: f64) -> Vec<lights::Beam> {
|
||||
self.sam_tracks.iter().filter_map(|st| st.ghost(self.origin, t, st.id)?.spot_beam()).collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// Ticks between a track's points.
|
||||
pub const STEP: u32 = 2;
|
||||
/// The longest recording (10 minutes) and how many are kept.
|
||||
@@ -244,6 +292,10 @@ impl Track {
|
||||
_ => DVec3::NEG_Z,
|
||||
}
|
||||
}
|
||||
/// Its `i`-th point (every `STEP` ticks from `first`), if it has one.
|
||||
pub fn sample(&self, origin: DVec3, i: usize) -> Option<DVec3> {
|
||||
self.points.get(i).map(|q| origin + DVec3::new(q[0] as f64, q[1] as f64, q[2] as f64))
|
||||
}
|
||||
/// The tick of its last point.
|
||||
pub fn last(&self) -> u32 {
|
||||
self.first + (self.points.len().max(1) as u32 - 1) * STEP
|
||||
@@ -587,6 +639,13 @@ impl Sim {
|
||||
units::draw_sam_model(&ghost, &mut rng, out);
|
||||
}
|
||||
}
|
||||
// The protected objects as marked in the raid (struck ones shrink), not the live ones.
|
||||
for (i, p) in rec.objects.iter().enumerate() {
|
||||
let struck = rec.events.iter().any(|e| e.at as f64 <= t && matches!(e.kind, EventKind::Hit { object: Some(o), .. } if o == i));
|
||||
let bob = (t * 0.1 + i as f64).sin() * 0.25;
|
||||
let rot = DQuat::from_rotation_y(t * 0.08);
|
||||
out.model(base + 0x00e0_0000 + i as u32 * PARTS, "airdef:target", *p + DVec3::Y * (1.6 + bob), rot, if struck { 0.4 } else { 0.8 }, true);
|
||||
}
|
||||
// Fires: what the events left burning (the flames dim and the smoke thickens with time),
|
||||
// out when their life ends.
|
||||
for f in replay_fires(rec, t) {
|
||||
@@ -673,6 +732,32 @@ mod tests {
|
||||
assert!((pose(100.0).pos[0] - 4.0).abs() < 1e-6);
|
||||
}
|
||||
|
||||
// #76: a replay's searchlights point where the recording had them, from the recorded pose.
|
||||
#[test]
|
||||
fn a_replay_has_the_recorded_searchlight_beams() {
|
||||
let mut r = recording();
|
||||
let mut light = Sam::new(9, SamKind::Light, DVec3::new(10.0, 64.0, 0.0), 0.0);
|
||||
light.beam_on = true;
|
||||
light.beam_free = 300.0;
|
||||
light.yaw = 1.0;
|
||||
light.pitch = 0.8;
|
||||
r.note_sams(&[light], 0);
|
||||
// Swung round and switched off later.
|
||||
let mut later = Sam::new(9, SamKind::Light, DVec3::new(10.0, 64.0, 0.0), 0.0);
|
||||
later.yaw = 2.0;
|
||||
later.pitch = 0.8;
|
||||
r.note_sams(&[later], 100);
|
||||
assert!(r.beams(-1.0).is_empty(), "nothing before it was seen");
|
||||
let b = r.beams(0.0);
|
||||
assert_eq!(b.len(), 1);
|
||||
assert_eq!(b[0].id, 9);
|
||||
assert!((b[0].free - 304.0).abs() < 1e-6 || (b[0].free - 296.0).abs() < 1e-6, "free {}", b[0].free);
|
||||
assert!(b[0].dir.y > 0.5, "pointing up: {:?}", b[0].dir);
|
||||
assert!(r.beams(100.0).is_empty(), "switched off");
|
||||
r.sam_tracks[0].lost = Some(50);
|
||||
assert!(r.beams(10.0).len() == 1 && r.beams(60.0).is_empty(), "a lost light has no beam");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_system_first_seen_later_is_not_drawn_before() {
|
||||
let mut r = recording();
|
||||
|
||||
@@ -654,6 +654,69 @@ fn replay_fires_and_blasts_follow_the_recording() {
|
||||
assert!(record::replay_blasts(&rec, 10.0 + a[0].life as f64).is_empty(), "burnt out");
|
||||
}
|
||||
|
||||
// #78: a replay's smoke is rebuilt from the recording as a function of its time: trails behind
|
||||
// what flew (clearing the fog), a column over the fire, billows that outlive the fireball; a seek
|
||||
// shows what playing through shows, and the live Sim is not touched.
|
||||
#[test]
|
||||
fn replay_smoke_has_trails_and_fire_columns_and_is_a_function_of_time() {
|
||||
use record::{Event, EventKind};
|
||||
let mut sim = Sim::new(1);
|
||||
sim.add_drone(DroneKind::Geran3, DVec3::new(0.0, 80.0, 0.0), DVec3::Z, DVec3::new(0.0, 70.0, 2000.0));
|
||||
sim.add_drone(DroneKind::Geran3, DVec3::new(30.0, 80.0, 0.0), DVec3::Z, DVec3::new(30.0, 70.0, 2000.0));
|
||||
let mut g = Ground::default();
|
||||
let mut out = Out::default();
|
||||
for _ in 0..160 {
|
||||
sim.step(&mut g, None, &mut out);
|
||||
}
|
||||
let mut rec = sim.rec.take().unwrap();
|
||||
assert_eq!(rec.tracks.len(), 2);
|
||||
rec.events = vec![Event { at: 40, pos: DVec3::new(5.0, 70.0, 5.0), kind: EventKind::Hit { drone: 1, kind: DroneKind::Geran3, power: 2, object: None, sam: None } }];
|
||||
let live_tick = sim.tick;
|
||||
let live_fires = sim.fires.list.len();
|
||||
let t = 130.0;
|
||||
let a = crate::smoke::replay_smoke(&rec, t);
|
||||
let trails = a.iter().filter(|s| s.clear > 0.0).count();
|
||||
let columns = a.iter().filter(|s| s.soot > 0.8).count();
|
||||
let billows = a.iter().filter(|s| s.soot == 0.55).count();
|
||||
assert!(trails > 0, "trails of both tracks: {trails}");
|
||||
assert!(columns > 0, "a column over the fire: {columns}");
|
||||
assert!(billows > 0, "the blast's billows");
|
||||
// Seeking away and back, or forward from nothing, gives the same smoke.
|
||||
let _ = crate::smoke::replay_smoke(&rec, 10.0);
|
||||
let _ = crate::smoke::replay_smoke(&rec, 155.0);
|
||||
let b = crate::smoke::replay_smoke(&rec, t);
|
||||
assert_eq!(a.iter().map(|s| (s.id, s.born as u64)).collect::<Vec<_>>(), b.iter().map(|s| (s.id, s.born as u64)).collect::<Vec<_>>());
|
||||
// Nothing from the future; before the raid, nothing.
|
||||
assert!(a.iter().all(|s| s.born <= t));
|
||||
assert!(crate::smoke::replay_smoke(&rec, -5.0).is_empty());
|
||||
// The billows go on long after the short fireball is out.
|
||||
let late = crate::smoke::replay_smoke(&rec, 400.0);
|
||||
assert!(late.iter().any(|s| s.soot == 0.55));
|
||||
// The live state is not touched.
|
||||
assert_eq!((sim.tick, sim.fires.list.len()), (live_tick, live_fires));
|
||||
}
|
||||
|
||||
// #76: the protected objects of a replay are the recording's, not the live marks.
|
||||
#[test]
|
||||
fn a_replay_draws_the_recorded_objects_not_the_live_ones() {
|
||||
let mut sim = Sim::new(1);
|
||||
sim.targets.push(DVec3::new(0.0, 70.0, 0.0));
|
||||
sim.target_health.push(100.0);
|
||||
sim.add_drone(DroneKind::Geran3, DVec3::new(0.0, 80.0, 0.0), DVec3::Z, DVec3::new(0.0, 70.0, 500.0));
|
||||
let mut g = Ground::default();
|
||||
let mut out = Out::default();
|
||||
sim.step(&mut g, None, &mut out);
|
||||
let rec = sim.rec.take().unwrap();
|
||||
assert_eq!(rec.objects.len(), 1);
|
||||
// The live mark is moved away after the raid; the replay still shows it where it was.
|
||||
sim.targets[0] = DVec3::new(900.0, 70.0, 900.0);
|
||||
let mut shown = Out::default();
|
||||
sim.draw_ghosts(&rec, 0.0, 0x1000, &mut shown);
|
||||
let marks: Vec<_> = shown.models.iter().filter(|m| m.name == "airdef:target").collect();
|
||||
assert_eq!(marks.len(), 1);
|
||||
assert!(marks[0].at.x.abs() < 1.0 && marks[0].at.z.abs() < 1.0, "{:?}", marks[0].at);
|
||||
}
|
||||
|
||||
fn sim_first(r: &record::Recording) -> u64 {
|
||||
r.tracks.first().map_or(0, |t| t.first as u64)
|
||||
}
|
||||
|
||||
+148
-67
@@ -47,6 +47,150 @@ fn seg(id: u32, a: DVec3, b: DVec3, born: u64, life: u32) -> SmokeSegment {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// The column over one fire up to `tick`: a puff every 15 ticks (90 for the weaker fires) that
|
||||
/// rises, spreads and thins. A pure function of the tick.
|
||||
fn fire_column(out: &mut Vec<SmokeSegment>, fire_id: u32, at: DVec3, start: u64, size: f32, shown: bool, tick: u64, level: &dyn Fn(u64) -> (f32, f32)) {
|
||||
// Only the strongest fires get a full column; the rest a thin puff now and then.
|
||||
let step = if shown { 15 } else { 90 };
|
||||
let first = start.max(tick.saturating_sub(520));
|
||||
let mut k = first.div_ceil(step) * step;
|
||||
while k <= tick && out.len() < MAX_TOTAL {
|
||||
let (flame, smoke) = level(k);
|
||||
if smoke > 0.05 && k >= start {
|
||||
let id = 0x4000_0000 | (fire_id.wrapping_mul(131) ^ (k / step) as u32) & 0x3fff_ffff;
|
||||
let at = at + DVec3::Y * 0.6;
|
||||
let mut s = seg(id, at, at, k, 540);
|
||||
s.radius_start = 1.0 * size;
|
||||
s.radius_end = 8.0 * size + 2.0;
|
||||
s.density = 2.6 * smoke * size.sqrt() * if shown { 1.0 } else { 0.5 };
|
||||
s.heat = flame * 0.6;
|
||||
s.soot = 0.85;
|
||||
s.rise = 2.6;
|
||||
out.push(s);
|
||||
}
|
||||
k += step;
|
||||
}
|
||||
}
|
||||
|
||||
/// Blasts: a billow of puffs going up, for 900 ticks after each.
|
||||
fn blast_billows(out: &mut Vec<SmokeSegment>, blasts: &[crate::sim::Blast], tick: u64) {
|
||||
for b in blasts {
|
||||
let age = tick.saturating_sub(b.start);
|
||||
if age > 900 {
|
||||
continue;
|
||||
}
|
||||
for j in 0..6u64 {
|
||||
let born = b.start + j * 3;
|
||||
if born > tick {
|
||||
break;
|
||||
}
|
||||
let h = b.size as f64 * (0.2 + 0.5 * j as f64);
|
||||
let at = b.at + DVec3::Y * h;
|
||||
let mut s = seg(0x5000_0000 | (b.id.wrapping_mul(7) + j as u32) & 0x0fff_ffff, at, at, born, 800);
|
||||
s.radius_start = b.size * 0.6;
|
||||
s.radius_end = b.size * 3.2 + 4.0;
|
||||
s.density = 2.4 / (1.0 + j as f32 * 0.25);
|
||||
s.heat = if j < 3 { 1.0 } else { 0.4 };
|
||||
s.soot = 0.55;
|
||||
s.rise = 4.0 - 0.3 * j as f32;
|
||||
out.push(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn style_drone(s: &mut SmokeSegment, class: Class) {
|
||||
let (r0, r1, dens, heat, soot, clear, life): (f32, f32, f32, f32, f32, f32, f32) = match class {
|
||||
Class::Drone => (0.9, 5.0, 2.0, 0.0, 0.45, 3.0, 1200.0),
|
||||
Class::Jet | Class::Cruise => (1.1, 7.0, 2.5, 0.15, 0.35, 4.0, 1300.0),
|
||||
Class::Supersonic => (1.4, 9.0, 3.2, 0.5, 0.2, 5.0, 1300.0),
|
||||
Class::Ballistic => (2.0, 13.0, 4.0, 0.7, 0.15, 7.0, 1500.0),
|
||||
};
|
||||
s.radius_start = r0;
|
||||
s.radius_end = r1;
|
||||
s.density = dens;
|
||||
s.heat = heat;
|
||||
s.soot = soot;
|
||||
s.clear = clear;
|
||||
s.life = life;
|
||||
}
|
||||
|
||||
fn style_missile(s: &mut SmokeSegment) {
|
||||
s.radius_start = 0.6;
|
||||
s.radius_end = 5.0;
|
||||
s.density = 3.0;
|
||||
s.heat = 0.8;
|
||||
s.soot = 0.05;
|
||||
s.clear = 3.0;
|
||||
s.life = 1000.0;
|
||||
}
|
||||
|
||||
/// Points between a replay trail segment's ends (a segment every `TRAIL_GRID * STEP` ticks).
|
||||
const TRAIL_GRID: usize = 4;
|
||||
|
||||
/// The smoke a recording shows at its tick `t`: trails behind everything that flew, columns over
|
||||
/// the fires its events lit, billows over its blasts. A pure function of `t` (nothing is kept
|
||||
/// between calls, so a seek, a pause or a cut shows exactly what playing through would), and it
|
||||
/// touches no live state. Trail segments sit on a fixed grid of each track's points.
|
||||
pub fn replay_smoke(rec: &crate::sim::record::Recording, t: f64) -> Vec<SmokeSegment> {
|
||||
use crate::sim::record::{STEP, What};
|
||||
let tick = t.max(0.0) as u64;
|
||||
let mut out: Vec<SmokeSegment> = Vec::new();
|
||||
let stride = (TRAIL_GRID as u32 * STEP) as f64;
|
||||
for (n, tr) in rec.tracks.iter().enumerate() {
|
||||
let (life, style): (f64, Box<dyn Fn(&mut SmokeSegment)>) = match tr.what {
|
||||
What::Drone(kind) => {
|
||||
let class = kind.spec().class;
|
||||
let mut probe = seg(0, DVec3::ZERO, DVec3::ZERO, 0, 0);
|
||||
style_drone(&mut probe, class);
|
||||
(probe.life as f64, Box::new(move |s| style_drone(s, class)))
|
||||
}
|
||||
What::Missile(..) => (1000.0, Box::new(style_missile)),
|
||||
};
|
||||
// The segments whose end point has been reached and whose life is not over.
|
||||
let lo = (((t - life - tr.first as f64) / stride).floor().max(0.0)) as usize;
|
||||
let hi = (((t - tr.first as f64) / stride).floor().max(0.0)) as usize;
|
||||
for g in lo.max(1)..=hi {
|
||||
let (Some(a), Some(b)) = (tr.sample(rec.origin, (g - 1) * TRAIL_GRID), tr.sample(rec.origin, g * TRAIL_GRID)) else { break };
|
||||
let born = tr.first as u64 + (g * TRAIL_GRID) as u64 * STEP as u64;
|
||||
if born > tick || a.distance(b) >= 400.0 {
|
||||
continue;
|
||||
}
|
||||
let mut s = seg(0x2000_0000 | ((n as u32).wrapping_mul(7919) ^ g as u32) & 0x0fff_ffff, a, b, born, 1200);
|
||||
style(&mut s);
|
||||
if (tick as f64) < born as f64 + s.life as f64 {
|
||||
out.push(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
if out.len() > MAX_TRAIL {
|
||||
out.sort_by_key(|s| s.born as u64);
|
||||
let cut = out.len() - MAX_TRAIL;
|
||||
out.drain(..cut);
|
||||
}
|
||||
// Fires, the strongest dozen in full (as the live ones are).
|
||||
let mut fires = crate::sim::record::replay_fires(rec, t);
|
||||
fires.sort_by(|a, b| b.size.total_cmp(&a.size).then(a.start.cmp(&b.start)));
|
||||
for (rank, f) in fires.iter().enumerate() {
|
||||
let life = f.life as f64;
|
||||
fire_column(&mut out, 0x1000_0000 | f.key as u32, f.at, f.start as u64, f.size, rank < crate::sim::fires::MAX, tick, &|k| crate::sim::fires::level(k.saturating_sub(f.start as u64) as f64, life));
|
||||
}
|
||||
// Blasts keep their billows long after the fireball is out.
|
||||
let blasts: Vec<crate::sim::Blast> = rec
|
||||
.events
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, e)| e.at as u64 <= tick)
|
||||
.map(|(k, e)| {
|
||||
let (size, life) = crate::sim::record::blast_spec(e.kind);
|
||||
crate::sim::Blast { id: 0x4000_0000 | k as u32, at: e.pos, size, start: e.at as u64, life }
|
||||
})
|
||||
.collect();
|
||||
blast_billows(&mut out, &blasts, tick);
|
||||
out.truncate(MAX_TOTAL);
|
||||
out
|
||||
}
|
||||
|
||||
impl Smoke {
|
||||
fn trail(&mut self, key: (u8, u32), at: DVec3, tick: u64, style: impl Fn(&mut SmokeSegment)) {
|
||||
let Some(&(from, when)) = self.last.get(&key) else {
|
||||
@@ -76,32 +220,10 @@ impl Smoke {
|
||||
self.last_tick = tick;
|
||||
for d in &sim.drones {
|
||||
let class = d.kind.spec().class;
|
||||
let (r0, r1, dens, heat, soot, clear, life): (f32, f32, f32, f32, f32, f32, f32) = match class {
|
||||
Class::Drone => (0.9, 5.0, 2.0, 0.0, 0.45, 3.0, 1200.0),
|
||||
Class::Jet | Class::Cruise => (1.1, 7.0, 2.5, 0.15, 0.35, 4.0, 1300.0),
|
||||
Class::Supersonic => (1.4, 9.0, 3.2, 0.5, 0.2, 5.0, 1300.0),
|
||||
Class::Ballistic => (2.0, 13.0, 4.0, 0.7, 0.15, 7.0, 1500.0),
|
||||
};
|
||||
self.trail((0, d.id), d.pos, tick, |s| {
|
||||
s.radius_start = r0;
|
||||
s.radius_end = r1;
|
||||
s.density = dens;
|
||||
s.heat = heat;
|
||||
s.soot = soot;
|
||||
s.clear = clear;
|
||||
s.life = life;
|
||||
});
|
||||
self.trail((0, d.id), d.pos, tick, |s| style_drone(s, class));
|
||||
}
|
||||
for m in &sim.missiles {
|
||||
self.trail((1, m.id), m.pos, tick, |s| {
|
||||
s.radius_start = 0.6;
|
||||
s.radius_end = 5.0;
|
||||
s.density = 3.0;
|
||||
s.heat = 0.8;
|
||||
s.soot = 0.05;
|
||||
s.clear = 3.0;
|
||||
s.life = 1000.0;
|
||||
});
|
||||
self.trail((1, m.id), m.pos, tick, style_missile);
|
||||
}
|
||||
// Forget what is gone.
|
||||
if tick % 100 == 0 {
|
||||
@@ -129,50 +251,9 @@ impl Smoke {
|
||||
if f.quiet && f.size < 1.0 {
|
||||
continue;
|
||||
}
|
||||
// Only the strongest fires get a full column; the rest a thin puff now and then.
|
||||
let step = if f.shown { 15 } else { 90 };
|
||||
let first = f.start.max(tick.saturating_sub(520));
|
||||
let mut k = first.div_ceil(step) * step;
|
||||
while k <= tick && out.len() < MAX_TOTAL {
|
||||
let (flame, smoke) = f.level(k);
|
||||
if smoke > 0.05 && k >= f.start {
|
||||
let id = 0x4000_0000 | (f.id.wrapping_mul(131) ^ (k / step) as u32) & 0x3fff_ffff;
|
||||
let at = f.at + DVec3::Y * 0.6;
|
||||
let mut s = seg(id, at, at, k, 540);
|
||||
s.radius_start = 1.0 * f.size;
|
||||
s.radius_end = 8.0 * f.size + 2.0;
|
||||
s.density = 2.6 * smoke * f.size.sqrt() * if f.shown { 1.0 } else { 0.5 };
|
||||
s.heat = flame * 0.6;
|
||||
s.soot = 0.85;
|
||||
s.rise = 2.6;
|
||||
out.push(s);
|
||||
}
|
||||
k += step;
|
||||
}
|
||||
}
|
||||
// Blasts: a billow of puffs going up.
|
||||
for b in &sim.blasts {
|
||||
let age = tick.saturating_sub(b.start);
|
||||
if age > 900 {
|
||||
continue;
|
||||
}
|
||||
for j in 0..6u64 {
|
||||
let born = b.start + j * 3;
|
||||
if born > tick {
|
||||
break;
|
||||
}
|
||||
let h = b.size as f64 * (0.2 + 0.5 * j as f64);
|
||||
let at = b.at + DVec3::Y * h;
|
||||
let mut s = seg(0x5000_0000 | (b.id.wrapping_mul(7) + j as u32) & 0x0fff_ffff, at, at, born, 800);
|
||||
s.radius_start = b.size * 0.6;
|
||||
s.radius_end = b.size * 3.2 + 4.0;
|
||||
s.density = 2.4 / (1.0 + j as f32 * 0.25);
|
||||
s.heat = if j < 3 { 1.0 } else { 0.4 };
|
||||
s.soot = 0.55;
|
||||
s.rise = 4.0 - 0.3 * j as f32;
|
||||
out.push(s);
|
||||
}
|
||||
fire_column(&mut out, f.id, f.at, f.start, f.size, f.shown, tick, &|k| f.level(k));
|
||||
}
|
||||
blast_billows(&mut out, &sim.blasts, tick);
|
||||
out.truncate(MAX_TOTAL);
|
||||
out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user