Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

Tools: a scripted trailer capture from the real build, PNG frames at 1920x1080, 60 fps (refs #45) (#819)

Berid351e44ed280
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 394cf504e..ff7244933 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -110,6 +110,12 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
the tilt-shift blur off and on, at once; the choice is kept per browser in `/idbfs/statecraft-settings/settings.txt`
(a fixed folder, as the autosave's), never in the sim or the save, so the goldens do not move. `?notiltshift` still
boots without the blur.
+- A scripted trailer capture from the real build (refs #45): `MapCapture.Trailer` renders the camera moves in
+ `TrailerShot.Default` (the whole country, down to the promo 03 ground and back up; 14 s from the existing promo
+ poses) at 1920 x 1080 and 60 fps on the desktop tier, as PNG frames with the water's clock pinned per frame, the units
+ of turn 1 of a game started with `-seed`, and a `trailer.txt` recording the commit, seed and settings.
+ `docs/RELEASING.md` "Capturing trailer footage" gives the command and the ffmpeg line. Map only (no UI, no sound);
+ the draft cut is still to come.
- The info panel of Tiberias' hex adds "Tiberias is shown here because its own hex is water." (Hebrew too, with the
town's Hebrew name), so the hillside hex's
70 m does not read as the town's (refs #204). It is worked out in Unity from the town's own lon/lat and the hex grid
diff --git a/docs/RELEASING.md b/docs/RELEASING.md
index f226e3bcd..cabf60215 100644
--- a/docs/RELEASING.md
+++ b/docs/RELEASING.md
@@ -137,6 +137,47 @@ give a new image an `ASSETS.yaml` row, change `CONCEPT`, `CLIP` or `GRID` in `te
and land it as a normal pull request. Whether a real build screenshot later replaces the concept art in "What is
this?" is not decided.
+## Capturing trailer footage (issue #45)
+
+The trailer's map shots come from the real build: the editor renders the map frame by frame, so a capture can be run
+again and gives the same camera, state and water on every frame. The pixels match too, except the unit badges' glyphs
+at the whole-country zoom: two runs on the build server differed only there (1,288 of 6.2 million bytes per frame;
+the 60 km frames were byte-identical), where a glyph and its plate draw at almost the same depth. Build the sim DLLs
+first (`python3 tools/build_sim_for_unity.py`), run Unity with graphics (not `-nographics`; on Linux under
+`xvfb-run -a`), then encode the frames with ffmpeg:
+
+```sh
+"$UNITY" -batchmode -CI false -GITHUB_ACTIONS false -TF_BUILD false -quit -projectPath unity \
+ -executeMethod MapCapture.Trailer -captureDir "$PWD/captures/<name>" [-seed 1948] -logFile "$PWD/unity-trailer.log"
+ffmpeg -framerate 60 -i captures/<name>/frame-%05d.png -vf scale=out_color_matrix=bt709 \
+ -c:v libx264 -preset slow -crf 16 -pix_fmt yuv420p -colorspace bt709 -color_primaries bt709 -color_trc bt709 \
+ -movflags +faststart captures/<name>/trailer-map.mp4
+```
+
+Give `-captureDir` an absolute path (a relative one resolves against Unity's working directory) under the ignored
+`captures/` or outside the repo: frames anywhere else in the tree would mark the recorded commit `-dirty`. The capture
+deletes any `frame-*.png` already in it first, so an older, longer run cannot leak into the encode.
+
+- **What it renders:** the camera moves in `TrailerShot.Default` (`unity/Assets/Scripts/Map/TrailerShot.cs`), built only
+ from the promo poses the art checkpoint already compares (`PromoPose`): the whole country held for 2 s, down to the
+ Jaffa-Tel Aviv-Lydda ground of promo 03 (6 s), and back up to the whole country (6 s). 840 frames, 14 s, each move
+ eased in and out. That order is a placeholder; the shots are the owner's call. Change the list to change it.
+- **Settings:** 1920 x 1080 on the desktop (PC) tier, 60 fps, the water's clock pinned to each frame's time, the 1948
+ sub-districts and the units of turn 1 of a new historical game started with `-seed` (default the golden seed, 1948;
+ turn 1's units do not depend on the seed today, it is recorded so a later moment can be repeated). The frames are
+ `frame-00000.png` onwards, one sequence across the shots. `trailer.txt` beside them records the commit, Unity
+ version, seed, size, fps, tier and each shot's frame range.
+- **Not in it:** the UI (editor renders draw no UI Toolkit, so UI shots still come from the player), sound, and the cut.
+ The .mp4 has no audio track; Steam prefers AAC audio, which the cut adds.
+- **Why PNG frames:** a frame is written only when it is fully rendered, so a slow machine gives the same footage as a
+ fast one, and the Linux editor needs no video codec. On the software-rendered Linux build server (llvmpipe) the
+ default 840 frames took 15 to 25 minutes (907 s alone, 1,459 s beside another Unity run) and 2.3 GB of PNG; the
+ encode took under a minute. Delete the frames after encoding.
+- **Check the encode** before it goes anywhere:
+ `ffprobe -v error -show_entries stream=codec_name,width,height,r_frame_rate,bit_rate captures/<name>/trailer-map.mp4`
+ must say h264, 1920 x 1080, 60/1, and a bit rate above Steam's 5,000 Kbps. If it is under (long still holds compress
+ well), encode again with `-b:v 8M -maxrate 12M -bufsize 16M` in place of `-crf 16`.
+
## Store-page checklist (issue #45; OWNER STEP)
This is preparation, not a published store page or an answered content survey. The checklist does not clear the name,
@@ -163,9 +204,10 @@ assets or content for commercial use. Finish the release gates above first; the
08 as gameplay. Review each screenshot's age-suitability flag individually; never mark a sensitive scene suitable for
all ages just to gain placement. If at least four genuinely qualify, mark them suitable for all ages; with fewer
flagged, the game may not appear in some placements.
-- [ ] Prepare a trailer from the real build, not the M2 recruiting flythrough or concept-art target. The deterministic
- 1920 x 1080, 60 fps capture and draft cut are the separate trailer part of #45, still pending; this checklist does
- not provide a capture script or a finished trailer. Record the build/seed and capture settings with the cut.
+- [ ] Prepare a trailer from the real build, not the M2 recruiting flythrough or concept-art target. Capture the map
+ footage with "Capturing trailer footage" above (1920 x 1080, 60 fps, deterministic); the draft cut is still pending
+ (#45), so this checklist does not provide a finished trailer. Keep the capture's `trailer.txt` (build commit, seed and
+ capture settings) with the cut.
Steam requires a trailer and recommends that the first one be mostly gameplay; this project's rule (real build only)
is stricter. Upload the highest resolution available, up to 1920 x 1080, at 30/29.97 or 60/59.94 fps and
5,000+ Kbps, in a .mov, .wmv or .mp4 container; H.264 video with AAC audio is preferred
diff --git a/unity/Assets/Editor/MapCapture.cs b/unity/Assets/Editor/MapCapture.cs
index 7905e2b0c..e0ddcfbe9 100644
--- a/unity/Assets/Editor/MapCapture.cs
+++ b/unity/Assets/Editor/MapCapture.cs
@@ -207,14 +207,90 @@ public static class MapCapture
finally { QualitySettings.SetQualityLevel(saved, true); }
}
- /// <summary>The units in play as a new game starts (golden seed, historical mode): what the player draws on turn 1, or, with
- /// -unitsDate, on that day.</summary>
- static void ShowStartUnits(MapScene map)
+ /// <summary>The scripted trailer capture (issue #45): flies the camera through TrailerShot.Default and renders every frame
+ /// at 1920x1080 on the desktop tier (PC) into &lt;-captureDir&gt; (default captures/trailer) as frame-NNNNN.png, one numbered
+ /// sequence across the shots, with the water's clock pinned to the frame's time so a re-run gives the same camera, state
+ /// and water on every frame (the pixels too, but for the unit badges' glyphs at the whole-country zoom; see
+ /// docs/RELEASING.md "Capturing trailer footage"). The map as a new game starts: the 1948 sub-districts and the units on
+ /// turn 1 of a historical game started with -seed (default the golden seed; turn 1's units do not depend on it today,
+ /// but the seed is what makes a later game moment repeatable). PNG frames, not video: a frame is written only once it is
+ /// rendered, so a slow software renderer gives the same footage, and ffmpeg encodes them. trailer.txt beside them
+ /// records the commit, seed and settings. Editor renders draw no UI Toolkit, so this is the map only.</summary>
+ public static void Trailer()
+ {
+ var args = System.Environment.GetCommandLineArgs();
+ string Arg(string name) { int i = System.Array.IndexOf(args, name); return i >= 0 && i + 1 < args.Length ? args[i + 1] : null; }
+ var dir = Arg("-captureDir") ?? Path.Combine(CaptureDir, "trailer");
+ var seed = Arg("-seed") is string s ? ulong.Parse(s, System.Globalization.CultureInfo.InvariantCulture) : Statecraft.Sim.GoldenRun.Seed;
+ int tier = System.Array.IndexOf(QualitySettings.names, "PC");
+ if (tier < 0) throw new System.InvalidOperationException("no PC quality level: the trailer is captured on the desktop tier");
+ var map = OpenAndBuild();
+ ShowStartUnits(map, seed);
+ var subdistricts = Subdistricts1948.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", Subdistricts1948.FileName)));
+ new MapRegions(subdistricts, Armistice1949.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", Armistice1949.FileName))))
+ .Apply(subdistricts.ShownFrom);
+ // Frames left from an earlier, longer run would end up in the encode (ffmpeg reads frame-%05d.png until a gap).
+ Directory.CreateDirectory(dir);
+ foreach (var old in Directory.GetFiles(dir, "frame-*.png")) File.Delete(old);
+ var rig = Camera.main.GetComponent<CameraRig>();
+ rig.TopInset = 0;
+ int saved = QualitySettings.GetQualityLevel(), frame = 0;
+ var shots = new System.Text.StringBuilder();
+ try
+ {
+ QualitySettings.SetQualityLevel(tier, true);
+ foreach (var shot in TrailerShot.Default)
+ {
+ shots.AppendLine($"shot {shot.Name}: {shot.From.Name} -> {shot.To.Name}, frames {frame}-{frame + shot.Frames - 1}");
+ for (int i = 0; i < shot.Frames; i++, frame++)
+ {
+ shot.PoseAt(i).Apply(rig, map.Frame);
+ MapShaderGlobals.PinWaterTime(100f + frame / (float)TrailerShot.Fps);
+ Statecraft.Game.Map.Units.UnitFlagFacing.FaceAll(Camera.main.transform.position);
+ foreach (var layer in Object.FindObjectsByType<Statecraft.Game.Map.Units.UnitLayer>(FindObjectsSortMode.None)) layer.FaceCamera(Camera.main);
+ Save(Camera.main, 1920, 1080, Path.Combine(dir, $"frame-{frame:D5}.png"));
+ }
+ }
+ }
+ finally { MapShaderGlobals.PinWaterTime(null); QualitySettings.SetQualityLevel(saved, true); }
+ File.WriteAllText(Path.Combine(dir, "trailer.txt"),
+ $"commit: {Commit()}\nunity: {Application.unityVersion}\nseed: {seed}\nsize: 1920x1080\nfps: {TrailerShot.Fps}\n" +
+ $"tier: PC\nframes: {frame}\n{shots}");
+ Debug.Log($"TRAILER {frame} frames in {dir}");
+ }
+
+ /// <summary>The checked-out commit for trailer.txt, "-dirty" when the tree has uncommitted changes (they are in the frames
+ /// but not in the commit), or "unknown" when git cannot say.</summary>
+ static string Commit()
+ {
+ var sha = Git("rev-parse HEAD");
+ if (sha == null || sha.Length == 0) return "unknown";
+ var status = Git("status --porcelain");
+ return status == null ? sha + "-unknown-status" : status.Length > 0 ? sha + "-dirty" : sha;
+ }
+
+ /// <summary>git's trimmed output in the repo root, or null when git is missing or fails.</summary>
+ static string Git(string arguments)
+ {
+ try
+ {
+ using var git = System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("git", arguments)
+ { WorkingDirectory = Paths.RepoRoot, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false });
+ if (git == null) return null;
+ var output = git.StandardOutput.ReadToEnd().Trim(); git.StandardError.ReadToEnd(); git.WaitForExit();
+ return git.ExitCode == 0 ? output : null;
+ }
+ catch (System.Exception e) when (e is System.ComponentModel.Win32Exception || e is System.InvalidOperationException) { return null; }
+ }
+
+ /// <summary>The units in play as a new game starts (golden seed unless the trailer passes its -seed, historical mode): what
+ /// the player draws on turn 1, or, with -unitsDate, on that day.</summary>
+ static void ShowStartUnits(MapScene map, ulong seed = Statecraft.Sim.GoldenRun.Seed)
{
var content = Statecraft.Sim.ContentLoader.Load(Paths.Content);
var units = Statecraft.Game.Map.Units.UnitData.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", Statecraft.Game.Map.Units.UnitData.DefaultFileName)));
var layer = Statecraft.Game.Map.Units.UnitLayer.Create(map, units, content.Hexes, still: true);
- var state = Statecraft.Sim.Simulation.NewGame(content, Statecraft.Sim.GoldenRun.Seed, Statecraft.Sim.Mode.Historical);
+ var state = Statecraft.Sim.Simulation.NewGame(content, seed, Statecraft.Sim.Mode.Historical);
// -unitsDate YYYY-MM-DD: the units as on that day (a render of a unit outside the first turn; the sim never sees it).
var args = System.Environment.GetCommandLineArgs();
int at = System.Array.IndexOf(args, "-unitsDate");
diff --git a/unity/Assets/Scripts/Map/TrailerShot.cs b/unity/Assets/Scripts/Map/TrailerShot.cs
new file mode 100644
index 000000000..4766a73eb
--- /dev/null
+++ b/unity/Assets/Scripts/Map/TrailerShot.cs
@@ -0,0 +1,49 @@
+#nullable enable
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace Statecraft.Game.Map
+{
+ /// <summary>One camera move of the scripted trailer capture (issue #45, MapCapture.Trailer): from one promo pose to another
+ /// over <see cref="Seconds"/> at <see cref="Fps"/>, eased in and out. Pure arithmetic on the frame number, so the same
+ /// frame always gets the same camera, whatever the machine's speed.</summary>
+ public readonly struct TrailerShot
+ {
+ /// <summary>Steam takes 30 or 60 fps (docs/RELEASING.md); 60 keeps the slow moves smooth.</summary>
+ public const int Fps = 60;
+
+ public readonly string Name; public readonly PromoPose From, To; public readonly float Seconds;
+
+ public TrailerShot(string name, PromoPose from, PromoPose to, float seconds)
+ { Name = name; From = from; To = to; Seconds = seconds; }
+
+ public int Frames => Mathf.RoundToInt(Seconds * Fps);
+
+ /// <summary>The camera on frame <paramref name="frame"/> (0 to Frames - 1): the first frame is From, the last is To.
+ /// Smoothstep easing, so a move neither starts nor stops with a jolt. The distance follows the eased curve in log
+ /// terms (it falls evenly as a ratio), because a straight lerp from 250 km to 60 km would race through the high part
+ /// and crawl at the end.</summary>
+ public PromoPose PoseAt(int frame)
+ {
+ float t = Frames <= 1 ? 1f : Mathf.Clamp01(frame / (float)(Frames - 1));
+ float e = t * t * (3f - 2f * t);
+ return new PromoPose($"{Name}-{frame:D4}",
+ From.Lon + (To.Lon - From.Lon) * e, From.Lat + (To.Lat - From.Lat) * e,
+ (float)(From.Distance * System.Math.Pow((double)To.Distance / From.Distance, e)), Mathf.Lerp(From.Yaw, To.Yaw, e));
+ }
+
+ /// <summary>The default flight, from framings the art checkpoint already compares (PromoPose): the whole country held
+ /// for two seconds, down to the Jaffa-Tel Aviv-Lydda ground of promo 03, and back up to the whole country for the
+ /// title. 14 s, 840 frames. Each move eases in and out on its own, so the camera settles on every promo pose (one
+ /// frame repeats at each join) before the next move: a beat for the cut, on purpose. Not the 6 km close checks: they
+ /// are ground checks shot with the trees off, and in the first capture (2026-10-16) the move down to the Judean one ended
+ /// with hillside and tree crowns filling the frame. A placeholder order for the owner to change: the trailer's shots are
+ /// the owner's call (#45).</summary>
+ public static IReadOnlyList<TrailerShot> Default { get; } = new[]
+ {
+ new TrailerShot("country", PromoPose.Diorama02, PromoPose.Diorama02, 2f),
+ new TrailerShot("descent", PromoPose.Diorama02, PromoPose.Gameplay03, 6f),
+ new TrailerShot("rise", PromoPose.Gameplay03, PromoPose.Diorama02, 6f),
+ };
+ }
+}
diff --git a/unity/Assets/Scripts/Map/TrailerShot.cs.meta b/unity/Assets/Scripts/Map/TrailerShot.cs.meta
new file mode 100644
index 000000000..ae381ed50
--- /dev/null
+++ b/unity/Assets/Scripts/Map/TrailerShot.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 490e50a2a1a427a9f80bc9e18533e130
\ No newline at end of file
diff --git a/unity/Assets/Tests/EditMode/TrailerShotTests.cs b/unity/Assets/Tests/EditMode/TrailerShotTests.cs
new file mode 100644
index 000000000..34cd4f6e0
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/TrailerShotTests.cs
@@ -0,0 +1,66 @@
+#nullable enable
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game.Map;
+
+/// <summary>Issue #45: the scripted trailer capture's shot list (TrailerShot) and its editor entry point (MapCapture.Trailer).</summary>
+public class TrailerShotTests
+{
+ /// <summary>Every shot starts exactly on its From pose and ends exactly on its To pose, at 60 fps, the shots join up
+ /// (no jump between them), and the default flight is the 840 frames docs/RELEASING.md states.</summary>
+ [Test]
+ public void TheShotsStartAndEndOnTheirPosesAndJoinUp()
+ {
+ var shots = TrailerShot.Default;
+ Assert.That(shots.Count, Is.GreaterThan(0));
+ foreach (var s in shots)
+ {
+ Assert.AreEqual(UnityEngine.Mathf.RoundToInt(s.Seconds * 60), s.Frames, s.Name);
+ Assert.That(s.Frames, Is.GreaterThan(1), s.Name);
+ AssertSamePlace(s.From, s.PoseAt(0), s.Name + " first frame");
+ AssertSamePlace(s.To, s.PoseAt(s.Frames - 1), s.Name + " last frame");
+ }
+ for (int i = 1; i < shots.Count; i++) AssertSamePlace(shots[i - 1].To, shots[i].From, shots[i].Name + " joins the shot before");
+ Assert.AreEqual(840, shots.Sum(x => x.Frames), "docs/RELEASING.md and the CHANGELOG say 840 frames");
+ }
+
+ /// <summary>The frames only use framings already approved for the art checkpoint (PromoPose.All and CloseChecks), and the
+ /// zoom moves one way inside a shot, within the camera's own limits: no overshoot past either end.</summary>
+ [Test]
+ public void TheShotsUseThePromoPosesAndNeverOvershoot()
+ {
+ var approved = PromoPose.All.Concat(PromoPose.CloseChecks).Select(p => p.Name).ToList();
+ foreach (var s in TrailerShot.Default)
+ {
+ CollectionAssert.Contains(approved, s.From.Name, s.Name);
+ CollectionAssert.Contains(approved, s.To.Name, s.Name);
+ float lo = System.Math.Min(s.From.Distance, s.To.Distance), hi = System.Math.Max(s.From.Distance, s.To.Distance);
+ float last = s.PoseAt(0).Distance;
+ for (int f = 0; f < s.Frames; f++)
+ {
+ var p = s.PoseAt(f);
+ Assert.That(p.Distance, Is.InRange(lo - 1f, hi + 1f), $"{s.Name} frame {f}");
+ Assert.That(p.Distance, Is.InRange(CameraController.MinDistance, CameraController.MaxDistance), $"{s.Name} frame {f}");
+ Assert.That(s.To.Distance >= s.From.Distance ? p.Distance >= last - 1e-3f : p.Distance <= last + 1e-3f, $"{s.Name} frame {f} zooms one way");
+ last = p.Distance;
+ }
+ }
+ }
+
+ /// <summary>The headless entry point exists: -executeMethod MapCapture.Trailer (docs/RELEASING.md).</summary>
+ [Test]
+ public void TheCaptureHasAnEditorEntryPoint()
+ {
+ var capture = System.Type.GetType("MapCapture, Assembly-CSharp-Editor");
+ Assert.IsNotNull(capture);
+ Assert.IsNotNull(capture!.GetMethod("Trailer", System.Type.EmptyTypes), "MapCapture.Trailer()");
+ }
+
+ static void AssertSamePlace(PromoPose want, PromoPose got, string what)
+ {
+ Assert.AreEqual(want.Lon, got.Lon, 1e-9, what + " lon");
+ Assert.AreEqual(want.Lat, got.Lat, 1e-9, what + " lat");
+ Assert.AreEqual(want.Distance, got.Distance, 1e-2f, what + " distance");
+ Assert.AreEqual(want.Yaw, got.Yaw, 1e-4f, what + " yaw");
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/TrailerShotTests.cs.meta b/unity/Assets/Tests/EditMode/TrailerShotTests.cs.meta
new file mode 100644
index 000000000..1e89cc630
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/TrailerShotTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: fe27a160caac03e0daf17d5fcb671a70
\ No newline at end of file