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:
+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