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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user