A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Tests: the shot guard also checks the projection matrix, and the rigs share it (Refs #2882) (#2901)
Beriee4eafeb6cd3
diff --git a/unity/Assets/Tests/EditMode/CabinetPreviewShots.cs b/unity/Assets/Tests/EditMode/CabinetPreviewShots.csindex d0d222660..fc870d37c 100644--- a/unity/Assets/Tests/EditMode/CabinetPreviewShots.cs+++ b/unity/Assets/Tests/EditMode/CabinetPreviewShots.cs@@ -134,6 +134,7 @@ public class CabinetPreviewShotsvoid Shot(string name, string person){var cam = Camera.main;+ ShotCamera.Require(cam, Width, Height);var frame = new RenderTexture(Width, Height, 24, RenderTextureFormat.ARGB32);var before = cam.targetTexture;cam.targetTexture = frame; cam.Render(); cam.targetTexture = before;diff --git a/unity/Assets/Tests/EditMode/CivMovementShots.cs b/unity/Assets/Tests/EditMode/CivMovementShots.csindex dbedcf51f..f5a93c9a0 100644--- a/unity/Assets/Tests/EditMode/CivMovementShots.cs+++ b/unity/Assets/Tests/EditMode/CivMovementShots.cs@@ -103,8 +103,7 @@ public class CivMovementShots{var cam = Camera.main;// A camera at another aspect writes a stretched still (#2882): its rig skipped ShotCamera.Configure.- if (Mathf.Abs(cam.aspect - (float)Width / Height) > 0.001f)- throw new InvalidOperationException($"the camera's aspect is {cam.aspect:0.000}, its frame's {(float)Width / Height:0.000} ({Width} x {Height}): call ShotCamera.Configure after the scene opens");+ ShotCamera.Require(cam, Width, Height);var frame = new RenderTexture(Width, Height, 24, RenderTextureFormat.ARGB32);var before = cam.targetTexture;cam.targetTexture = frame; cam.Render(); cam.targetTexture = before;diff --git a/unity/Assets/Tests/EditMode/PanelPreviewShots.cs b/unity/Assets/Tests/EditMode/PanelPreviewShots.csindex 32db38d67..d718ff861 100644--- a/unity/Assets/Tests/EditMode/PanelPreviewShots.cs+++ b/unity/Assets/Tests/EditMode/PanelPreviewShots.cs@@ -144,6 +144,7 @@ public class PanelPreviewShotsvoid Shot(string name){var cam = Camera.main;+ ShotCamera.Require(cam, Width, Height);var frame = new RenderTexture(Width, Height, 24, RenderTextureFormat.ARGB32);var before = cam.targetTexture;cam.targetTexture = frame; cam.Render(); cam.targetTexture = before;diff --git a/unity/Assets/Tests/EditMode/ShotCamera.cs b/unity/Assets/Tests/EditMode/ShotCamera.csindex 1e8dd3519..02883491f 100644--- a/unity/Assets/Tests/EditMode/ShotCamera.cs+++ b/unity/Assets/Tests/EditMode/ShotCamera.cs@@ -15,4 +15,16 @@ static class ShotCameravar rig = cam.GetComponent<CameraRig>();if (rig != null) rig.ApplyProjection();}++ /// <summary>Throws when the camera would draw a stretched still: its aspect, or the aspect its projection matrix was+ /// built at, differs from the frame's. A rig that set cam.aspect after the top bar froze the matrix passes the first check+ /// and fails the second.</summary>+ internal static void Require(Camera cam, int width, int height)+ {+ float frame = (float)width / height;+ var p = cam.projectionMatrix;+ float built = p[1, 1] / p[0, 0];+ if (Mathf.Abs(cam.aspect - frame) > 0.001f || Mathf.Abs(built - frame) > 0.001f)+ throw new System.InvalidOperationException($"the camera's aspect is {cam.aspect:0.000} and its projection's {built:0.000}, its frame's {frame:0.000} ({width} x {height}): call ShotCamera.Configure after the scene opens");+ }}diff --git a/unity/Assets/Tests/EditMode/ShotCameraTests.cs b/unity/Assets/Tests/EditMode/ShotCameraTests.csindex 60e46207d..31355a82b 100644--- a/unity/Assets/Tests/EditMode/ShotCameraTests.cs+++ b/unity/Assets/Tests/EditMode/ShotCameraTests.cs@@ -3,6 +3,7 @@ using System;using System.Collections;using System.IO;using NUnit.Framework;+using Statecraft.Game.Map;using UnityEditor.SceneManagement;using UnityEngine;using UnityEngine.TestTools;@@ -32,8 +33,22 @@ public class ShotCameraTestsyield return CivMovementShots.Boot(false, dir, (t, p, u, g) => { rt = t; ps = p; });var cam = Camera.main;float frame = (float)CivMovementShots.Width / CivMovementShots.Height;+ Assert.Greater(cam.GetComponent<CameraRig>().TopInset, 0f, "the top bar has set the inset, so the matrix is the frozen custom one");Assert.AreEqual(frame, cam.aspect, 0.001f, "the camera's aspect is its frame's");var p = cam.projectionMatrix;Assert.AreEqual(frame, p[1, 1] / p[0, 0], 0.001f, "the projection is built at the frame's aspect");}++ [UnityTest]+ public IEnumerator TheShotRefusesAFrozenMatrixAtTheWrongAspect()+ {+ dir = Path.Combine(Path.GetTempPath(), "statecraft-shot-camera-" + Guid.NewGuid().ToString("N"));+ yield return CivMovementShots.Boot(false, dir, (t, p, u, g) => { rt = t; ps = p; });+ var cam = Camera.main;+ // The old rig pattern: the matrix froze at the batch run's 4:3, then cam.aspect was set without Apply.+ cam.aspect = 4f / 3f;+ cam.GetComponent<CameraRig>().ApplyProjection();+ cam.aspect = (float)CivMovementShots.Width / CivMovementShots.Height;+ Assert.Throws<InvalidOperationException>(() => CivMovementShots.Shot(rt!, "frozen"), "a frozen matrix at another aspect is refused");+ }}diff --git a/unity/Assets/Tests/EditMode/SiteFieldShots.cs b/unity/Assets/Tests/EditMode/SiteFieldShots.csindex 1ee1cb76f..28fbb5ad3 100644--- a/unity/Assets/Tests/EditMode/SiteFieldShots.cs+++ b/unity/Assets/Tests/EditMode/SiteFieldShots.cs@@ -106,6 +106,7 @@ public class SiteFieldShots{int w = CivMovementShots.Width, h = CivMovementShots.Height;var cam = Camera.main;+ ShotCamera.Require(cam, w, h);var frame = new RenderTexture(w, h, 24, RenderTextureFormat.ARGB32);var before = cam.targetTexture;cam.targetTexture = frame; cam.Render(); cam.targetTexture = before;