A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
fix(map): a border skirt continues each edge as land or sea; nothing covers the rift (fix round 2, R2-1, N1)
eyalgolan75730926def9
diff --git a/unity/Assets/Editor/MapCapture.cs b/unity/Assets/Editor/MapCapture.csindex d6f321d9f..a8046e756 100644--- a/unity/Assets/Editor/MapCapture.cs+++ b/unity/Assets/Editor/MapCapture.cs@@ -29,7 +29,7 @@ public static class MapCapturevar scene = EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);var controller = Camera.main.gameObject.AddComponent<CameraController>(); // adds the CameraRig it requiresvar map = new GameObject("MapScene").AddComponent<MapScene>();- map.Configure(Load(MapMaterials.TerrainPath), Load(MapMaterials.OverlayPath), Load(MapMaterials.MarkerPath), Load(MapMaterials.SelectionPath), Load(MapMaterials.SeaPath));+ map.Configure(Load(MapMaterials.TerrainPath), Load(MapMaterials.OverlayPath), Load(MapMaterials.MarkerPath), Load(MapMaterials.SelectionPath), Load(MapMaterials.SeaPath), Load(MapMaterials.BorderLandPath));var boot = new GameObject("Boot").AddComponent<GameBoot>();boot.Configure(map);var placements = new GameObject("Placements").AddComponent<PlacementLayer>();diff --git a/unity/Assets/Editor/MapMaterials.cs b/unity/Assets/Editor/MapMaterials.csindex fb7dd34c7..d004d069b 100644--- a/unity/Assets/Editor/MapMaterials.cs+++ b/unity/Assets/Editor/MapMaterials.cs@@ -14,6 +14,7 @@ namespace Statecraft.Game.EditorToolspublic const string MarkerPath = Folder + "/SettlementMarker.mat";public const string SelectionPath = Folder + "/HexSelection.mat";public const string SeaPath = Folder + "/Sea.mat";+ public const string BorderLandPath = Folder + "/BorderLand.mat";public static void Create(){@@ -38,6 +39,12 @@ namespace Statecraft.Game.EditorToolssea.SetFloat("_SpecularHighlights", 1f); sea.SetFloat("_EnvironmentReflections", 1f);sea.DisableKeyword("_SPECULARHIGHLIGHTS_OFF"); sea.DisableKeyword("_ENVIRONMENTREFLECTIONS_OFF");EditorUtility.SetDirty(sea);+ // Neighbouring land past the map's edge (Sinai, Jordan, Lebanon): one muted land tone, lit and matte like the sea+ // (fix round 2, R2-1).+ var land = Make(BorderLandPath, "Universal Render Pipeline/Lit", Statecraft.Game.Map.MapBuilder.BorderLandColour);+ land.SetFloat("_Smoothness", 0f); land.SetFloat("_Metallic", 0f);+ land.SetFloat("_SpecularHighlights", 1f); land.SetFloat("_EnvironmentReflections", 1f);+ EditorUtility.SetDirty(land);AssetDatabase.SaveAssets();}diff --git a/unity/Assets/Map.unity b/unity/Assets/Map.unityindex 1ea8c3e08..6affc6bb2 100644--- a/unity/Assets/Map.unity+++ b/unity/Assets/Map.unity@@ -384,6 +384,7 @@ MonoBehaviour:markerMaterial: {fileID: 2100000, guid: 7c65bbd4355344f1990495c458323a4e, type: 2}selectionMaterial: {fileID: 2100000, guid: 6116b1f8c72b244e0a9556c2cdb6b1c5, type: 2}seaMaterial: {fileID: 2100000, guid: 5bb451931546c49d6b2fe35726d07cfd, type: 2}+ borderLandMaterial: {fileID: 2100000, guid: ed41bb6e0c8274066b408da9b1f5bef2, type: 2}--- !u!4 &1195372453Transform:m_ObjectHideFlags: 0diff --git a/unity/Assets/Materials/BorderLand.mat b/unity/Assets/Materials/BorderLand.matnew file mode 100644index 000000000..117aa1628--- /dev/null+++ b/unity/Assets/Materials/BorderLand.mat@@ -0,0 +1,137 @@+%YAML 1.1+%TAG !u! tag:unity3d.com,2011:+--- !u!114 &-4358778686204817034+MonoBehaviour:+ m_ObjectHideFlags: 11+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_GameObject: {fileID: 0}+ m_Enabled: 1+ m_EditorHideFlags: 0+ m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}+ m_Name:+ m_EditorClassIdentifier: Unity.RenderPipelines.Universal.Editor::UnityEditor.Rendering.Universal.AssetVersion+ version: 10+--- !u!21 &2100000+Material:+ serializedVersion: 8+ m_ObjectHideFlags: 0+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: BorderLand+ m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}+ m_Parent: {fileID: 0}+ m_ModifiedSerializedProperties: 0+ m_ValidKeywords: []+ m_InvalidKeywords: []+ m_LightmapFlags: 4+ m_EnableInstancingVariants: 1+ m_DoubleSidedGI: 0+ m_CustomRenderQueue: -1+ stringTagMap:+ RenderType: Opaque+ disabledShaderPasses:+ - MOTIONVECTORS+ m_LockedProperties:+ m_SavedProperties:+ serializedVersion: 3+ m_TexEnvs:+ - _BaseMap:+ m_Texture: {fileID: 0}+ m_Scale: {x: 1, y: 1}+ m_Offset: {x: 0, y: 0}+ - _BumpMap:+ m_Texture: {fileID: 0}+ m_Scale: {x: 1, y: 1}+ m_Offset: {x: 0, y: 0}+ - _DetailAlbedoMap:+ m_Texture: {fileID: 0}+ m_Scale: {x: 1, y: 1}+ m_Offset: {x: 0, y: 0}+ - _DetailMask:+ m_Texture: {fileID: 0}+ m_Scale: {x: 1, y: 1}+ m_Offset: {x: 0, y: 0}+ - _DetailNormalMap:+ m_Texture: {fileID: 0}+ m_Scale: {x: 1, y: 1}+ m_Offset: {x: 0, y: 0}+ - _EmissionMap:+ m_Texture: {fileID: 0}+ m_Scale: {x: 1, y: 1}+ m_Offset: {x: 0, y: 0}+ - _MainTex:+ m_Texture: {fileID: 0}+ m_Scale: {x: 1, y: 1}+ m_Offset: {x: 0, y: 0}+ - _MetallicGlossMap:+ m_Texture: {fileID: 0}+ m_Scale: {x: 1, y: 1}+ m_Offset: {x: 0, y: 0}+ - _OcclusionMap:+ m_Texture: {fileID: 0}+ m_Scale: {x: 1, y: 1}+ m_Offset: {x: 0, y: 0}+ - _ParallaxMap:+ m_Texture: {fileID: 0}+ m_Scale: {x: 1, y: 1}+ m_Offset: {x: 0, y: 0}+ - _SpecGlossMap:+ m_Texture: {fileID: 0}+ m_Scale: {x: 1, y: 1}+ m_Offset: {x: 0, y: 0}+ - unity_Lightmaps:+ m_Texture: {fileID: 0}+ m_Scale: {x: 1, y: 1}+ m_Offset: {x: 0, y: 0}+ - unity_LightmapsInd:+ m_Texture: {fileID: 0}+ m_Scale: {x: 1, y: 1}+ m_Offset: {x: 0, y: 0}+ - unity_ShadowMasks:+ m_Texture: {fileID: 0}+ m_Scale: {x: 1, y: 1}+ m_Offset: {x: 0, y: 0}+ m_Ints: []+ m_Floats:+ - _AddPrecomputedVelocity: 0+ - _AlphaClip: 0+ - _AlphaToMask: 0+ - _Blend: 0+ - _BlendModePreserveSpecular: 1+ - _BumpScale: 1+ - _ClearCoatMask: 0+ - _ClearCoatSmoothness: 0+ - _Cull: 2+ - _Cutoff: 0.5+ - _DetailAlbedoMapScale: 1+ - _DetailNormalMapScale: 1+ - _DstBlend: 0+ - _DstBlendAlpha: 0+ - _EnvironmentReflections: 1+ - _GlossMapScale: 0+ - _Glossiness: 0+ - _GlossyReflections: 0+ - _Metallic: 0+ - _OcclusionStrength: 1+ - _Parallax: 0.005+ - _QueueOffset: 0+ - _ReceiveShadows: 1+ - _Smoothness: 0+ - _SmoothnessTextureChannel: 0+ - _SpecularHighlights: 1+ - _SrcBlend: 1+ - _SrcBlendAlpha: 1+ - _Surface: 0+ - _WorkflowMode: 1+ - _XRMotionVectorsPass: 1+ - _ZWrite: 1+ m_Colors:+ - _BaseColor: {r: 0.6, g: 0.56, b: 0.46, a: 1}+ - _Color: {r: 0.6, g: 0.56, b: 0.45999992, a: 1}+ - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}+ - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}+ m_BuildTextureStacks: []+ m_AllowLocking: 1diff --git a/unity/Assets/Materials/BorderLand.mat.meta b/unity/Assets/Materials/BorderLand.mat.metanew file mode 100644index 000000000..8db72ce39--- /dev/null+++ b/unity/Assets/Materials/BorderLand.mat.meta@@ -0,0 +1,8 @@+fileFormatVersion: 2+guid: ed41bb6e0c8274066b408da9b1f5bef2+NativeFormatImporter:+ externalObjects: {}+ mainObjectFileID: 2100000+ userData:+ assetBundleName:+ assetBundleVariant:diff --git a/unity/Assets/Scripts/Map/MapBuilder.cs b/unity/Assets/Scripts/Map/MapBuilder.csindex 2c6135478..00d67a1ca 100644--- a/unity/Assets/Scripts/Map/MapBuilder.cs+++ b/unity/Assets/Scripts/Map/MapBuilder.cs@@ -23,6 +23,9 @@ namespace Statecraft.Game.Map/// capture, the 90 km flythrough) a coarse surface that rises above the draped hex outlines in valleys (K2).</summary>public const float TerrainPixelError = 1f;+ /// <summary>The muted land tone of neighbouring land past the map's edge (BorderLand.mat).</summary>+ public static readonly Color BorderLandColour = new Color(0.60f, 0.56f, 0.46f);+/// <summary>Biome colours of the terrain layers (the minimap uses the same ones).</summary>public static IReadOnlyDictionary<string, Color> BiomeColours => Biome;@@ -147,6 +150,92 @@ namespace Statecraft.Game.Mapdata.SetAlphamaps(0, 0, a);}+ /// <summary>Distances (m) of the border skirt's rings from the map's edge: land falls from the edge's height to sea+ /// level across the first rings, then stays flat to the last, beyond anything the camera can see.</summary>+ public static readonly float[] SkirtRings = { 0f, 4000f, 20000f, 60000f, 600000f };+ /// <summary>Share of the fall to sea level reached at each ring (land samples only).</summary>+ static readonly float[] SkirtFall = { 0f, 0.4f, 0.85f, 1f, 1f };+ /// <summary>Edge samples per side of the border skirt (the heightmap has 2048 intervals per side).</summary>+ public const int SkirtSamplesPerEdge = 1024;+ /// <summary>A heightmap sample this close to 0 m is sea (tools/dem_to_heightmap.py writes open sea as exactly 0 m).</summary>+ public const float SeaToleranceM = 0.5f;++ /// <summary>The land and sea past the map's edge (fix round 2, R2-1 and N1). Each edge sample continues outward: a sea+ /// sample stays flat at sea level (submesh 0, the sea material, lit like the terrain's sea, so no seam shows); a land+ /// sample falls from the edge's height to sea level (submesh 1, a muted land tone), so Sinai, Jordan and Lebanon read+ /// as land. A segment with a land end is land. Corner fans close the four corners. Every triangle lies outside the+ /// terrain's footprint, so nothing covers the map (the old full sea plane hid all land below about -10 m).</summary>+ public static Mesh BuildBorderSkirt(TerrainData data, float elevMinM, MapRuntimeAssets assets)+ {+ var size = data.size;+ float seaY = (0f - elevMinM) * VerticalExaggeration;+ var verts = new List<Vector3>(); var sea = new List<int>(); var land = new List<int>();+ bool IsLand(float h) => Mathf.Abs(h / VerticalExaggeration + elevMinM) > SeaToleranceM;+ // One ring of vertices outward from an edge point; returns the index of its first vertex.+ int Spoke(Vector2 p, Vector2 outward, bool isLand, Vector2? outward2 = null)+ {+ float h = data.GetInterpolatedHeight(Mathf.Clamp01(p.x / size.x), Mathf.Clamp01(p.y / size.z));+ int first = verts.Count;+ for (int k = 0; k < SkirtRings.Length; k++)+ {+ var q = p + (outward + (outward2 ?? Vector2.zero)) * SkirtRings[k];+ float y = isLand ? Mathf.Lerp(h, seaY, SkirtFall[k]) : seaY;+ if (k == 0) y = h; // meets the terrain's edge exactly+ verts.Add(new Vector3(q.x, y, q.y));+ }+ return first;+ }+ void Quad(List<int> into, int a0, int b0) // the band between two spokes+ {+ for (int k = 0; k + 1 < SkirtRings.Length; k++)+ {+ int a = a0 + k, a1 = a0 + k + 1, b = b0 + k, b1 = b0 + k + 1;+ Tri(into, a, b, b1); Tri(into, a, b1, a1);+ }+ }+ void Tri(List<int> into, int i, int j, int l) // wound to face up+ {+ var n = Vector3.Cross(verts[j] - verts[i], verts[l] - verts[i]);+ if (n.y < 0) { var t = j; j = l; l = t; }+ if (Mathf.Abs(n.y) > 1e-3f) { into.Add(i); into.Add(j); into.Add(l); } // drops the degenerate corner centre+ }+ float Height(Vector2 p) => data.GetInterpolatedHeight(Mathf.Clamp01(p.x / size.x), Mathf.Clamp01(p.y / size.z));+ // The four edges, walked along: (start, end, outward).+ var edges = new (Vector2 a, Vector2 b, Vector2 n)[]+ {+ (new Vector2(0, 0), new Vector2(size.x, 0), Vector2.down), // south+ (new Vector2(size.x, 0), new Vector2(size.x, size.z), Vector2.right), // east+ (new Vector2(size.x, size.z), new Vector2(0, size.z), Vector2.up), // north+ (new Vector2(0, size.z), new Vector2(0, 0), Vector2.left), // west+ };+ foreach (var (a, b, n) in edges)+ {+ int prev = -1; bool prevLand = false;+ for (int i = 0; i <= SkirtSamplesPerEdge; i++)+ {+ var p = Vector2.Lerp(a, b, (float)i / SkirtSamplesPerEdge);+ bool isLand = IsLand(Height(p));+ int spoke = Spoke(p, n, isLand);+ if (prev >= 0) Quad(prevLand || isLand ? land : sea, prev, spoke);+ prev = spoke; prevLand = isLand;+ }+ }+ // Corners: a fan between the two edges' outward spokes and the diagonal, in the corner sample's kind.+ for (int e = 0; e < edges.Length; e++)+ {+ var corner = edges[e].b; var n1 = edges[e].n; var n2 = edges[(e + 1) % edges.Length].n;+ bool isLand = IsLand(Height(corner));+ int s1 = Spoke(corner, n1, isLand), sd = Spoke(corner, n1, isLand, n2), s2 = Spoke(corner, n2, isLand);+ Quad(isLand ? land : sea, s1, sd); Quad(isLand ? land : sea, sd, s2);+ }+ var mesh = assets.Own(new Mesh { name = "BorderSkirt", indexFormat = UnityEngine.Rendering.IndexFormat.UInt32 });+ mesh.SetVertices(verts);+ mesh.subMeshCount = 2;+ mesh.SetTriangles(sea, 0); mesh.SetTriangles(land, 1);+ mesh.RecalculateNormals(); mesh.RecalculateBounds();+ return mesh;+ }+/// <summary>Vertices of one draped hex ring (<see cref="DrapedRing"/>).</summary>public const int RingVertices = 6 * OverlaySegmentsPerEdge;diff --git a/unity/Assets/Scripts/Map/MapScene.cs b/unity/Assets/Scripts/Map/MapScene.csindex 7913d410b..17fc4e5fb 100644--- a/unity/Assets/Scripts/Map/MapScene.cs+++ b/unity/Assets/Scripts/Map/MapScene.cs@@ -11,7 +11,7 @@ namespace Statecraft.Game.Map/// component calls Build(inputs) once the inputs are loaded (fetched on WebGL); editor tools call Build().</summary>public sealed class MapScene : MonoBehaviour{- [SerializeField] Material terrainMaterial, overlayMaterial, markerMaterial, selectionMaterial, seaMaterial;+ [SerializeField] Material terrainMaterial, overlayMaterial, markerMaterial, selectionMaterial, seaMaterial, borderLandMaterial;public GeoFrame Frame { get; private set; }/// <summary>hexes.json as the last Build read it (bounds, hex size, biomes).</summary>@@ -21,12 +21,8 @@ namespace Statecraft.Game.Map/// <summary>The selected hex's outline: a child of the terrain (so a rebuild destroys it).</summary>public const string SelectionName = "HexSelection";- /// <summary>The sea past the map's edge: a child of the terrain (so a rebuild destroys it).</summary>- public const string SeaPlaneName = "SeaPlane";- /// <summary>How far the sea plane reaches past the terrain on every side; the camera never sees farther (MaxDistance).</summary>- public const float SeaMarginM = 500_000f;- /// <summary>Depth of the sea plane under sea level, so the terrain's own sea draws over it inside the map.</summary>- public const float SeaPlaneDropM = 30f;+ /// <summary>The land and sea past the map's edge: a child of the terrain (so a rebuild destroys it).</summary>+ public const string BorderSkirtName = "BorderSkirt";/// <summary>Highlight colour of the selected hex (the UI's gold, brighter, to read against every biome); MapMaterials/// bakes it into the editor-made HexSelection.mat.</summary>public static readonly Color SelectionColour = new Color(1f, 0.84f, 0.38f);@@ -86,8 +82,11 @@ namespace Statecraft.Game.Mapmr.enabled = true;}- public void Configure(Material terrain, Material overlay, Material marker, Material selection, Material sea)- { terrainMaterial = terrain; overlayMaterial = overlay; markerMaterial = marker; selectionMaterial = selection; seaMaterial = sea; }+ public void Configure(Material terrain, Material overlay, Material marker, Material selection, Material sea, Material borderLand)+ {+ terrainMaterial = terrain; overlayMaterial = overlay; markerMaterial = marker; selectionMaterial = selection;+ seaMaterial = sea; borderLandMaterial = borderLand;+ }/// <summary>Builds from the repository files with System.IO (editor and desktop only).</summary>public void Build() => Build(GameInputs.MapFromDisk(Paths.Content, Paths.StreamingMap));@@ -100,6 +99,7 @@ namespace Statecraft.Game.Mapif (markerMaterial == null) throw new InvalidOperationException("MapScene: markerMaterial is not assigned");if (selectionMaterial == null) throw new InvalidOperationException("MapScene: selectionMaterial is not assigned");if (seaMaterial == null) throw new InvalidOperationException("MapScene: seaMaterial is not assigned");+ if (borderLandMaterial == null) throw new InvalidOperationException("MapScene: borderLandMaterial is not assigned");var cam = Camera.main;if (cam == null) throw new InvalidOperationException("MapScene needs a camera tagged MainCamera");@@ -110,7 +110,7 @@ namespace Statecraft.Game.MapterrainGo.transform.SetParent(transform, true);Terrain = terrainGo.GetComponent<Terrain>();var size = Terrain.terrainData.size;- AddSeaPlane(terrainGo.transform, size, (0f - meta.elev_min_m) * MapBuilder.VerticalExaggeration);+ AddBorderSkirt(terrainGo, meta.elev_min_m);Frame = new GeoFrame(meta.lon0, meta.lon1, meta.lat0, meta.lat1, size.x, size.z);var list = SettlementPlacer.Parse(inputs.SettlementsYaml, (meta.lon0, meta.lon1, meta.lat0, meta.lat1), SettlementsPath);SettlementPlacer.Place(list, Frame, Terrain, markerMaterial).transform.SetParent(transform, true);@@ -124,20 +124,17 @@ namespace Statecraft.Game.Mapassets.Own(rig.Volume.profile);}- /// <summary>A lit plane in the sea colour, just under sea level (0 m: heightmap sea), reaching SeaMarginM past the- /// terrain: past the map's edge the sea is lit as the terrain's sea is, so no seam shows (fix round 1). Drawn with the- /// editor-made Sea.mat on Unity's built-in quad; no collider, so clicks still pick only the terrain.</summary>- void AddSeaPlane(Transform terrain, Vector3 size, float seaLevelY)+ /// <summary>The land and sea past the map's edge (MapBuilder.BuildBorderSkirt), drawn with the editor-made Sea.mat and+ /// BorderLand.mat; no collider, so clicks still pick only the terrain. It lies outside the terrain's footprint only.</summary>+ void AddBorderSkirt(GameObject terrainGo, float elevMinM){- var plane = new GameObject(SeaPlaneName);- plane.transform.SetParent(terrain, false);- plane.AddComponent<MeshFilter>().sharedMesh = Resources.GetBuiltinResource<Mesh>("Quad.fbx");- var renderer = plane.AddComponent<MeshRenderer>();- renderer.sharedMaterial = seaMaterial;+ var skirt = new GameObject(BorderSkirtName);+ skirt.transform.SetParent(terrainGo.transform, false);+ skirt.AddComponent<MeshFilter>().sharedMesh =+ MapBuilder.BuildBorderSkirt(Terrain.terrainData, elevMinM, terrainGo.GetComponent<MapRuntimeAssets>());+ var renderer = skirt.AddComponent<MeshRenderer>();+ renderer.sharedMaterials = new[] { seaMaterial, borderLandMaterial };renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;- plane.transform.localPosition = new Vector3(size.x / 2, seaLevelY - SeaPlaneDropM, size.z / 2);- plane.transform.localRotation = Quaternion.Euler(90f, 0f, 0f); // the quad faces -Z; this turns it to face up- plane.transform.localScale = new Vector3(size.x + 2 * SeaMarginM, size.z + 2 * SeaMarginM, 1f);}static string MetaPath => "heightmap.json";diff --git a/unity/Assets/Tests/EditMode/MapActionUiTests.cs b/unity/Assets/Tests/EditMode/MapActionUiTests.csindex ebb05a27b..9c93b46b5 100644--- a/unity/Assets/Tests/EditMode/MapActionUiTests.cs+++ b/unity/Assets/Tests/EditMode/MapActionUiTests.cs@@ -114,7 +114,8 @@ public class MapActionUiTestsAssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/HexOverlay.mat"),AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/SettlementMarker.mat"),AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/HexSelection.mat"),- AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/Sea.mat"));+ AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/Sea.mat"),+ AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/BorderLand.mat"));map.Build();var layer = new GameObject("Placements").AddComponent<PlacementLayer>();var tlv = C.SettlementHexes.Single(s => s.Id == "tel_aviv");@@ -242,7 +243,8 @@ public class MapActionUiTestsAssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/HexOverlay.mat"),AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/SettlementMarker.mat"),AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/HexSelection.mat"),- AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/Sea.mat"));+ AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/Sea.mat"),+ AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/BorderLand.mat"));map.Build();Physics.SyncTransforms();return map;diff --git a/unity/Assets/Tests/EditMode/SettlementTests.cs b/unity/Assets/Tests/EditMode/SettlementTests.csindex ccfd33615..f9347e6ca 100644--- a/unity/Assets/Tests/EditMode/SettlementTests.cs+++ b/unity/Assets/Tests/EditMode/SettlementTests.cs@@ -130,7 +130,7 @@ public class MapSceneTestsstatic string RealYamlPath => Path.Combine(Paths.Content, "map", "settlements_1948.yaml");const string TerrainMatPath = "Assets/Materials/Terrain.mat", OverlayMatPath = "Assets/Materials/HexOverlay.mat",- MarkerMatPath = "Assets/Materials/SettlementMarker.mat", SelectionMatPath = "Assets/Materials/HexSelection.mat", SeaMatPath = "Assets/Materials/Sea.mat";+ MarkerMatPath = "Assets/Materials/SettlementMarker.mat", SelectionMatPath = "Assets/Materials/HexSelection.mat", SeaMatPath = "Assets/Materials/Sea.mat", BorderLandMatPath = "Assets/Materials/BorderLand.mat";[SetUp] public void FreshScene() => EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);@@ -143,7 +143,7 @@ public class MapSceneTests{if (withCamera) new GameObject("TestMainCamera") { tag = "MainCamera" }.AddComponent<Camera>();var map = new GameObject("MapScene").AddComponent<MapScene>();- map.Configure(Load(TerrainMatPath), Load(OverlayMatPath), Load(MarkerMatPath), Load(SelectionMatPath), Load(SeaMatPath));+ map.Configure(Load(TerrainMatPath), Load(OverlayMatPath), Load(MarkerMatPath), Load(SelectionMatPath), Load(SeaMatPath), Load(BorderLandMatPath));return map;}@@ -180,28 +180,172 @@ public class MapSceneTestsAssert.Less(cam.ViewportPointToRay(new Vector3(x, 1f, 0)).direction.y, 0f, $"top edge at x={x} looks down");}- /// <summary>Fix round 1 (review M7, the sea seam): a lit sea plane at sea level, under the terrain, carries the sea past- /// the map's edge, drawn with the editor-made Sea.mat (URP Lit, the sea biome colour, matte like the terrain).</summary>+ /// <summary>Fix round 2 (R2-1, N1): outside the heightmap's bbox each side continues the terrain edge next to it: sea+ /// where the edge is sea (Sea.mat), muted land where it is land (BorderLand.mat), so Sinai, Jordan and Lebanon do not+ /// read as sea. The skirt lies entirely outside the terrain's footprint, so nothing covers land below sea level.</summary>[Test]- public void ASeaPlaneCarriesTheSeaPastTheTerrain()+ public void TheBorderSkirtContinuesEachEdgeOutsideTheMap(){var map = NewMap(); map.Build();- var plane = map.Terrain.transform.Find(MapScene.SeaPlaneName);- Assert.IsNotNull(plane, "the sea plane exists");- var mr = plane.GetComponent<MeshRenderer>();- var sea = Load(SeaMatPath);- Assert.AreSame(sea, mr.sharedMaterial, "the editor-made sea material, not an instance");- Assert.AreEqual("Universal Render Pipeline/Lit", sea.shader.name, "lit like the terrain");- var c = sea.GetColor("_BaseColor"); var want = MapBuilder.BiomeColours["sea"];- Assert.Less(Mathf.Abs(c.r - want.r) + Mathf.Abs(c.g - want.g) + Mathf.Abs(c.b - want.b), 1e-3f, "the sea biome colour");+ Assert.IsNull(map.Terrain.transform.Find("SeaPlane"), "no plane over the terrain (fix round 2, N1)");+ var skirt = map.Terrain.transform.Find(MapScene.BorderSkirtName);+ Assert.IsNotNull(skirt, "the border skirt exists");+ var mr = skirt.GetComponent<MeshRenderer>();+ CollectionAssert.AreEqual(new[] { Load(SeaMatPath), Load(BorderLandMatPath) }, mr.sharedMaterials, "sea, then land: editor-made");+ Assert.AreEqual("Universal Render Pipeline/Lit", Load(BorderLandMatPath).shader.name);+ var mesh = skirt.GetComponent<MeshFilter>().sharedMesh;+ var verts = mesh.vertices;var size = map.Terrain.terrainData.size;- var b = mr.bounds;- Assert.Less(b.min.x, -400000f); Assert.Greater(b.max.x, size.x + 400000f);- Assert.Less(b.min.z, -400000f); Assert.Greater(b.max.z, size.z + 400000f);- var seaHex = System.Array.Find(map.Hexes.hexes, h => h.biome == "sea");- var seaY = map.Terrain.SampleHeight(map.Frame.ToWorld(seaHex.lon, seaHex.lat, 0));- Assert.Less(b.max.y, seaY, "under the terrain's sea, so the terrain draws inside its bounds");- Assert.Greater(b.max.y, seaY - 100f, "at sea level");+ // Which submesh covers a point (world x, z) just outside the map, from lon/lat.+ int Cover(double lat, double lon)+ {+ var p = map.Frame.ToWorld(lon, lat, 0);+ for (int sm = 0; sm < mesh.subMeshCount; sm++)+ {+ var t = mesh.GetTriangles(sm);+ for (int k = 0; k < t.Length; k += 3)+ if (Inside(new Vector2(p.x, p.z), verts[t[k]], verts[t[k + 1]], verts[t[k + 2]])) return sm;+ }+ return -1;+ }+ Assert.AreEqual(1, Cover(31.95, 36.05), "east of the map at Amman's latitude: Jordan, land");+ Assert.AreEqual(1, Cover(29.30, 34.50), "south of the map: Sinai, land");+ Assert.AreEqual(0, Cover(32.00, 34.05), "west of the map off the coast: sea");+ Assert.AreEqual(1, Cover(33.50, 35.60), "north of the map inland: Lebanon, land");+ Assert.AreEqual(0, Cover(33.50, 34.50), "north-west of the map: sea");+ Assert.AreEqual(1, Cover(29.40, 34.30), "south-west corner: Sinai, land");+ // Nothing of the skirt lies over the terrain (N1): every triangle is outside the footprint.+ for (int sm = 0; sm < mesh.subMeshCount; sm++)+ {+ var t = mesh.GetTriangles(sm);+ for (int k = 0; k < t.Length; k += 3)+ {+ var c = (verts[t[k]] + verts[t[k + 1]] + verts[t[k + 2]]) / 3;+ Assert.IsFalse(c.x > 1f && c.x < size.x - 1f && c.z > 1f && c.z < size.z - 1f, $"skirt triangle over the terrain at {c}");+ }+ }+ // Its inner edge meets the terrain's edge (no gap, no step).+ var edge = System.Array.FindAll(verts, v => Mathf.Abs(v.x - size.x) < 0.5f && v.z > 1000f && v.z < size.z - 1000f);+ Assert.Greater(edge.Length, 100);+ foreach (var v in edge)+ Assert.AreEqual(map.Terrain.SampleHeight(new Vector3(v.x - 0.5f, 0, v.z)), v.y, 2f, $"east edge at z={v.z}");+ // Facing up (seen from the camera's side).+ var used = new HashSet<int>();+ for (int sm = 0; sm < mesh.subMeshCount; sm++) used.UnionWith(mesh.GetTriangles(sm));+ var normals = mesh.normals;+ foreach (var i in used) Assert.Greater(normals[i].y, 0f, $"vertex {i} faces up");+ }++ static bool Inside(Vector2 p, Vector3 a, Vector3 b, Vector3 c)+ {+ float Side(Vector2 p1, Vector3 p2, Vector3 p3) => (p1.x - p3.x) * (p2.z - p3.z) - (p2.x - p3.x) * (p1.y - p3.z);+ float d1 = Side(p, a, b), d2 = Side(p, b, c), d3 = Side(p, c, a);+ bool neg = d1 < 0 || d2 < 0 || d3 < 0, pos = d1 > 0 || d2 > 0 || d3 > 0;+ return !(neg && pos);+ }++ /// <summary>Renders the real scene (Map.unity's light, rig and post-processing) looking at <paramref name="look"/> and+ /// returns the pixel colour of each world point.</summary>+ static System.Collections.IEnumerator RenderAt(Vector3 look, float distance, Vector3[] points, Color[] colours, int radius = 0, bool darkest = false)+ {+ var cam = Camera.main; var rig = cam.GetComponent<CameraRig>();+ rig.LookAt = look; rig.Distance = distance; rig.Yaw = 0; rig.TopInset = 0; rig.Apply();+ var rt = new RenderTexture(1600, 900, 24);+ var tex = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false);+ try+ {+ cam.targetTexture = rt;+ yield return null;+ cam.Render();+ RenderTexture.active = rt;+ tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0); tex.Apply();+ for (int i = 0; i < points.Length; i++)+ {+ var p = cam.WorldToScreenPoint(points[i]); // while the camera still renders into the texture+ var best = tex.GetPixel((int)p.x, (int)p.y);+ for (int dx = -radius; dx <= radius; dx++)+ for (int dy = -radius; dy <= radius; dy++)+ {+ var c = tex.GetPixel((int)p.x + dx, (int)p.y + dy);+ if (darkest && c.r + c.g + c.b < best.r + best.g + best.b) best = c;+ }+ colours[i] = best;+ }+ }+ finally+ {+ RenderTexture.active = null; cam.targetTexture = null;+ rt.Release(); Object.DestroyImmediate(rt); Object.DestroyImmediate(tex);+ }+ }++ static bool LandColour(Color c) => c.r > c.b + 0.05f;+ static bool SeaColour(Color c) => c.b > c.r + 0.15f;++ /// <summary>Fix round 2 (R2-1), rendered: just past the east (Amman's latitude) and south (Sinai) edges the backdrop is+ /// land-coloured, past the west edge sea-coloured.</summary>+ [UnityTest]+ public System.Collections.IEnumerator TheBackdropIsLandWhereTheNeighboursAreLand()+ {+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);+ var map = Object.FindFirstObjectByType<MapScene>();+ map.Build();+ foreach (var (name, lat, lon, land) in new[] { ("east (Jordan)", 31.95, 36.0, true), ("south (Sinai)", 29.38, 34.5, true), ("west (sea)", 32.0, 34.12, false), ("north (Lebanon)", 33.42, 35.6, true) })+ {+ var at = map.Frame.ToWorld(lon, lat, 0);+ var edge = map.Frame.ToWorld(System.Math.Min(System.Math.Max(lon, 34.2), 35.9), System.Math.Min(System.Math.Max(lat, 29.45), 33.35), 0);+ at.y = edge.y = map.Terrain.SampleHeight(edge);+ var colours = new Color[1];+ yield return RenderAt(edge, 90000f, new[] { at }, colours);+ TestContext.WriteLine($"{name}: {colours[0]}");+ Assert.IsTrue(land ? LandColour(colours[0]) : SeaColour(colours[0]), $"{name}: {(land ? "land" : "sea")} expected, rendered {colours[0]}");+ }+ }++ /// <summary>Fix round 2 (N1), rendered: the land below sea level (the Jordan valley, Beit She'an, the Dead Sea's shores+ /// and the Arava) shows its biome colour, its hex lines and its settlement markers; nothing covers it.</summary>+ [UnityTest]+ public System.Collections.IEnumerator TheRiftBelowSeaLevelIsVisible()+ {+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);+ var map = Object.FindFirstObjectByType<MapScene>();+ map.Build();+ float size = map.Hexes.hex_size_km * 1000f;+ // The lowest land hex in each band: Beit She'an valley, the Jordan valley by Jericho, the Arava north of Eilat.+ foreach (var (name, lat0, lat1) in new[] { ("Beit She'an valley", 32.35, 32.65), ("Jordan valley (Jericho)", 31.75, 32.05), ("Dead Sea shore / northern Arava", 30.6, 31.2) })+ {+ HexJson low = null;+ foreach (var h in map.Hexes.hexes)+ if (h.land && h.lat >= lat0 && h.lat <= lat1 && h.biome != "lake" && (low == null || h.elev_m < low.elev_m)) low = h;+ Assert.IsNotNull(low, name);+ Assert.Less(low.elev_m, -10f, $"{name}: a hex below the old plane's -10 m");+ var centre = map.Frame.ToWorld(low.lon, low.lat, 0); centre.y = map.Terrain.SampleHeight(centre);+ var corner2 = HexMath.Corner(new Vector2(centre.x, centre.z), size, 0);+ var corner = new Vector3(corner2.x, 0, corner2.y); corner.y = map.Terrain.SampleHeight(corner) + MapBuilder.OverlayClearanceM;+ var colours = new Color[1]; var lines = new Color[1];+ yield return RenderAt(centre, 40000f, new[] { centre }, colours);+ yield return RenderAt(centre, 40000f, new[] { corner }, lines, radius: 2, darkest: true);+ TestContext.WriteLine($"{name} ({low.q}, {low.r}) {low.elev_m:0} m: centre {colours[0]}, line {lines[0]}");+ Assert.IsTrue(LandColour(colours[0]), $"{name}: the {low.biome} colour, rendered {colours[0]}");+ Assert.Less(lines[0].r + lines[0].g + lines[0].b, 0.75f * (colours[0].r + colours[0].g + colours[0].b), $"{name}: the hex line shows, rendered {lines[0]}");+ }+ // Settlement markers in the rift (below -10 m) are drawn: the pixel at the marker's top is not the sea colour.+ var root = GameObject.Find("Settlements").transform;+ int seen = 0;+ foreach (Transform box in root)+ {+ if (box.name.EndsWith("_label") || box.GetComponent<MeshRenderer>() == null) continue;+ var ground = map.Terrain.SampleHeight(box.position);+ var realElevation = ground / MapBuilder.VerticalExaggeration + HeightmapLoader.Load(Paths.StreamingMap).meta.elev_min_m;+ if (realElevation > -10f) continue;+ var top = box.position + Vector3.up * box.lossyScale.y / 2;+ var colours = new Color[1];+ yield return RenderAt(box.position, 40000f, new[] { top }, colours);+ TestContext.WriteLine($"marker {box.name} at {realElevation:0} m: {colours[0]}");+ Assert.IsFalse(SeaColour(colours[0]), $"marker {box.name} is hidden ({colours[0]})");+ seen++;+ }+ Assert.Greater(seen, 0, "the rift has settlement markers to check");}/// <summary>Fix round 1 (the sea seam), rendered: at the west and north-west edges of the map, the sea on the terrain and@@ -316,15 +460,18 @@ public class MapSceneTestspublic void BuildWithoutMaterialsNamesTheMissingField(){var map = new GameObject("MapScene").AddComponent<MapScene>();- map.Configure(Load(TerrainMatPath), Load(OverlayMatPath), null, Load(SelectionMatPath), Load(SeaMatPath));+ map.Configure(Load(TerrainMatPath), Load(OverlayMatPath), null, Load(SelectionMatPath), Load(SeaMatPath), Load(BorderLandMatPath));var ex = Assert.Throws<System.InvalidOperationException>(() => map.Build());StringAssert.Contains("markerMaterial", ex.Message);- map.Configure(Load(TerrainMatPath), Load(OverlayMatPath), Load(MarkerMatPath), null, Load(SeaMatPath));+ map.Configure(Load(TerrainMatPath), Load(OverlayMatPath), Load(MarkerMatPath), null, Load(SeaMatPath), Load(BorderLandMatPath));ex = Assert.Throws<System.InvalidOperationException>(() => map.Build());StringAssert.Contains("selectionMaterial", ex.Message);- map.Configure(Load(TerrainMatPath), Load(OverlayMatPath), Load(MarkerMatPath), Load(SelectionMatPath), null);+ map.Configure(Load(TerrainMatPath), Load(OverlayMatPath), Load(MarkerMatPath), Load(SelectionMatPath), null, Load(BorderLandMatPath));ex = Assert.Throws<System.InvalidOperationException>(() => map.Build());StringAssert.Contains("seaMaterial", ex.Message);+ map.Configure(Load(TerrainMatPath), Load(OverlayMatPath), Load(MarkerMatPath), Load(SelectionMatPath), Load(SeaMatPath), null);+ ex = Assert.Throws<System.InvalidOperationException>(() => map.Build());+ StringAssert.Contains("borderLandMaterial", ex.Message);}[Test]@@ -351,7 +498,7 @@ public class MapSceneTestsvar map = NewMap(); map.Build();var go = map.gameObject; Object.DestroyImmediate(map);var fresh = go.AddComponent<MapScene>();- fresh.Configure(Load(TerrainMatPath), Load(OverlayMatPath), Load(MarkerMatPath), Load(SelectionMatPath), Load(SeaMatPath));+ fresh.Configure(Load(TerrainMatPath), Load(OverlayMatPath), Load(MarkerMatPath), Load(SelectionMatPath), Load(SeaMatPath), Load(BorderLandMatPath));fresh.Build();AssertOneOfEach();}