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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 15:19:32 +03:00
parent 51f9609327
commit 0f5c4136f3
43 changed files with 1197 additions and 207 deletions
+69 -16
View File
@@ -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());
}
}