Replays in full HD with shader effects driven by the recording (#56), recorded clock survives gaps (#57), cinematic intercepts: layered sound with travel delay, big flash, light burst, exposure punch, shock ring (#51) (fork patch 31)
build / mod (push) Successful in 3m21s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 03:59:47 +03:00
parent 4bab572293
commit 8a12225ba1
40 changed files with 1185 additions and 105 deletions
+111 -37
View File
@@ -114,9 +114,11 @@ pub struct Recording {
/// The systems and objects as they stood: (id, kind, where).
pub sams: Vec<(u32, SamKind, DVec3)>,
pub objects: Vec<DVec3>,
/// The world clock's time of day (ticks) every `TIME_STEP` ticks of the recording, from its
/// start: replays show the sky of the raid, not the current one. Empty when the clock was unknown.
times: Vec<u64>,
/// The world clock's time of day as (recording tick, day ticks), sampled on every
/// `TIME_STEP`-th tick the clock was known: replays show the sky of the raid, not the current
/// one. A tick the clock was unknown has no sample (a gap), so a late start or a lost clock
/// never shifts later samples; empty when the clock was never known.
times: Vec<(u32, u64)>,
/// Ticks the sky has been clear.
quiet: u32,
}
@@ -166,6 +168,86 @@ impl Track {
}
}
/// A fire as a replay shows it: what the events lit and kept alight, merged as the live fires are.
#[derive(Clone, Copy, Debug)]
pub struct ReplayFire {
pub at: DVec3,
/// The recording's tick it was lit.
pub start: u32,
pub life: u32,
pub size: f32,
/// The event that lit it (the models' ids).
pub key: usize,
}
/// The look of an interception by the drone's warhead: (fireball radius, ticks it burns, loudness).
/// A bare decoy pops; a big warhead lights the sky. The same in the live raid and its replay.
pub fn kill_look(kind: DroneKind) -> (f32, u32, f32) {
let w = kind.spec().warhead.min(8) as f32;
(3.5 * (0.85 + 0.12 * w), (8 + (w as u32) / 2) * 9, 1.0 + 0.06 * w)
}
/// A blast's look for an event: (fireball radius, ticks it burns). The live blasts use the same.
pub fn blast_spec(kind: EventKind) -> (f32, u32) {
const SIZE: [f32; 5] = [2.5, 4.5, 7.0, 10.0, 13.0];
const LIFE: [u32; 5] = [11, 11, 18, 22, 26];
match kind {
EventKind::Kill { kind, .. } => {
let (size, life, _) = kill_look(kind);
(size, life)
}
EventKind::Hit { power, .. } | EventKind::Crash { power, .. } => {
let p = (power as usize).min(4);
(SIZE[p], LIFE[p] * 9)
}
EventKind::SamLost { .. } => (8.0, 18 * 9),
EventKind::Split { .. } => (2.0, 7 * 9),
}
}
/// The blasts of the recording's events burning at `t` (its ticks, fractional): the same
/// `Blast`s the live simulation keeps, with `start` in the recording's ticks and the event's
/// own id range. A pure function of `t`, so a seek or a pause shows the same frame.
pub fn replay_blasts(rec: &Recording, t: f64) -> Vec<Blast> {
rec.events
.iter()
.enumerate()
.filter_map(|(k, e)| {
let (size, life) = blast_spec(e.kind);
let age = t - e.at as f64;
(0.0..life as f64).contains(&age).then_some(Blast { id: 0x4000_0000 | k as u32, at: e.pos, size, start: e.at as u64, life })
})
.collect()
}
/// The fires burning at `t` in the recording: events within 6 blocks of a fire still burning
/// feed it (the greater size, the longer life), as `Sim::ignite` does; those after it died light
/// a new one. A pure function of `t`.
pub fn replay_fires(rec: &Recording, t: f64) -> Vec<ReplayFire> {
let mut fires: Vec<ReplayFire> = Vec::new();
for (k, e) in rec.events.iter().enumerate() {
if e.at as f64 > t {
break;
}
let power = match e.kind {
EventKind::Crash { power, .. } => power,
EventKind::Hit { power, .. } => power.max(1),
EventKind::SamLost { .. } => 2,
_ => continue,
};
let (size, life) = (fires::size_for(power), fires::life_for(power));
let alive = |f: &ReplayFire| e.at < f.start + f.life;
if let Some(f) = fires.iter_mut().find(|f| alive(f) && f.at.distance(e.pos) < 6.0) {
f.size = f.size.max(size);
f.life = f.life.max(e.at - f.start + life);
} else {
fires.push(ReplayFire { at: e.pos, start: e.at, life, size, key: k });
}
}
fires.retain(|f| t < (f.start + f.life) as f64);
fires
}
impl Recording {
fn new(number: u32, sim: &Sim) -> Self {
let origin = sim.targets.first().copied().or_else(|| sim.sams.first().map(|s| s.pos)).unwrap_or(DVec3::ZERO);
@@ -199,12 +281,16 @@ impl Recording {
/// clock as sampled, run on between samples at the pace it ran (a jump is a step), or None
/// when the clock was not known (the replay then shows the world's own time).
pub fn day_time(&self, t: f64) -> Option<u64> {
let k = (t.max(0.0) / TIME_STEP as f64).floor() as usize;
let i = k.min(self.times.len().checked_sub(1)?);
let a = self.times[i];
let into = if i == k { t.max(0.0) - (i as u32 * TIME_STEP) as f64 } else { 0.0 };
let t = t.max(0.0);
// The last sample at or before `t`; none before the first one means unknown.
let i = self.times.partition_point(|s| s.0 as f64 <= t).checked_sub(1)?;
let (ta, a) = self.times[i];
match self.times.get(i + 1) {
Some(&b) if b >= a && b - a <= 2 * TIME_STEP as u64 => Some(a + ((b - a) as f64 * into / TIME_STEP as f64) as u64),
// Neighbouring samples with no gap between: run on at the pace between them.
Some(&(tb, b)) if tb - ta <= TIME_STEP && b >= a && b - a <= 2 * TIME_STEP as u64 => {
let f = ((t - ta as f64) / (tb - ta) as f64).clamp(0.0, 1.0);
Some(a + ((b - a) as f64 * f) as u64)
}
_ => Some(a),
}
}
@@ -271,9 +357,8 @@ impl Sim {
let Some(r) = &mut self.rec else { return };
if r.len % TIME_STEP == 0
&& let Some(dt) = self.day_time
&& r.times.len() == (r.len / TIME_STEP) as usize
{
r.times.push(dt);
r.times.push((r.len, dt));
}
if r.len % STEP == 0 {
for d in &self.drones {
@@ -349,43 +434,32 @@ impl Sim {
}
}
}
// Fires: what the events left burning (the flames dim and the smoke thickens with time).
let mut lit: Vec<(DVec3, f64)> = Vec::new();
for (k, e) in rec.events.iter().enumerate() {
let power = match e.kind {
EventKind::Crash { power, .. } => power,
EventKind::Hit { power, .. } => power.max(1),
EventKind::SamLost { .. } => 2,
_ => continue,
};
let age = t - e.at as f64;
// One fire where several events met.
if lit.iter().any(|(p, at)| p.distance(e.pos) < 6.0 && *at <= e.at as f64) {
continue;
}
lit.push((e.pos, e.at as f64));
let (flame, smoke) = fires::replay_fire(power, age);
let id = base + 0x00c0_0000 + k as u32 * PARTS;
// 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) {
let age = t - f.start as f64;
let (flame, smoke) = fires::replay_fire_of(f.size, f.life, age);
let id = base + 0x00c0_0000 + f.key as u32 * PARTS;
if flame > 0.05 {
let wob = 1.0 + 0.15 * (age * 0.9 + k as f64).sin();
out.model(id, "airdef:flame", e.pos + DVec3::Y * 0.5, DQuat::from_rotation_y(age * 0.07), (flame as f64 * 0.8 * wob).max(0.05), true);
let wob = 1.0 + 0.15 * (age * 0.9 + f.key as f64).sin();
out.model(id, "airdef:flame", f.at + DVec3::Y * 0.5, DQuat::from_rotation_y(age * 0.07), (flame as f64 * 0.8 * wob).max(0.05), true);
}
if smoke > 0.1 && (age as u64) % 3 == 0 {
out.particles("minecraft:large_smoke", e.pos + DVec3::Y, 0.8, DVec3::new(0.0, 0.1, 0.0), 0.03, 1 + (smoke * 2.0) as u32);
out.particles("minecraft:large_smoke", f.at + DVec3::Y, 0.8, DVec3::new(0.0, 0.1, 0.0), 0.03, 1 + (smoke * 2.0) as u32);
}
}
// Blasts: a fireball growing and fading for 1.5 s after each.
// Blasts: with the shader effects on, the post pass and the HD lights draw them from
// `replay_blasts` (the same as the live ones); the models are the fallback without them.
if self.shader {
return;
}
for (k, e) in rec.events.iter().enumerate() {
let age = t - e.at as f64;
if !(0.0..30.0).contains(&age) {
continue;
}
let size = match e.kind {
EventKind::Kill { .. } => 3.5,
EventKind::Hit { power, .. } | EventKind::Crash { power, .. } => [2.5, 4.5, 7.0, 10.0, 13.0][(power as usize).min(4)],
EventKind::SamLost { .. } => 8.0,
EventKind::Split { .. } => 2.0,
};
let (size, _) = blast_spec(e.kind);
let size = size as f64;
let f = age / 30.0;
let s = size * (f * 4.0).min(1.0) * (1.0 - f * f);
let id = base + 0x0080_0000 + k as u32 * PARTS;