Replays show SAMs and the world as it was at raid time, film clock for exports; clouds and fog polish; shared texture generator, new missile bodies, octagonal wheels, tracked sides, charred wrecks (#55 part 1) (fork patch 33)
build / mod (push) Successful in 3m54s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 14:30:39 +03:00
parent 76f680eba6
commit 438d68d50f
245 changed files with 45962 additions and 3798 deletions
+6 -5
View File
@@ -477,10 +477,11 @@ impl Sim {
self.fires.extinguish();
n
}
}
/// A wreck: the hull sunk and turned, the launcher or turret thrown down beside it.
pub(super) fn draw_wreck(&self, i: usize, out: &mut Out) {
let sam = &self.sams[i];
/// A wreck: the hull sunk and turned, the launcher or turret thrown down beside it (a live system's, or a replay's ghost).
pub(super) fn draw_wreck_of(sam: &Sam, out: &mut Out) {
{
let s = sam.kind.spec().scale;
let tilt = DQuat::from_rotation_y(sam.heading) * DQuat::from_rotation_z(0.12) * DQuat::from_rotation_x(-0.06);
let hull = sam.pos + DVec3::Y * (0.5 * s - 0.35);
@@ -488,9 +489,9 @@ impl Sim {
let thrown = DQuat::from_rotation_y(sam.heading + 1.1) * DQuat::from_rotation_z(1.2);
let parts = &sam.kind.spec().parts;
let (body, part) = (parts.body, parts.launcher.or(parts.pack));
out.model(sam.id, body, hull, tilt, s, false);
out.model(sam.id, super::units::wreck(body), hull, tilt, s, false);
if let Some(part) = part {
out.model(sam.id + 1, part, sam.pos + side + DVec3::Y * 0.4 * s, thrown, s, false);
out.model(sam.id + 1, super::units::wreck(part), sam.pos + side + DVec3::Y * 0.4 * s, thrown, s, false);
}
}
}
+3
View File
@@ -1395,6 +1395,8 @@ pub struct Sim {
next: u32,
pub rng: Rng,
pub tick: u64,
/// The game's tick number (the one `tick` is called with), for a recording to know the world's time by.
pub engine_tick: u64,
pub kills: u32,
pub hits: u32,
/// Drones that struck the land or a building short of their aim.
@@ -1460,6 +1462,7 @@ impl Sim {
next: 1,
rng: Rng::new(seed),
tick: 0,
engine_tick: 0,
kills: 0,
hits: 0,
crashes: 0,
+242 -4
View File
@@ -5,6 +5,95 @@
//! has been clear a while; the last few are kept.
use super::*;
/// A system's pose at a moment of a recording.
#[derive(Clone, Copy, PartialEq, Debug)]
pub struct SamKey {
/// The recording's tick.
pub at: u32,
/// Relative to the recording's origin.
pos: [f32; 3],
heading: f32,
/// Where the launcher or turret points.
yaw: f32,
pitch: f32,
/// The antenna's turn.
dish: f32,
}
impl SamKey {
fn of(sam: &Sam, origin: DVec3, at: u32) -> Self {
let p = sam.pos - origin;
SamKey {
at,
pos: [p.x as f32, p.y as f32, p.z as f32],
heading: sam.heading as f32,
yaw: sam.yaw as f32,
pitch: sam.pitch as f32,
dish: sam.dish as f32,
}
}
/// The same pose (to within what could be seen).
fn same(&self, o: &SamKey) -> bool {
let near = |a: f32, b: f32, e: f32| (a - b).abs() < e;
(0..3).all(|i| near(self.pos[i], o.pos[i], 0.01))
&& near(self.heading, o.heading, 0.002)
&& near(self.yaw, o.yaw, 0.002)
&& near(self.pitch, o.pitch, 0.002)
&& near(self.dish, o.dish, 0.002)
}
}
/// A system through a recording: its poses (a new one only when it changed, with the
/// stillness before it marked), and when it was lost.
pub struct SamTrack {
pub id: u32,
pub kind: SamKind,
pub keys: Vec<SamKey>,
/// The recording's tick it was destroyed.
pub lost: Option<u32>,
}
/// `a` turned toward `b` by `f` the short way round.
fn turn(a: f32, b: f32, f: f32) -> f32 {
let tau = std::f32::consts::TAU;
let d = (b - a + std::f32::consts::PI).rem_euclid(tau) - std::f32::consts::PI;
a + d * f
}
impl SamTrack {
/// The pose at `t` (the recording's ticks, fractional); None before the system was first seen.
pub fn pose(&self, t: f64) -> Option<SamKey> {
let first = self.keys.first()?;
if t < first.at as f64 {
return None;
}
let i = self.keys.partition_point(|k| k.at as f64 <= t).saturating_sub(1);
let a = self.keys[i];
let Some(b) = self.keys.get(i + 1) else { return Some(a) };
let f = ((t - a.at as f64) / (b.at - a.at).max(1) as f64).clamp(0.0, 1.0) as f32;
let l = |x: f32, y: f32| x + (y - x) * f;
Some(SamKey {
at: a.at,
pos: [l(a.pos[0], b.pos[0]), l(a.pos[1], b.pos[1]), l(a.pos[2], b.pos[2])],
heading: turn(a.heading, b.heading, f),
yaw: turn(a.yaw, b.yaw, f),
pitch: l(a.pitch, b.pitch),
dish: turn(a.dish, b.dish, f),
})
}
/// The system as it stood at `t`, as a ghost to draw with the ids from `id`.
pub fn ghost(&self, origin: DVec3, t: f64, id: u32) -> Option<Sam> {
let k = self.pose(t)?;
let pos = origin + DVec3::new(k.pos[0] as f64, k.pos[1] as f64, k.pos[2] as f64);
let mut sam = Sam::new(id, self.kind, pos, k.heading as f64);
sam.yaw = k.yaw as f64;
sam.pitch = k.pitch as f64;
sam.dish = k.dish as f64;
sam.health = if self.lost.is_some_and(|l| t >= l as f64) { 0.0 } else { 1.0 };
Some(sam)
}
}
/// Ticks between a track's points.
pub const STEP: u32 = 2;
/// The longest recording (10 minutes) and how many are kept.
@@ -114,6 +203,13 @@ pub struct Recording {
/// The systems and objects as they stood: (id, kind, where).
pub sams: Vec<(u32, SamKind, DVec3)>,
pub objects: Vec<DVec3>,
/// Every system's poses through the raid (the drawing of a replay: where it stood, which way
/// it pointed, whether it was still whole).
pub sam_tracks: Vec<SamTrack>,
sam_index: HashMap<u32, usize>,
/// The game's tick number as sampled with the clock: (recording tick, game tick). A replay
/// shows the world's blocks as of this time.
ticks: Vec<(u32, 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
@@ -261,10 +357,51 @@ impl Recording {
tally: Tally::default(),
sams: sim.sams.iter().map(|s| (s.id, s.kind, s.pos)).collect(),
objects: sim.targets.clone(),
sam_tracks: Vec::new(),
sam_index: HashMap::new(),
ticks: Vec::new(),
times: Vec::new(),
quiet: 0,
}
}
/// Notes the systems' poses at the recording's tick `now`: a pose only when it changed, with
/// the pose it held marked before it so a replay doesn't glide through the stillness.
fn note_sams(&mut self, sams: &[Sam], now: u32) {
for sam in sams {
let key = SamKey::of(sam, self.origin, now);
let i = *self.sam_index.entry(sam.id).or_insert_with(|| {
self.sam_tracks.push(SamTrack { id: sam.id, kind: sam.kind, keys: Vec::new(), lost: None });
self.sam_tracks.len() - 1
});
let track = &mut self.sam_tracks[i];
match track.keys.last().copied() {
None => track.keys.push(key),
Some(last) if last.same(&key) => {}
Some(last) => {
if last.at + STEP < now {
track.keys.push(SamKey { at: now - STEP, ..last });
}
track.keys.push(key);
}
}
}
}
/// The game's tick at the recording's tick `t` (fractional), if it was known: the samples run
/// on at the pace of the ticks between them (a pause or a gap is a step).
pub fn world_tick(&self, t: f64) -> Option<u64> {
let t = t.max(0.0);
let i = self.ticks.partition_point(|s| s.0 as f64 <= t).checked_sub(1).or(if self.ticks.is_empty() { None } else { Some(0) })?;
let (ta, a) = self.ticks[i];
let ahead = (t - ta as f64).max(0.0);
Some(match self.ticks.get(i + 1) {
Some(&(tb, b)) if b >= a && b - a <= 2 * (tb - ta).max(1) as u64 => a + (ahead.min((tb - ta) as f64) * (b - a) as f64 / (tb - ta).max(1) as f64) as u64,
_ => a + ahead as u64,
})
}
/// The game tick the recording began at.
pub fn first_tick(&self) -> Option<u64> {
self.ticks.first().map(|s| s.1)
}
fn point(&mut self, id: u32, what: What, pos: DVec3) {
let rel = pos - self.origin;
let q = [rel.x as f32, rel.y as f32, rel.z as f32];
@@ -337,6 +474,11 @@ impl Sim {
{
r.tracks[i].fell = Some(at);
}
if let EventKind::SamLost { sam, .. } = kind
&& let Some(&i) = r.sam_index.get(&sam)
{
r.sam_tracks[i].lost.get_or_insert(at);
}
r.events.push(Event { at, pos, kind });
}
}
@@ -355,12 +497,15 @@ impl Sim {
self.rec = Some(Recording::new(self.recordings, self));
}
let Some(r) = &mut self.rec else { return };
if r.len % TIME_STEP == 0
&& let Some(dt) = self.day_time
{
r.times.push((r.len, dt));
if r.len % TIME_STEP == 0 {
if let Some(dt) = self.day_time {
r.times.push((r.len, dt));
}
r.ticks.push((r.len, self.engine_tick));
}
if r.len % STEP == 0 {
let now = r.len;
r.note_sams(&self.sams, now);
for d in &self.drones {
r.point(d.id, What::Drone(d.kind), d.pos);
}
@@ -434,6 +579,14 @@ impl Sim {
}
}
}
// The air-defence systems as they stood: where, which way, the launcher or turret where it
// pointed, a wreck once lost.
let mut rng = Rng(1);
for (k, st) in rec.sam_tracks.iter().enumerate() {
if let Some(ghost) = st.ghost(rec.origin, t, base + 0x0040_0000 + k as u32 * PARTS) {
units::draw_sam_model(&ghost, &mut rng, out);
}
}
// 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) {
@@ -471,3 +624,88 @@ impl Sim {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
fn sam_at(x: f64, heading: f64, yaw: f64) -> Sam {
let mut s = Sam::new(7, SamKind::S400, DVec3::new(x, 64.0, 0.0), heading);
s.yaw = yaw;
s
}
fn recording() -> Recording {
Recording {
number: 1,
origin: DVec3::ZERO,
len: 0,
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,
}
}
#[test]
fn a_system_keeps_its_pose_through_stillness_and_moves_when_it_moved() {
let mut r = recording();
// Still for 20 ticks, then the turret swings and the vehicle drives.
for now in (0..=20).step_by(STEP as usize) {
r.note_sams(&[sam_at(0.0, 0.0, 0.0)], now);
}
assert_eq!(r.sam_tracks[0].keys.len(), 1, "stillness is one key");
r.note_sams(&[sam_at(4.0, 0.0, 1.0)], 22);
let t = &r.sam_tracks[0];
let pose = |tick: f64| t.pose(tick).unwrap();
// Held at the old pose until just before the change, not gliding over the stillness.
assert!(pose(10.0).pos[0].abs() < 1e-6 && pose(10.0).yaw.abs() < 1e-6);
assert!(pose(20.0).pos[0].abs() < 1e-6);
// Half way through the move.
assert!((pose(21.0).pos[0] - 2.0).abs() < 1e-4 && (pose(21.0).yaw - 0.5).abs() < 1e-4);
assert!((pose(100.0).pos[0] - 4.0).abs() < 1e-6);
}
#[test]
fn a_system_first_seen_later_is_not_drawn_before() {
let mut r = recording();
r.note_sams(&[sam_at(0.0, 0.0, 0.0)], 40);
assert!(r.sam_tracks[0].pose(10.0).is_none());
assert!(r.sam_tracks[0].pose(40.0).is_some());
}
#[test]
fn angles_turn_the_short_way_and_a_lost_system_is_a_wreck() {
let mut r = recording();
r.note_sams(&[sam_at(0.0, 0.0, 6.2)], 0);
r.note_sams(&[sam_at(0.0, 0.0, 0.1)], 2);
let t = &mut r.sam_tracks[0];
let mid = t.pose(1.0).unwrap().yaw;
assert!(!(0.2..6.0).contains(&mid), "through zero, not back round: {mid}");
assert!(t.ghost(DVec3::ZERO, 1.0, 0).unwrap().alive());
t.lost = Some(30);
assert!(t.ghost(DVec3::ZERO, 29.0, 0).unwrap().alive());
assert!(!t.ghost(DVec3::ZERO, 31.0, 0).unwrap().alive());
}
#[test]
fn the_games_tick_is_known_through_the_recording() {
let mut r = recording();
assert_eq!(r.world_tick(5.0), None);
r.ticks = vec![(0, 1000), (20, 1020), (40, 1040), (60, 1100)];
assert_eq!(r.first_tick(), Some(1000));
assert_eq!(r.world_tick(0.0), Some(1000));
assert_eq!(r.world_tick(10.0), Some(1010));
assert_eq!(r.world_tick(30.0), Some(1030));
// A jump of the game's ticks between samples (the recording paused or a gap) is a step.
assert_eq!(r.world_tick(50.0), Some(1040 + 10));
assert_eq!(r.world_tick(70.0), Some(1100 + 10));
}
}
+45 -6
View File
@@ -631,11 +631,16 @@ impl Sam {
impl Sim {
/// Draws unit `i`: its vehicle, its launcher or turret where it points, its antennas turning.
pub(super) fn draw_sam(&mut self, i: usize, out: &mut Out) {
if !self.sams[i].alive() {
self.draw_wreck(i, out);
return;
}
let sam = &self.sams[i];
draw_sam_model(&self.sams[i], &mut self.rng, out);
}
}
/// Draws a system as it stands (a live one, or a replay's ghost built from the recording).
pub(super) fn draw_sam_model(sam: &Sam, rng: &mut Rng, out: &mut Out) {
if !sam.alive() {
damage::draw_wreck_of(sam, out);
return;
}
let spec = sam.kind.spec();
let parts = &spec.parts;
let base = sam.base();
@@ -709,9 +714,43 @@ impl Sim {
_ => &[],
};
for (n, b) in barrels.iter().enumerate() {
let r = rot * DQuat::from_rotation_z(self.rng.f() * TAU);
let r = rot * DQuat::from_rotation_z(rng.f() * TAU);
out.model(id + 12 + n as u32, "airdef:flash", mount + rot * *b * s, r, 0.9, true);
}
}
}
/// The charred variant of a part's model, for wrecks (tools/gen_models.py `WRECKS`); a part without one keeps its model.
pub(super) fn wreck(model: &'static str) -> &'static str {
match model {
"airdef:patriot_trailer" => "airdef:patriot_trailer_burnt",
"airdef:patriot_launcher" => "airdef:patriot_launcher_burnt",
"airdef:gepard_hull" => "airdef:gepard_hull_burnt",
"airdef:gepard_turret" => "airdef:gepard_turret_burnt",
"airdef:gepard_guns" => "airdef:gepard_guns_burnt",
"airdef:pantsir_truck" => "airdef:pantsir_truck_burnt",
"airdef:pantsir_turret" => "airdef:pantsir_turret_burnt",
"airdef:pantsir_pack" => "airdef:pantsir_pack_burnt",
"airdef:s400_chassis" => "airdef:s400_chassis_burnt",
"airdef:s400_tubes" => "airdef:s400_tubes_burnt",
"airdef:s500_chassis" => "airdef:s500_chassis_burnt",
"airdef:s500_tubes" => "airdef:s500_tubes_burnt",
"airdef:irist_chassis" => "airdef:irist_chassis_burnt",
"airdef:irist_tubes" => "airdef:irist_tubes_burnt",
"airdef:nasams_trailer" => "airdef:nasams_trailer_burnt",
"airdef:nasams_launcher" => "airdef:nasams_launcher_burnt",
"airdef:buk_chassis" => "airdef:buk_chassis_burnt",
"airdef:buk_turret" => "airdef:buk_turret_burnt",
"airdef:buk_rails" => "airdef:buk_rails_burnt",
"airdef:tor_chassis" => "airdef:tor_chassis_burnt",
"airdef:tor_turret" => "airdef:tor_turret_burnt",
"airdef:p1sun_launcher" => "airdef:p1sun_launcher_burnt",
"airdef:radar_truck" => "airdef:radar_truck_burnt",
"airdef:depot" => "airdef:depot_burnt",
"airdef:tzm_truck" => "airdef:tzm_truck_burnt",
"airdef:ew_truck" => "airdef:ew_truck_burnt",
"airdef:searchlight" => "airdef:searchlight_burnt",
"airdef:searchlight_head" => "airdef:searchlight_head_burnt",
other => other,
}
}