From 021c4cbcbf166eb30e4e36284c52f95478eed593 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 04:36:28 +0200 Subject: [PATCH 01/20] Gravity: one potential per zone owns acceleration and height GravityField is the law of one well (logarithmic tail, softened core). Zone.GetForce and GetHeight sum it over the bodies; GetNormal derives from the force for ship tilt; Flow and Ship read GetForce. Well strength, core radius and Roche limit are PlanetSettings curves of mass, height exaggeration K one global. Deletes GravityAcceleration, GravityReferenceRate, GravityStrength, the PowerPulse well, GetNormal's finite differences and BodyData.GravityDepthExponent. Settings.asset carries the calibrated curves. Tests: PotentialOwnerTests, the moon's moon placement, retired keys over every BodyData type, a body-derived giant sweep. Not yet built or run (verify job follows); this commit may not build. Co-Authored-By: Claude Opus 5.5 --- Assets/Resources/Settings.asset | 4 +- Assets/Scripts/ServerShared/GravityField.cs | 27 +++ .../Scripts/ServerShared/GravityField.cs.meta | 11 + Assets/Scripts/ServerShared/Settings.cs | 12 +- Assets/Scripts/ServerShared/Ship.cs | 3 +- Assets/Scripts/ServerShared/Zone.cs | 71 +++--- Assets/Scripts/ServerShared/ZoneData.cs | 3 - .../Aetheria.Shared.Tests/FireControlTests.cs | 2 +- .../FloatingBodyTests.cs | 74 ++---- tests/Aetheria.Shared.Tests/FlowFieldTests.cs | 32 ++- .../GravitySubtractTests.cs | 77 ++++--- tests/Aetheria.Shared.Tests/LootTests.cs | 6 +- tests/Aetheria.Shared.Tests/MineTests.cs | 4 +- .../PotentialOwnerTests.cs | 216 ++++++++++++++++++ tests/Aetheria.Shared.Tests/WellFixture.cs | 19 +- .../ZonePlacedAtBuildTests.cs | 43 +++- 16 files changed, 433 insertions(+), 171 deletions(-) create mode 100644 Assets/Scripts/ServerShared/GravityField.cs create mode 100644 Assets/Scripts/ServerShared/GravityField.cs.meta create mode 100644 tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs diff --git a/Assets/Resources/Settings.asset b/Assets/Resources/Settings.asset index 64c4333d7..7b85163f5 100644 --- a/Assets/Resources/Settings.asset +++ b/Assets/Resources/Settings.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:319895214aaeea5d4dfe034c46edca055f62c6b4a9692788e60ce8a5827c4b78 -size 12634 +oid sha256:8eaa1790664477d84e442fbefc89dbd83f0b6948b4433f721f67a78703c6d7b4 +size 12871 diff --git a/Assets/Scripts/ServerShared/GravityField.cs b/Assets/Scripts/ServerShared/GravityField.cs new file mode 100644 index 000000000..53c2755a0 --- /dev/null +++ b/Assets/Scripts/ServerShared/GravityField.cs @@ -0,0 +1,27 @@ +using CultMath; +using static CultMath.math; +using float2 = CultMath.float2; + +/// +/// The law of one gravity well: a 2D point mass with a softened core. Outside the core radius the potential is +/// logarithmic and the pull is c / r; inside it the pull falls linearly to zero at the centre and meets the tail in +/// value and slope at the core radius. c is the well's strength (u^2/s^2), R its core radius (u). No threshold +/// anywhere: a well pulls at every distance. Zone.GetForce and Zone.GetHeight sum this over a zone's bodies. +/// +public static class GravityField +{ + // The potential at distance r from the body, defined up to a constant (callers subtract their reference). + public static float Potential(float c, float coreRadius, float r) => + r < coreRadius + ? c * r * r / (2 * coreRadius * coreRadius) + : c * (log(r / coreRadius) + .5f); + + // The acceleration at `offsetFromBody`, toward the body: zero at the body itself. + public static float2 Acceleration(float c, float coreRadius, float2 offsetFromBody) + { + var r = length(offsetFromBody); + if (r == 0f) return float2.zero; + var pull = r < coreRadius ? c * r / (coreRadius * coreRadius) : c / r; + return -offsetFromBody / r * pull; + } +} diff --git a/Assets/Scripts/ServerShared/GravityField.cs.meta b/Assets/Scripts/ServerShared/GravityField.cs.meta new file mode 100644 index 000000000..929e64b6d --- /dev/null +++ b/Assets/Scripts/ServerShared/GravityField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5b0c7d3e9a1f4e2c8d6a7f1b3c9e0a42 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/ServerShared/Settings.cs b/Assets/Scripts/ServerShared/Settings.cs index ab422c7fa..a0fa7c7d9 100644 --- a/Assets/Scripts/ServerShared/Settings.cs +++ b/Assets/Scripts/ServerShared/Settings.cs @@ -17,11 +17,21 @@ public class PlanetSettings public ExponentialCurve GravityRadius; public ExponentialCurve LightRadius; public ExponentialCurve BodyRadius; + + // The closest a child may orbit its parent, in u, by the parent's mass. Authored like BodyRadius, never per body. + public ExponentialCurve RocheLimit = new ExponentialCurve(); + + // A body's well, by its mass (GravityField): its strength c in u^2/s^2 (the pull is c / r beyond the core) and its + // softened core radius in u, which must stay inside the RocheLimit curve. + public ExponentialCurve WellStrength = new ExponentialCurve(); + public ExponentialCurve CoreRadius = new ExponentialCurve(); + + // The one global exaggeration of gravity height: height = potential / K, in u/s^2 per unit of height. + public float HeightExaggeration = 1f; public float AsteroidVerticalOffset = -5f; public ExponentialLerp AsteroidSize; public ExponentialLerp AsteroidHitpoints; public ExponentialLerp AsteroidRespawnTime; - public float GravityStrength; public float SecureAreaRadiusMultiplier = .45f; public ExponentialCurve OrbitPeriod; diff --git a/Assets/Scripts/ServerShared/Ship.cs b/Assets/Scripts/ServerShared/Ship.cs index e5759f4cc..560afce17 100644 --- a/Assets/Scripts/ServerShared/Ship.cs +++ b/Assets/Scripts/ServerShared/Ship.cs @@ -130,9 +130,8 @@ public class Ship : Entity Position.xz += Velocity * delta; + Velocity += Zone.GetForce(Position.xz) * delta; var normal = Zone.GetNormal(Position.xz); - var force = new float2(normal.x, normal.z); - Velocity += Zone.GravityAcceleration(force, Zone.Settings.GravityStrength) * delta; var shipRight = Direction.Rotate(ItemRotation.Clockwise); var forward = cross(float3(shipRight.x, 0, shipRight.y), normal); Rotation = quaternion.LookRotation(forward, normal); diff --git a/Assets/Scripts/ServerShared/Zone.cs b/Assets/Scripts/ServerShared/Zone.cs index 1b3604b54..423f48ed2 100644 --- a/Assets/Scripts/ServerShared/Zone.cs +++ b/Assets/Scripts/ServerShared/Zone.cs @@ -617,17 +617,12 @@ public class Zone var result = 0f; foreach (var body in PlanetInstances.Values) { - var p = position - body.Orbit.Position; //GetOrbitPosition(body.BodyData.Orbit) - var distSqr = lengthsq(p); - var gravityRadius = body.GravityWellRadius; - if (distSqr < gravityRadius*gravityRadius) - { - var depth = body.GravityWellDepth; - result -= PowerPulse(sqrt(distSqr) / gravityRadius, body.BodyData.GravityDepthExponent) * depth; - } + var offset = position - body.Orbit.Position; + result += GravityField.Potential(body.WellStrength, body.CoreRadius, length(offset)) + - GravityField.Potential(body.WellStrength, body.CoreRadius, Pack.Radius); } - return result; + return result / Settings.HeightExaggeration; } public float GetLight(float2 position) @@ -647,33 +642,21 @@ public class Zone internal float SchematicCellSize => _itemManager.GameplaySettings.SchematicCellSize; internal float FieldCrossSection(AsteroidBeltData belt) => _itemManager.ItemData.Get(belt.Kind)?.CrossSection ?? 0f; - // The one law of how a gravity well pushes anything: ships, floating items and mines all read it. The shape is - // the one ships have always felt, normalize(f) * strength * (1 / (1 - |f|^2) - 1), gated off below |f|^2 = .001. - // It is an acceleration, per second: the legacy law added that amount once per 60 fps frame with no dt, so - // GravityReferenceRate (60) restates it and `acceleration * dt` gives the legacy push at 60 fps. - public const float GravityReferenceRate = 60f; - - public static float2 GravityAcceleration(float2 normalXz, float strength) - { - var magnitude = lengthsq(normalXz); - if (magnitude <= .001f) return float2.zero; - return normalize(normalXz) * strength * (1 / (1 - magnitude) - 1) * GravityReferenceRate; - } - - // The acceleration the well exerts at `position`. + // The one source of gravitational acceleration (u/s^2): the sum of every body's well (GravityField). Ships, + // floating items, clouds and mines all read it, and so does Flow. It is the gradient of the potential GetHeight + // draws, so the two cannot disagree. public float2 GetForce(float2 position) { - var normal = GetNormal(position); - return GravityAcceleration(new float2(normal.x, normal.z), Settings.GravityStrength); + var force = float2.zero; + foreach (var body in PlanetInstances.Values) + force += GravityField.Acceleration(body.WellStrength, body.CoreRadius, position - body.Orbit.Position); + return force; } // The global flow velocity at `position` in zone time, in u/s (FlowField is the law). The slope term reads the - // downhill gradient, which GetNormal's xz is proportional to. - public float3 Flow(float3 position) - { - var normal = GetNormal(position.xz); - return FlowField.At(Settings.Flow, position, FlowScroll, new float2(normal.x, normal.z)); - } + // downhill direction, which is the force. + public float3 Flow(float3 position) => + FlowField.At(Settings.Flow, position, FlowScroll, GetForce(position.xz)); // The flow's noise scroll at zone time (Zone.Flow evaluates at exactly this); lowered to the shaders' _FlowScroll. public float2 FlowScroll => FlowField.Scroll(Settings.Flow, _time); @@ -688,16 +671,12 @@ public class Zone return pow((x + 1) * (1 - x), exponent); } - public float3 GetNormal(float2 pos, float step = .1f, float mul = 1) + // The surface normal of the drawn height (potential / K), derived from the force. Display only (ship tilt): the + // sim never reads it as a force. + public float3 GetNormal(float2 pos) { - float hL = GetHeight(new float2(pos.x - step, pos.y)) * mul; - float hR = GetHeight(new float2(pos.x + step, pos.y)) * mul; - float hD = GetHeight(new float2(pos.x, pos.y - step)) * mul; - float hU = GetHeight(new float2(pos.x, pos.y + step)) * mul; - - // Deduce terrain normal - float3 normal = new float3((hL - hR), (hD - hU), step*2); - return normalize(normal).xzy; + var slope = GetForce(pos) / Settings.HeightExaggeration; + return normalize(new float3(slope.x, 1f, slope.y)); } } @@ -706,10 +685,17 @@ public class Planet public Orbit Orbit; protected readonly PlanetSettings Settings; public BodyData BodyData; + // Brush inputs only (ZoneRenderer's Gravity Well brushes and planet icon); no sim reader. grid-lowering deletes them. public float GravityWellDepth; public float GravityWellRadius; public float BodyRadius; + // The well (GravityField): strength c and softened core radius R by mass, and the Roche limit, the closest a child + // may orbit. All three are authored PlanetSettings curves of mass; the core must sit inside the Roche limit. + public float WellStrength; + public float CoreRadius; + public float RocheLimit; + public Planet(PlanetSettings settings, BodyData data, Orbit orbit) { Settings = settings; @@ -723,6 +709,11 @@ public class Planet BodyRadius = Settings.BodyRadius.Evaluate(BodyData.Mass) * BodyData.BodyRadiusMultiplier; GravityWellRadius = Settings.GravityRadius.Evaluate(BodyData.Mass) * BodyData.GravityRadiusMultiplier; GravityWellDepth = Settings.GravityDepth.Evaluate(BodyData.Mass) * BodyData.GravityDepthMultiplier; + WellStrength = Settings.WellStrength.Evaluate(BodyData.Mass); + CoreRadius = Settings.CoreRadius.Evaluate(BodyData.Mass); + RocheLimit = Settings.RocheLimit.Evaluate(BodyData.Mass); + if (WellStrength > 0 && !(0 < CoreRadius && CoreRadius < RocheLimit)) + throw new InvalidOperationException("A body's core radius must be positive and inside its Roche limit (PlanetSettings.CoreRadius, RocheLimit)."); } } diff --git a/Assets/Scripts/ServerShared/ZoneData.cs b/Assets/Scripts/ServerShared/ZoneData.cs index 70448ac40..a609db234 100644 --- a/Assets/Scripts/ServerShared/ZoneData.cs +++ b/Assets/Scripts/ServerShared/ZoneData.cs @@ -92,9 +92,6 @@ public abstract class BodyData [JsonProperty("depthMul")] [Key(7)] public float GravityDepthMultiplier = 1; - - [JsonProperty("depthExp")] [Key(8)] - public float GravityDepthExponent = 16; } [CultDocument("aetheria.planetdata", "1"), MessagePackObject, JsonObject(MemberSerialization.OptIn)] diff --git a/tests/Aetheria.Shared.Tests/FireControlTests.cs b/tests/Aetheria.Shared.Tests/FireControlTests.cs index d4d0ba50d..735e84a1f 100644 --- a/tests/Aetheria.Shared.Tests/FireControlTests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlTests.cs @@ -90,7 +90,7 @@ public sealed class FireControlTests : IDisposable var items = new ItemManager(_openCache, ledger, TestSettings(), _ => { }); var planets = new PlanetSettings(); var pack = new ZonePack(); - if (well) WellFixture.Dig(_openCache, pack, planets, pack.Radius, 1000f, 1f); + if (well) WellFixture.Dig(_openCache, pack, planets, 300f, 100f); var zone = new Zone(items, planets, pack, new GalaxyZone { Name = "Test Zone", Owner = null }, null); var hullRef = items.ItemData.RefOf(items.ItemData.GetByName("TestHull")); diff --git a/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs b/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs index e4ee47cfe..fbf68bf79 100644 --- a/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs +++ b/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs @@ -168,53 +168,7 @@ public sealed class FloatingBodyTests : IDisposable Assert.NotEqual(new FloatingBodyId(7), new FloatingBodyId(8)); } - // The law ships felt at 3035230b, written out here from that tree's Ship.Update (a per-tick velocity add, no dt) - // and not from Zone: the pin must not move when Zone's law does. - private static float2 LegacyPushPerFrame(float2 f, float strength) - { - var m = lengthsq(f); - if (m <= .001f) return float2.zero; - return normalize(f) * strength * (1 / (1 - m) - 1); - } - - [Fact] - public void TheGravityLawPushesShipsAsItDidAtSixtyFps() - { - foreach (var strength in new[] { 1f, 7.5f }) - foreach (var f in new[] { new float2(.1f, 0), new float2(.2f, .1f), new float2(-.3f, .4f), new float2(.5f, -.5f), new float2(0, .7f) }) - { - var legacy = LegacyPushPerFrame(f, strength); - var perFrame = Zone.GravityAcceleration(f, strength) * (1f / 60f); - var tolerance = Math.Max(1e-7f, length(legacy) * 1e-5f); - Assert.InRange(perFrame.x, legacy.x - tolerance, legacy.x + tolerance); - Assert.InRange(perFrame.y, legacy.y - tolerance, legacy.y + tolerance); - } - // Per second: halving dt halves the push, so the law holds at any tick rate. - var a = Zone.GravityAcceleration(new float2(.3f, .1f), 2f); - Assert.Equal(a.x * .5f, (a * (1f / 120f)).x * 60f, 5); - // The gate: |f|^2 at or below .001 pushes nothing. - Assert.Equal(float2.zero, Zone.GravityAcceleration(new float2(.03f, 0), 1f)); - Assert.NotEqual(float2.zero, Zone.GravityAcceleration(new float2(.0317f, 0), 1f)); - } - - [Fact] - public void DriftMatchesLegacyFloatingItemsAtSixtyFps() - { - // After 5 s at 60 fps with GravityStrength 1 and a normal of length |f| along x, the legacy GridObject drift - // position (measured by Soul, 2026-10-07, off 3035230b's GridObject.Update): |f| .05 -> 1.7371, .1 -> 7.0012, - // .3 -> 68.55, .5 -> 231.04. The sim steps the same law with exp decay where GridObject used 1 - k dt. - var s = Settings(); - foreach (var (norm, expected) in new[] { (.05f, 1.7371f), (.1f, 7.0012f), (.3f, 68.55f), (.5f, 231.04f) }) - { - var body = Run(new KinematicBody(), 5f, 1f / 60f, Zone.GravityAcceleration(new float2(norm, 0), 1f), s); - Assert.InRange(body.Position.x, expected * .999f, expected * 1.001f); - Assert.Equal(0f, body.Position.y, 4); - } - } - - // Ship.Update's own gravity line, through the real ship and a real zone (no planets: the zone's well alone - // gives a slope). The expectation is built from the zone's own normal and the 3035230b ship law, so flipping - // the sign or changing how delta enters the line fails here, not only the Zone function's pin above. + // Ship.Update's own gravity line, through the real ship and a real zone with one well at the origin. private Ship ShipAt(float x, out Zone zone) { var cache = AetheriaStores.Open(Path.Combine(_root, Guid.NewGuid().ToString("N") + ".cc"), Path.Combine(_root, Guid.NewGuid().ToString("N") + ".run.cc"), catalogWritable: true); @@ -230,9 +184,9 @@ public sealed class FloatingBodyTests : IDisposable QualityPriceModifier = new ExponentialLerp() }; var items = new ItemManager(cache, new ProvenanceLedger(), settings, _ => { }); - var planets = new PlanetSettings { GravityStrength = 1 }; + var planets = new PlanetSettings(); var pack = new ZonePack { Radius = 1000 }; - WellFixture.Dig(cache, pack, planets, 1000, 1000, 1); + WellFixture.Dig(cache, pack, planets, 300, 100); zone = new Zone(items, planets, pack, new GalaxyZone { Name = "Test Zone", Owner = null }, null); var design = cache.GetByName("Skiff"); var hull = new EquippableItem @@ -248,21 +202,27 @@ public sealed class FloatingBodyTests : IDisposable } [Fact] - public void AShipInAWellIsPulledTowardItByTheLawPerSecond() + public void AShipInAWellIsPulledByThePotential() { foreach (var delta in new[] { 1f / 60f, 1f / 30f }) { var ship = ShipAt(400f, out var zone); - var normal = zone.GetNormal(ship.Position.xz); - var push = LegacyPushPerFrame(new float2(normal.x, normal.z), zone.Settings.GravityStrength) * (delta * 60f); - Assert.True(push.x < 0f, "the well must pull a ship at +x toward the centre"); + var at = ship.Position.xz; + var expected = zone.GetForce(at) * delta; + Assert.True(expected.x < 0f, "the well must pull a ship at +x toward the centre"); ship.Update(delta); - var tolerance = Math.Max(1e-6f, length(push) * 1e-4f); - Assert.InRange(ship.Velocity.x, push.x - tolerance, push.x + tolerance); - Assert.InRange(ship.Velocity.y, push.y - tolerance, push.y + tolerance); + var tolerance = Math.Max(1e-7f, length(expected) * 1e-4f); + Assert.InRange(ship.Velocity.x, expected.x - tolerance, expected.x + tolerance); + Assert.InRange(ship.Velocity.y, expected.y - tolerance, expected.y + tolerance); + + var normal = zone.GetNormal(at); + var q = ship.Rotation; + var u = float3(q.x, q.y, q.z); + var v = float3(0, 1, 0); + var up = v + 2 * (q.w * cross(u, v) + cross(u, cross(u, v))); + Assert.True(length(up - normal) < 1e-4f, "the ship tilts to the zone's surface normal"); } } - } diff --git a/tests/Aetheria.Shared.Tests/FlowFieldTests.cs b/tests/Aetheria.Shared.Tests/FlowFieldTests.cs index 4924daa81..719ee1283 100644 --- a/tests/Aetheria.Shared.Tests/FlowFieldTests.cs +++ b/tests/Aetheria.Shared.Tests/FlowFieldTests.cs @@ -45,12 +45,12 @@ public sealed class FlowFieldTests : IDisposable SlopeAmplitude = slide, SwirlAmplitude = swirl }; - // A zone at `time` (the pack's clock, as a saved zone restores it), flat unless `depth` digs the zone's own well. - private Zone ZoneWith(FlowSettings flow, double time = 0, float depth = 0f) + // A zone at `time` (the pack's clock, as a saved zone restores it), flat unless `strength` digs the zone's own well. + private Zone ZoneWith(FlowSettings flow, double time = 0, float strength = 0f) { var planets = new PlanetSettings { Flow = flow }; var pack = new ZonePack { Time = time }; - if (depth > 0f) WellFixture.Dig(_items.ItemData, pack, planets, pack.Radius, depth, 2f); + if (strength > 0f) WellFixture.Dig(_items.ItemData, pack, planets, strength, 100f); return new Zone(_items, planets, pack, new GalaxyZone { Name = "Flow Zone", Owner = null }, null); } @@ -124,6 +124,28 @@ public sealed class FlowFieldTests : IDisposable } } + // Zone.Flow's slope term reads the owner's superposed force, not any one body's: two equal wells, probes off the + // axis between them where the nearest body's direction and the sum's differ. + [Fact] + public void TheSlopeTermFollowsTheSuperposedForce() + { + var planets = new PlanetSettings { Flow = Flow(amplitude: 0f, slide: 1.5f) }; + var pack = new ZonePack(); + WellFixture.Dig(_items.ItemData, pack, planets, 300f, 100f, new float2(-300f, 0f)); + WellFixture.Dig(_items.ItemData, pack, planets, 300f, 100f, new float2(300f, 0f)); + var zone = new Zone(_items, planets, pack, new GalaxyZone { Name = "Two Wells", Owner = null }, null); + var checkedPoints = 0; + foreach (var at in new[] { float2(100f, 400f), float2(-50f, -300f), float2(250f, 220f), float2(-420f, 90f) }) + { + var flow = zone.Flow(float3(at.x, 3f, at.y)); + var expected = 1.5f * normalize(zone.GetForce(at)); + Assert.Equal(expected.x, flow.x, 3); + Assert.Equal(expected.y, flow.z, 3); + checkedPoints++; + } + Assert.Equal(4, checkedPoints); + } + [Fact] public void SlopeTermSwirlsAndSlidesOnTheGradient() { @@ -131,13 +153,13 @@ public sealed class FlowFieldTests : IDisposable var at = new float3(500f, 3f, 300f); var downhill = normalize(float2(-at.x, -at.z)); - var slide = ZoneWith(Flow(amplitude: 0f, slide: 1.5f), depth: 64f).Flow(at); + var slide = ZoneWith(Flow(amplitude: 0f, slide: 1.5f), strength: 300f).Flow(at); Assert.Equal(0f, slide.y, 4); Assert.Equal(1.5f * downhill.x, slide.x, 2); Assert.Equal(1.5f * downhill.y, slide.z, 2); // Swirl is perpendicular to downhill, and has a handedness: (down.y, -down.x). - var swirl = ZoneWith(Flow(amplitude: 0f, swirl: 2f), depth: 64f).Flow(at); + var swirl = ZoneWith(Flow(amplitude: 0f, swirl: 2f), strength: 300f).Flow(at); Assert.Equal(0f, swirl.y, 4); Assert.Equal(2f * downhill.y, swirl.x, 2); Assert.Equal(-2f * downhill.x, swirl.z, 2); diff --git a/tests/Aetheria.Shared.Tests/GravitySubtractTests.cs b/tests/Aetheria.Shared.Tests/GravitySubtractTests.cs index 7f89cd0fd..696b491df 100644 --- a/tests/Aetheria.Shared.Tests/GravitySubtractTests.cs +++ b/tests/Aetheria.Shared.Tests/GravitySubtractTests.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Linq; using CultMath; using GameCult.Caching; using Xunit; @@ -41,7 +42,9 @@ public sealed class GravitySubtractTests : IDisposable // mass or multiplier than its twin would show it. private static PlanetSettings Planets() => new PlanetSettings { - GravityStrength = 1, + WellStrength = new ExponentialCurve { Exponent = .2f, Multiplier = 45.08f }, + CoreRadius = new ExponentialCurve { Exponent = .25f, Multiplier = 3f }, + RocheLimit = new ExponentialCurve { Exponent = .25f, Multiplier = 7.32f }, BodyRadius = new ExponentialCurve { Exponent = .25f, Multiplier = 3f }, GravityRadius = new ExponentialCurve { Exponent = .25f, Multiplier = 500f }, GravityDepth = new ExponentialCurve { Exponent = .175f, Multiplier = 30f }, @@ -72,26 +75,6 @@ public sealed class GravitySubtractTests : IDisposable } } - // The fixture the five bowl tests share reproduces the zone bowl it replaced (map B14): the bowl was - // -PowerPulse(r / (2 R), exponent) x depth, written out here from its definition, deepest at the centre and - // zero from r = R on, so a fixture whose radius or depth drifted from the bowl would change every pull it feeds. - [Fact] - public void TheWellFixtureReproducesTheFormerBowl() - { - foreach (var (radius, depth, exponent, at, expected) in new[] - { - (1000f, 1000f, 1f, 0f, -1000f), (1000f, 1000f, 1f, 400f, -840f), (1000f, 1000f, 1f, 1000f, 0f), - (2000f, 64f, 2f, 1000f, -36f), (2000f, 64f, 2f, 300f, -61.1524f) - }) - { - var planets = Planets(); - var pack = new ZonePack { Radius = radius }; - WellFixture.Dig(_cache, pack, planets, radius, depth, exponent); - var zone = new Zone(_items, planets, pack, new GalaxyZone { Name = "Bowl Zone", Owner = null }, null); - Assert.InRange(zone.GetHeight(new float2(at, 0)), expected - 1e-2f, expected + 1e-2f); - } - } - // One body of `data` at the origin of a zone whose only body it is. private Zone WithBody(BodyData data) { @@ -100,9 +83,8 @@ public sealed class GravitySubtractTests : IDisposable data.Mass = 100f; data.GravityRadiusMultiplier = 1.5f; data.GravityDepthMultiplier = .7f; - data.GravityDepthExponent = 2f; var body = _cache.Upsert(data).Key; - var pack = new ZonePack { Radius = 1000f }; + var pack = new ZonePack { Radius = PackRadius }; pack.Orbits.Add(new CultRecordRef(orbit)); pack.Planets.Add(new CultRecordRef(body)); return new Zone(_items, Planets(), pack, new GalaxyZone { Name = "Giant " + data.GetType().Name, Owner = null }, null); @@ -110,15 +92,18 @@ public sealed class GravitySubtractTests : IDisposable // The wells are the whole of a giant's height at every point, not just at a few radii: a ripple confined to // any annulus, or to a band derived from the body's radius, shows against the plain body somewhere in a sweep - // that runs from the centre to well past the well's support. + // that runs from a quarter of the core to twice the pack's radius, the core radius itself included. The sweep + // is derived from the body the zone built, not from constants. [Fact] public void AGiantsWellIsAPlainWellAtEveryTime() { var plain = WithBody(new PlanetData()); var giants = new[] { WithBody(new GasGiantData()), WithBody(new SunData()) }; - var radii = new System.Collections.Generic.List { 0.5f }; - for (var r = 1f; r <= 100f; r += 1f) radii.Add(r); - for (var r = 105f; r <= 2000f; r += 5f) radii.Add(r); + var core = plain.PlanetInstances.Values.Single().CoreRadius; + Assert.True(core > 1f, "the fixture body has a core to sweep around"); + var radii = new System.Collections.Generic.List { 0.5f, core }; + for (var r = core / 4f; r <= 4f * core; r += core / 16f) radii.Add(r); + for (var r = 4f * core; r <= 2f * PackRadius; r += PackRadius / 200f) radii.Add(r); var angles = new[] { 0f, 0.7f, 2.1f, 4.0f }; foreach (var time in new[] { 0f, 37.5f, 91.25f }) { @@ -146,19 +131,35 @@ public sealed class GravitySubtractTests : IDisposable } private float _clock; + private const float PackRadius = 1000f; - // CultCache has no primitive for reserving a removed MessagePack key; the wave keys of the gas giant (14-17) - // must not come back with a different meaning, because stored records may still carry them. + // CultCache has no primitive for reserving a removed MessagePack key. Key 8 of a body record (its former well + // exponent) and the wave keys of the gas giants (14-17) must not come back with a different meaning, because + // stored records may still carry them. Every record type that is a BodyData is checked, bases walked, so a giant + // kind added later (the sun is one) cannot take them. [Fact] - public void AGasGiantRecordNeverReusesTheRetiredWaveKeys() + public void ABodyRecordNeverReusesRetiredKeys() { - var keys = new System.Collections.Generic.List(); - for (var t = typeof(GasGiantData); t != null; t = t.BaseType) - foreach (var m in t.GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | - System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.DeclaredOnly)) - if (m.GetCustomAttributes(typeof(MessagePack.KeyAttribute), false) is MessagePack.KeyAttribute[] ks) - foreach (var k in ks) if (k.IntKey.HasValue) keys.Add(k.IntKey.Value); - Assert.NotEmpty(keys); - foreach (var retired in new[] { 14, 15, 16, 17 }) Assert.DoesNotContain(retired, keys); + static System.Collections.Generic.List KeysOf(System.Type type) + { + var keys = new System.Collections.Generic.List(); + for (var t = type; t != null; t = t.BaseType) + foreach (var m in t.GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | + System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.DeclaredOnly)) + if (m.GetCustomAttributes(typeof(MessagePack.KeyAttribute), false) is MessagePack.KeyAttribute[] ks) + foreach (var k in ks) if (k.IntKey.HasValue) keys.Add(k.IntKey.Value); + return keys; + } + + var bodies = typeof(BodyData).Assembly.GetTypes().Where(x => typeof(BodyData).IsAssignableFrom(x)).ToArray(); + Assert.Contains(typeof(SunData), bodies); + foreach (var type in bodies) + { + var keys = KeysOf(type); + Assert.NotEmpty(keys); + Assert.DoesNotContain(8, keys); + if (typeof(GasGiantData).IsAssignableFrom(type)) + foreach (var retired in new[] { 14, 15, 16, 17 }) Assert.DoesNotContain(retired, keys); + } } } diff --git a/tests/Aetheria.Shared.Tests/LootTests.cs b/tests/Aetheria.Shared.Tests/LootTests.cs index 2cac1ae2f..4aef9ff25 100644 --- a/tests/Aetheria.Shared.Tests/LootTests.cs +++ b/tests/Aetheria.Shared.Tests/LootTests.cs @@ -110,11 +110,7 @@ public sealed class LootTests : IDisposable var items = new ItemManager(cache, ledger, settings, _ => { }); var planets = new PlanetSettings(); var pack = new ZonePack { Radius = well ? 1000 : 0 }; - if (well) - { - planets.GravityStrength = 1; - WellFixture.Dig(cache, pack, planets, 1000, 1000, 1); - } + if (well) WellFixture.Dig(cache, pack, planets, 300, 100); var zone = new Zone(items, planets, pack, new GalaxyZone { Name = zoneName, Owner = null }, null); return new Lab { Items = items, Zone = zone }; } diff --git a/tests/Aetheria.Shared.Tests/MineTests.cs b/tests/Aetheria.Shared.Tests/MineTests.cs index f5274896b..e0685f3bf 100644 --- a/tests/Aetheria.Shared.Tests/MineTests.cs +++ b/tests/Aetheria.Shared.Tests/MineTests.cs @@ -118,9 +118,9 @@ public sealed class MineTests : IDisposable var ledger = new ProvenanceLedger(); for (var i = 1; i <= 500; i++) ledger.Lots[i] = new Lot { Origin = new Attributed(), Quality = 1 }; var items = new ItemManager(cache, ledger, settings, _ => { }); - var planets = well ? new PlanetSettings { GravityStrength = 1 } : new PlanetSettings(); + var planets = new PlanetSettings(); var pack = new ZonePack { Radius = well ? 1000 : 0 }; - if (well) WellFixture.Dig(cache, pack, planets, 1000, 1000, 1); + if (well) WellFixture.Dig(cache, pack, planets, 300, 100); var zone = new Zone(items, planets, pack, new GalaxyZone { Name = "Mines", Owner = null }, null); var lab = new Lab { Items = items, Zone = zone, Data = data, ItemData = cache.GetByName("Mine Layer") }; diff --git a/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs b/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs new file mode 100644 index 000000000..e1d6e8606 --- /dev/null +++ b/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs @@ -0,0 +1,216 @@ +using System; +using System.IO; +using System.Linq; +using CultMath; +using GameCult.Caching; +using Xunit; +using static CultMath.math; +using float2 = CultMath.float2; +using float3 = CultMath.float3; + +// aetheria-gravity target r4: one potential per zone owns gravity (potential-owns-gravity), built from the authored +// curves of mass (well strength, core radius, Roche limit) and one global exaggeration. Each test builds the zone +// through the production constructor from PlanetSettings and body records and reads the owner's GetForce and +// GetHeight; the closed forms written here state the law, they are not Zone's code. +public sealed class PotentialOwnerTests : IDisposable +{ + private const float PackRadius = 1000f; + private readonly string _root = Path.Combine(Path.GetTempPath(), "aetheria-potential-" + Guid.NewGuid().ToString("N")); + private readonly CultCache _cache; + private readonly ItemManager _items; + + public PotentialOwnerTests() + { + Directory.CreateDirectory(_root); + _cache = AetheriaStores.Open(Path.Combine(_root, "pot.cc"), Path.Combine(_root, "pot-run.cc"), catalogWritable: true); + _cache.Upsert(new VerseGrammar { Revision = 1 }); + _cache.FlushAsync().Wait(); + var settings = new GameplaySettings + { + DefaultEntitySettings = new EntitySettings(), + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + QualityPriceModifier = new ExponentialLerp() + }; + _items = new ItemManager(_cache, new ProvenanceLedger(), settings, _ => { }); + } + + public void Dispose() + { + _cache.Dispose(); + Directory.Delete(_root, true); + } + + // The authored curves of the shipped Settings.asset: strength c = 45.08 m^.2, core R = 3 m^.25, Roche 7.32 m^.25. + private static PlanetSettings Curves(float exaggeration = 1f) => new PlanetSettings + { + WellStrength = new ExponentialCurve { Exponent = .2f, Multiplier = 45.08f }, + CoreRadius = new ExponentialCurve { Exponent = .25f, Multiplier = 3f }, + RocheLimit = new ExponentialCurve { Exponent = .25f, Multiplier = 7.32f }, + BodyRadius = new ExponentialCurve { Exponent = .25f, Multiplier = 2f }, + GravityRadius = new ExponentialCurve(), GravityDepth = new ExponentialCurve(), + LightRadius = new ExponentialCurve(), OrbitPeriod = new ExponentialCurve(), + HeightExaggeration = exaggeration + }; + + private int _bodies; + + private Zone ZoneOf(PlanetSettings planets, params (float mass, float2 at)[] bodies) + { + var pack = new ZonePack { Radius = PackRadius }; + foreach (var (mass, at) in bodies) + { + var orbit = _cache.Upsert(new OrbitData { FixedPosition = at }).Key; + var body = _cache.Upsert(new PlanetData { Name = "Body " + ++_bodies, Orbit = new CultRecordRef(orbit), Mass = mass }).Key; + pack.Orbits.Add(new CultRecordRef(orbit)); + pack.Planets.Add(new CultRecordRef(body)); + } + return new Zone(_items, planets, pack, new GalaxyZone { Name = "Potential " + _bodies, Owner = null }, null); + } + + private static void Near(float expected, float actual, float relative) => + Assert.InRange(actual, expected - Math.Abs(expected) * relative - 1e-5f, expected + Math.Abs(expected) * relative + 1e-5f); + + // The law written out: potential c r^2 / 2R^2 inside the core, c (ln(r / R) + 1/2) beyond. + private static float Phi(float c, float core, float r) => r < core ? c * r * r / (2 * core * core) : c * (log(r / core) + .5f); + + [Fact] + public void StrengthFollowsTheAuthoredMassCurve() + { + var planets = Curves(); + foreach (var mass in new[] { 29.2f, 273.9f, 14152.4f }) + { + var zone = ZoneOf(planets, (mass, float2.zero)); + var core = planets.CoreRadius.Evaluate(mass); + foreach (var r in new[] { 3f * core, 10f * core, PackRadius / 2f }) + Near(planets.WellStrength.Evaluate(mass), length(zone.GetForce(new float2(r, 0))) * r, 1e-3f); + } + } + + [Fact] + public void TheCoreRadiusFollowsItsOwnCurve() + { + var planets = Curves(); + foreach (var mass in new[] { 29.2f, 14152.4f }) + { + var zone = ZoneOf(planets, (mass, float2.zero)); + var core = planets.CoreRadius.Evaluate(mass); + float Pull(float r) => length(zone.GetForce(new float2(0, r))); + var slope = Pull(.25f * core) / (.25f * core); + Near(slope, Pull(.5f * core) / (.5f * core), 1e-3f); + Near(slope, Pull(.9f * core) / (.9f * core), 1e-3f); + Assert.True(Pull(core) > Pull(.98f * core), "the pull still rises up to the core radius"); + Assert.True(Pull(core) > Pull(1.02f * core), "and falls beyond it"); + } + } + + [Fact] + public void TheCoreSitsInsideTheRocheLimit() + { + var planets = Curves(); + foreach (var mass in new[] { 29.2f, 14152.4f }) + Near(planets.RocheLimit.Evaluate(mass), ZoneOf(planets, (mass, float2.zero)).PlanetInstances.Values.Single().RocheLimit, 1e-6f); + + PlanetSettings Constants(float core, float roche) => new PlanetSettings + { + WellStrength = new ExponentialCurve { Constant = 100f }, + CoreRadius = new ExponentialCurve { Constant = core }, + RocheLimit = new ExponentialCurve { Constant = roche }, + BodyRadius = new ExponentialCurve { Constant = 10f }, + GravityRadius = new ExponentialCurve(), GravityDepth = new ExponentialCurve(), + LightRadius = new ExponentialCurve(), OrbitPeriod = new ExponentialCurve() + }; + Assert.Throws(() => ZoneOf(Constants(60f, 50f), (100f, float2.zero))); + Assert.Throws(() => ZoneOf(Constants(50f, 50f), (100f, float2.zero))); + Assert.Throws(() => ZoneOf(Constants(0f, 50f), (100f, float2.zero))); + ZoneOf(Constants(20f, 50f), (100f, float2.zero)); // inside the limit, and past the body's radius + } + + [Fact] + public void TheTailIsAPointMassWithNoRimAndNoGate() + { + var planets = Curves(); + var zone = ZoneOf(planets, (273.9f, float2.zero)); + var c = planets.WellStrength.Evaluate(273.9f); + var core = planets.CoreRadius.Evaluate(273.9f); + foreach (var r in new[] { core, 2f * core, PackRadius, 10f * PackRadius, 100f * PackRadius, 1000f * PackRadius }) + foreach (var angle in new[] { 0f, 1.1f, 3.5f }) + { + var at = new float2(r * cos(angle), r * sin(angle)); + var force = zone.GetForce(at); + Near(c, length(force) * r, 1e-3f); + Assert.True(dot(normalize(force), normalize(-at)) > .9999f, "the pull points at the body"); + } + } + + [Fact] + public void WellsSuperpose() + { + var planets = Curves(); + var a = (mass: 29.2f, at: new float2(-300f, 0f)); + var b = (mass: 14152.4f, at: new float2(300f, 0f)); + var both = ZoneOf(planets, a, b); + var onlyA = ZoneOf(planets, a); + var onlyB = ZoneOf(planets, b); + var probes = new[] + { + float2(-300f, 0f), float2(300f, 0f), float2(-310f, 4f), float2(305f, -9f), float2(0f, 0f), float2(0f, 250f), + float2(-150f, 100f), float2(150f, -100f), float2(900f, 700f), float2(-1200f, -300f), float2(40f, 3000f), float2(-300f, -40f) + }; + foreach (var p in probes) + { + var sum = onlyA.GetForce(p) + onlyB.GetForce(p); + Near(sum.x, both.GetForce(p).x, 1e-4f); + Near(sum.y, both.GetForce(p).y, 1e-4f); + Near(onlyA.GetHeight(p) + onlyB.GetHeight(p), both.GetHeight(p), 1e-4f); + } + } + + [Fact] + public void HeightIsThePotentialOverOneK() + { + foreach (var k in new[] { 1f, 10f }) + { + var planets = Curves(k); + var lone = ZoneOf(planets, (273.9f, float2.zero)); + var c = planets.WellStrength.Evaluate(273.9f); + var core = planets.CoreRadius.Evaluate(273.9f); + Assert.Equal(0f, lone.GetHeight(new float2(PackRadius, 0)), 4); + Near(-c * (log(PackRadius / core) + .5f) / k, lone.GetHeight(float2.zero), 1e-4f); + + var two = ZoneOf(planets, (29.2f, new float2(-300f, 0f)), (14152.4f, new float2(300f, 0f))); + var c0 = planets.WellStrength.Evaluate(29.2f); + var core0 = planets.CoreRadius.Evaluate(29.2f); + var c1 = planets.WellStrength.Evaluate(14152.4f); + var core1 = planets.CoreRadius.Evaluate(14152.4f); + const float step = .5f; + foreach (var p in new[] { float2(-200f, 120f), float2(0f, 0f), float2(100f, -300f), float2(500f, 40f), float2(-290f, 12f), float2(310f, 20f), float2(700f, 700f), float2(-80f, -500f) }) + { + var expected = Phi(c0, core0, length(p - float2(-300f, 0f))) - Phi(c0, core0, PackRadius) + + Phi(c1, core1, length(p - float2(300f, 0f))) - Phi(c1, core1, PackRadius); + Near(expected, two.GetHeight(p) * k, 1e-3f); + + // The downhill slope of the potential is the force: the central difference of height * K is -GetForce. + var gradient = float2( + (two.GetHeight(p + float2(step, 0)) - two.GetHeight(p - float2(step, 0))) * k / (2 * step), + (two.GetHeight(p + float2(0, step)) - two.GetHeight(p - float2(0, step))) * k / (2 * step)); + var force = two.GetForce(p); + Assert.InRange(length(gradient + force), 0f, length(force) * 1e-2f + 1e-4f); + } + } + } + + [Fact] + public void TheCoreMeetsTheTailAtItsRadius() + { + var planets = Curves(); + foreach (var mass in new[] { 29.2f, 14152.4f }) + { + var zone = ZoneOf(planets, (mass, float2.zero)); + var core = planets.CoreRadius.Evaluate(mass); + var inside = new float2(core * (1f - 1e-3f), 0); + var outside = new float2(core * (1f + 1e-3f), 0); + Assert.InRange(abs(zone.GetHeight(inside) - zone.GetHeight(outside)), 0f, abs(zone.GetHeight(outside)) * 1e-3f); + Assert.InRange(abs(length(zone.GetForce(inside)) - length(zone.GetForce(outside))), 0f, length(zone.GetForce(outside)) * 1e-3f); + } + } +} diff --git a/tests/Aetheria.Shared.Tests/WellFixture.cs b/tests/Aetheria.Shared.Tests/WellFixture.cs index ab6922cd7..0b895e4c0 100644 --- a/tests/Aetheria.Shared.Tests/WellFixture.cs +++ b/tests/Aetheria.Shared.Tests/WellFixture.cs @@ -1,20 +1,21 @@ using CultMath; using GameCult.Caching; -// The one fixture that gives a test zone a slope: a single body on a parentless orbit at the origin, with -// the curves a body needs. Gravity height is the sum of body wells, so a test that wants ground to slide on -// digs it here and nowhere else. `radius` is the zone radius the well is sized to (its well reaches 2 x radius, -// as the former bowl did); the well is deepest at the centre and zero at and beyond half its radius. +// The one fixture that gives a test zone a slope: a body on a parentless orbit (the origin unless `at` says otherwise; call again for more bodies), with the +// curves a body needs. Gravity is the sum of body wells (GravityField), so a test that wants ground to slide on +// digs it here and nowhere else. `strength` is the well's c (u^2/s^2) and `coreRadius` its softened core in u; the +// Roche limit curve sits at 2.5 cores so the body is a valid well. internal static class WellFixture { - public static void Dig(CultCache cache, ZonePack pack, PlanetSettings settings, float radius, float depth, float exponent) + public static void Dig(CultCache cache, ZonePack pack, PlanetSettings settings, float strength, float coreRadius, float2 at = default) { settings.BodyRadius = new ExponentialCurve(); settings.OrbitPeriod = new ExponentialCurve(); - settings.GravityRadius = new ExponentialCurve { Constant = 2f * radius }; - settings.GravityDepth = new ExponentialCurve { Constant = depth }; - var orbit = cache.Upsert(new OrbitData { FixedPosition = float2.zero }).Key; - var body = cache.Upsert(new PlanetData { Orbit = new CultRecordRef(orbit), GravityDepthExponent = exponent }).Key; + settings.WellStrength = new ExponentialCurve { Constant = strength }; + settings.CoreRadius = new ExponentialCurve { Constant = coreRadius }; + settings.RocheLimit = new ExponentialCurve { Constant = 2.5f * coreRadius }; + var orbit = cache.Upsert(new OrbitData { FixedPosition = at }).Key; + var body = cache.Upsert(new PlanetData { Name = $"Well {at.x},{at.y}", Orbit = new CultRecordRef(orbit) }).Key; pack.Orbits.Add(new CultRecordRef(orbit)); pack.Planets.Add(new CultRecordRef(body)); } diff --git a/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs b/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs index 002f0f2df..bdf8822d3 100644 --- a/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs +++ b/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs @@ -38,15 +38,15 @@ public sealed class ZonePlacedAtBuildTests : IDisposable private static ExponentialCurve Flat(float v) => new ExponentialCurve { Constant = v }; - // Flat space (no zone depth) with one planet whose well reaches 500 u, a fixed root orbit at RootAt and the + // One planet with a well (c 100, core 20 u, Roche limit 30 u), a fixed root orbit at RootAt and the // planet orbiting it at Distance from `phase`. Every orbit period is Period seconds. private static PlanetSettings Settings() => new PlanetSettings { OrbitPeriod = Flat(Period), BodyRadius = Flat(20f), - GravityRadius = Flat(500f), - GravityDepth = Flat(100f), - GravityStrength = 1f, + WellStrength = Flat(100f), + CoreRadius = Flat(20f), + RocheLimit = Flat(30f), LightRadius = Flat(0f) }; @@ -57,6 +57,8 @@ public sealed class ZonePlacedAtBuildTests : IDisposable public HullData Hull; public Zone Zone; public CultRecordKey PlanetOrbit; + public CultRecordKey MoonOrbit; + public CultRecordKey MoonsMoonOrbit; } private Scene Build(float phase, double time, bool moonFirst = false) @@ -81,6 +83,10 @@ public sealed class ZonePlacedAtBuildTests : IDisposable { Parent = new CultRecordRef(planetOrbit), Distance = 100f }).Key; + var moonsMoonOrbit = cache.Upsert(new OrbitData + { + Parent = new CultRecordRef(moonOrbit), Distance = 40f + }).Key; var planet = cache.Upsert(new PlanetData { Orbit = new CultRecordRef(planetOrbit), Mass = 1f }).Key; var pack = new ZonePack { @@ -90,10 +96,10 @@ public sealed class ZonePlacedAtBuildTests : IDisposable Time = time }; // The same three orbits either way; only the order the pack lists them in differs. - var listed = moonFirst ? new[] { moonOrbit, planetOrbit, rootOrbit } : new[] { rootOrbit, planetOrbit, moonOrbit }; + var listed = moonFirst ? new[] { moonsMoonOrbit, moonOrbit, planetOrbit, rootOrbit } : new[] { rootOrbit, planetOrbit, moonOrbit, moonsMoonOrbit }; foreach (var key in listed) pack.Orbits.Add(new CultRecordRef(key)); var zone = new Zone(items, Settings(), pack, new GalaxyZone { Name = "Placed", Owner = null }, null); - return new Scene { Cache = cache, Items = items, Hull = hull, Zone = zone, PlanetOrbit = planetOrbit }; + return new Scene { Cache = cache, Items = items, Hull = hull, Zone = zone, PlanetOrbit = planetOrbit, MoonOrbit = moonOrbit, MoonsMoonOrbit = moonsMoonOrbit }; } [Theory] @@ -116,6 +122,31 @@ public sealed class ZonePlacedAtBuildTests : IDisposable Assert.InRange(normalize(force).x, -1f, -.99f); } + // A moon's moon (the fourth orbit, a child of a child of the planet) is placed by the constructor too, whichever + // order the pack lists the chain in: each orbit sits its distance from its parent at its own phase of its own period. + [Theory] + [InlineData(false, 0.0)] + [InlineData(true, 0.0)] + [InlineData(false, 123.0)] + [InlineData(true, 123.0)] + public void AMoonsMoonSitsOnItsOrbitBeforeTheFirstTick(bool moonFirst, double time) + { + var s = Build(.1f, time, moonFirst); + var planet = s.Zone.Orbits[s.PlanetOrbit]; + var moon = s.Zone.Orbits[s.MoonOrbit]; + var moonsMoon = s.Zone.Orbits[s.MoonsMoonOrbit]; + float2 Offset(Orbit orbit) => OrbitData.Evaluate(frac((float) frac(time / orbit.Period) + orbit.Data.Phase)) * orbit.Data.Distance; + + var planetAt = RootAt + Offset(planet); + var moonAt = planetAt + Offset(moon); + var moonsMoonAt = moonAt + Offset(moonsMoon); + + Assert.True(moon.Period > .01f && moonsMoon.Period > .01f, "the chain's orbits move"); + Assert.InRange(length(moon.Position - moonAt), 0f, .01f); + Assert.InRange(length(moonsMoon.Position - moonsMoonAt), 0f, .01f); + Assert.True(length(moonsMoonAt - moonAt) > 1f, "the moon's moon is not on its parent"); + } + // A parent's velocity is its own orbital velocity on the first tick and every tick after, whichever order // the pack lists a moon and its planet in. dt differs per tick so a velocity taken from a fixed step fails. [Theory] From fde806293127c3f73448b5cad99bd952699f0621 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 04:51:20 +0200 Subject: [PATCH 02/20] Gravity potential-owner tests: fixtures keep the brush-input curves Planet still reads Co-Authored-By: Claude Opus 5.5 --- tests/Aetheria.Shared.Tests/WellFixture.cs | 2 ++ tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/Aetheria.Shared.Tests/WellFixture.cs b/tests/Aetheria.Shared.Tests/WellFixture.cs index 0b895e4c0..e732172d9 100644 --- a/tests/Aetheria.Shared.Tests/WellFixture.cs +++ b/tests/Aetheria.Shared.Tests/WellFixture.cs @@ -10,6 +10,8 @@ internal static class WellFixture public static void Dig(CultCache cache, ZonePack pack, PlanetSettings settings, float strength, float coreRadius, float2 at = default) { settings.BodyRadius = new ExponentialCurve(); + settings.GravityRadius = new ExponentialCurve(); // brush inputs, read by Planet until grid-lowering deletes them + settings.GravityDepth = new ExponentialCurve(); settings.OrbitPeriod = new ExponentialCurve(); settings.WellStrength = new ExponentialCurve { Constant = strength }; settings.CoreRadius = new ExponentialCurve { Constant = coreRadius }; diff --git a/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs b/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs index bdf8822d3..11d514de6 100644 --- a/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs +++ b/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs @@ -44,6 +44,8 @@ public sealed class ZonePlacedAtBuildTests : IDisposable { OrbitPeriod = Flat(Period), BodyRadius = Flat(20f), + GravityRadius = Flat(0f), // brush inputs, read by Planet until grid-lowering deletes them + GravityDepth = Flat(0f), WellStrength = Flat(100f), CoreRadius = Flat(20f), RocheLimit = Flat(30f), From 41e90d0e4084cd77b9c72d8fcf5e1dc265d73448 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 05:02:48 +0200 Subject: [PATCH 03/20] GravityField: a well of no strength digs nothing (c = 0, R = 0 gave NaN height) Co-Authored-By: Claude Opus 5.5 --- Assets/Scripts/ServerShared/GravityField.cs | 2 ++ .../Aetheria.Shared.Tests/FloatingBodyTests.cs | 2 +- .../PotentialOwnerTests.cs | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/ServerShared/GravityField.cs b/Assets/Scripts/ServerShared/GravityField.cs index 53c2755a0..71e1f0c2a 100644 --- a/Assets/Scripts/ServerShared/GravityField.cs +++ b/Assets/Scripts/ServerShared/GravityField.cs @@ -11,7 +11,9 @@ using float2 = CultMath.float2; public static class GravityField { // The potential at distance r from the body, defined up to a constant (callers subtract their reference). + // A well of no strength (a body whose curves are unauthored, so c = 0 and R = 0) digs nothing. public static float Potential(float c, float coreRadius, float r) => + c == 0f ? 0f : r < coreRadius ? c * r * r / (2 * coreRadius * coreRadius) : c * (log(r / coreRadius) + .5f); diff --git a/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs b/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs index fbf68bf79..b86ef459f 100644 --- a/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs +++ b/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs @@ -184,7 +184,7 @@ public sealed class FloatingBodyTests : IDisposable QualityPriceModifier = new ExponentialLerp() }; var items = new ItemManager(cache, new ProvenanceLedger(), settings, _ => { }); - var planets = new PlanetSettings(); + var planets = new PlanetSettings { HeightExaggeration = 10f }; // the tilt reads force / K, which K = 1 would hide var pack = new ZonePack { Radius = 1000 }; WellFixture.Dig(cache, pack, planets, 300, 100); zone = new Zone(items, planets, pack, new GalaxyZone { Name = "Test Zone", Owner = null }, null); diff --git a/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs b/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs index e1d6e8606..7111bccb4 100644 --- a/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs +++ b/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs @@ -73,6 +73,24 @@ public sealed class PotentialOwnerTests : IDisposable // The law written out: potential c r^2 / 2R^2 inside the core, c (ln(r / R) + 1/2) beyond. private static float Phi(float c, float core, float r) => r < core ? c * r * r / (2 * core * core) : c * (log(r / core) + .5f); + // A zone whose bodies have no authored gravity curves (most test zones) has no pull and no dip, and no NaN either. + [Fact] + public void BodiesWithNoAuthoredWellPullAndDigNothing() + { + var planets = new PlanetSettings + { + BodyRadius = new ExponentialCurve(), GravityRadius = new ExponentialCurve(), GravityDepth = new ExponentialCurve(), + LightRadius = new ExponentialCurve(), OrbitPeriod = new ExponentialCurve() + }; + var zone = ZoneOf(planets, (100f, float2.zero), (5000f, new float2(200f, 0f))); + foreach (var p in new[] { float2.zero, float2(200f, 0f), float2(37f, -911f), float2(5000f, 5000f) }) + { + Assert.Equal(0f, zone.GetHeight(p)); + Assert.Equal(0f, zone.GetForce(p).x); + Assert.Equal(0f, zone.GetForce(p).y); + } + } + [Fact] public void StrengthFollowsTheAuthoredMassCurve() { From dd06f39dbcfe181843f775f1cf241936697439b4 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 05:40:10 +0200 Subject: [PATCH 04/20] FloatingBodyTests: the tilt expectation is spelled from force and K, not read back from GetNormal Two hand mutants of GetNormal's K (ignored; times 3) survived because the test compared the ship's tilt with the same GetNormal it was testing. Co-Authored-By: Claude Opus 5.5 --- tests/Aetheria.Shared.Tests/FloatingBodyTests.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs b/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs index b86ef459f..16e66c1b0 100644 --- a/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs +++ b/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs @@ -217,7 +217,9 @@ public sealed class FloatingBodyTests : IDisposable Assert.InRange(ship.Velocity.x, expected.x - tolerance, expected.x + tolerance); Assert.InRange(ship.Velocity.y, expected.y - tolerance, expected.y + tolerance); - var normal = zone.GetNormal(at); + // The tilt is the surface of the drawn height (potential / K): its slope is the force over K. + var slope = zone.GetForce(at) / zone.Settings.HeightExaggeration; + var normal = normalize(float3(slope.x, 1f, slope.y)); var q = ship.Rotation; var u = float3(q.x, q.y, q.z); var v = float3(0, 1, 0); From 8013c2deecc025935f150b1000d1ddf8ff87343f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 06:36:01 +0200 Subject: [PATCH 05/20] Crossing and Lock On: restaged for the ruled field Under the potential-owner field the zone pulls everywhere (about 1.4 u/s^2 even in its weakest places), so the staged runs bend. Crossing's player sat on the star at the arena's origin and fell in; its crosser, braked by its pilot, never reached the bow line from 150 m to port. The crosser now starts 96.5 m to port and 70 m ahead of a player staged 250 m or more from every body, which keeps the pass at 3.2 s and 40 m (the test's 3.0-4.2 s and 30-60 m unchanged). Lock On's hostile started on the side where the zone bends its run by 7 degrees; the lock warning must point within 5 degrees of where the hostile was staged. It now starts ahead and to port, where the bend is under one degree and the lock comes at about 14 s. No assertion, limit or gravity is changed. Not built or run locally; verified in the Yggdrasil job. Co-Authored-By: Claude Opus 5.5 --- .../ServerShared/Scenarios/Crossing.cs | 19 +++++++++++-------- .../Scripts/ServerShared/Scenarios/LockOn.cs | 12 +++++++----- .../CrossingScenarioTests.cs | 2 +- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Assets/Scripts/ServerShared/Scenarios/Crossing.cs b/Assets/Scripts/ServerShared/Scenarios/Crossing.cs index b0d593704..880f492df 100644 --- a/Assets/Scripts/ServerShared/Scenarios/Crossing.cs +++ b/Assets/Scripts/ServerShared/Scenarios/Crossing.cs @@ -5,19 +5,22 @@ public sealed class Crossing : Scenario { public override string Name => "Crossing"; public override string Brief => "A Lightning Projector at the starboard gun and a Cell Blaster at the port gun, a fast Djinni crossing close ahead and an " + - "unpiloted one waiting at range. The Djinni starts to port moving across the bow; the arena's gravity bends its run. Make the pass coasting: give no throttle until the Djinni has crossed the bow, then fly freely (thrusting from the start carries you past it). Verify: as the Djinni crosses close, FastBlast lands some and projector " + + "unpiloted one waiting at range. The Djinni starts to port moving across the bow, and its pilot brakes it as it closes. Make the pass coasting: give no throttle until the Djinni has crossed the bow, then fly freely (thrusting from the start carries you past it). Verify: as the Djinni crosses close, FastBlast lands some and projector " + "almost none; against the Djinni at range both land. Fly it again without the Fire Control Array: " + "with it the small gun lands more."; public override uint Seed => 112; public override bool Ambient => false; - // Where the Djinni sit: the player is at the origin facing +z. The crosser starts ahead and to port, facing across - // the bow and already moving at the Djinni's 50 m/s cap, so its run sweeps across the bow within seconds (the arena - // pulls the player to port, which brings the two together). The waiting Djinni sits inside the Lightning Projector's arc at 80% of - // its Range. - public static readonly CultMath.float2 CrosserAt = float2(-150, 200), CrosserFacing = float2(1, 0), CrosserVelocity = float2(50, 0); + // Where the Djinni sit: the player is at Origin facing +z. Origin is 250 m or more from every body, where the zone's + // pull is weakest (about 1.4 u/s^2; the sum of the wells never drops to nothing, and at the old origin the player sat on the star). + // The crosser starts ahead and to port, facing across the bow and already moving at the Djinni's 50 m/s cap; its pilot + // brakes it as it closes, so it only just reaches the bow line, which fixes how far to port it starts (sweeping the starting + // x from -95 to -97.5 moves the pass from 3.0 s to 3.5 s; at -98 it never crosses). The waiting Djinni sits inside the Lightning + // Projector's arc at 80% of its Range. + public static readonly CultMath.float2 Origin = float2(724, 124); + public static readonly CultMath.float2 CrosserAt = Origin + float2(-96.5f, 70), CrosserFacing = float2(1, 0), CrosserVelocity = float2(50, 0); public const float ProjectorRange = 1216f; // the Lightning Projector's Range in metres, 1216.4 as the fit stands settled at rest - public static readonly CultMath.float2 Waiting = float2(0, ProjectorRange * .8f); + public static readonly CultMath.float2 Waiting = Origin + float2(0, ProjectorRange * .8f); public override Galaxy Generate(GalaxyStage stage) => stage.Prelude(DemoTerminus.Cast); @@ -39,7 +42,7 @@ public sealed class Crossing : Scenario ("Compact Sensor", int2(3, 10), None), ("Fire Control Array", int2(1, 6), Clockwise)); - stage.Player(fighter, float2(0, 0), facing: float2(0, 1)); + stage.Player(fighter, Origin, facing: float2(0, 1)); stage.Place(stage.Generated("Djinni"), CrosserAt, facing: CrosserFacing, stance: ScenarioStance.Hostile, piloted: true, velocity: CrosserVelocity); stage.Place(stage.Bare("Djinni"), Waiting); } diff --git a/Assets/Scripts/ServerShared/Scenarios/LockOn.cs b/Assets/Scripts/ServerShared/Scenarios/LockOn.cs index fa669e253..87e5de829 100644 --- a/Assets/Scripts/ServerShared/Scenarios/LockOn.cs +++ b/Assets/Scripts/ServerShared/Scenarios/LockOn.cs @@ -10,11 +10,13 @@ public sealed class LockOn : Scenario public override uint Seed => 113; public override bool Ambient => false; - // The hostile starts about 4000 m off, to the side of the player's axis, facing the player. At that range its passive - // sensors hold no track of the player (the test asks the sim's own PassiveInfo against the detection threshold); the - // player sees the hostile a little sooner, at about tick 20. The hostile closes, sees the player some eight seconds in, - // and locks two ticks later. At Duel's 900 m (and at 600 m) it sees and locks within a second. - public static readonly CultMath.float2 HostileAt = float2(1500, 3700); + // The hostile starts about 4000 m off, ahead and to port of the player, facing the player. At that range its passive + // sensors hold no track of the player (the test asks the sim's own PassiveInfo against the detection threshold). The + // hostile closes, sees the player some fourteen seconds in and locks. The zone's pull bends the hostile's run and moves the + // player, and the warning must still point at where the hostile was staged to within 5 degrees at the lock: this side keeps + // the bend under one degree (on the far side it is more than seven). At Duel's 900 m (and at 600 m) it sees and locks + // within a second. + public static readonly CultMath.float2 HostileAt = float2(-2000, 3450); public override Galaxy Generate(GalaxyStage stage) => stage.Prelude(DemoTerminus.Cast); diff --git a/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs b/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs index 8b5dfe019..955c331bd 100644 --- a/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs +++ b/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs @@ -84,7 +84,7 @@ public sealed partial class RunStartTests } } Assert.True(swept, $"the crosser's bearing never swept across the bow within {CrossingSeconds} s"); - // At seed 112 with no input the pass is at 3.6 s and 45 m; a seed or staging change that loses it moves these. + // At seed 112 with no input the pass is at 3.2 s and 40 m (the pilot brakes the crosser as it closes, so the pass is sensitive to where it starts: Crossing.CrosserAt); a seed, field or staging change that loses it moves these. Assert.InRange(crossedAt, 3.0f, 4.2f); Assert.InRange(crossedMetres, 30f, 60f); } From c4dfd905ff67b71ba66a0fb95f852313fcc23ff3 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 06:36:02 +0200 Subject: [PATCH 06/20] Gravity: the Planet guard refuses an unphysical well; tests pin the Roche rule, per-body multipliers, the core band and Ship's order A WellStrength that evaluates negative, NaN or infinite now throws at construction (it built an antimass well with NaN height). New tests: the core-inside-Roche guard judged at every mass on curves that cross in the generated range; per-body multipliers move neither strength, core nor Roche limit; potential and force consistency inside the cores' outer bands (0.5 R to R); a moving Ship feels the field where it has moved to. Not built or run locally; verified in the Yggdrasil job. Co-Authored-By: Claude Opus 5.5 --- Assets/Scripts/ServerShared/Zone.cs | 2 + .../FloatingBodyTests.cs | 21 ++++ .../PotentialOwnerTests.cs | 111 +++++++++++++++++- 3 files changed, 131 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/ServerShared/Zone.cs b/Assets/Scripts/ServerShared/Zone.cs index 423f48ed2..cd0449545 100644 --- a/Assets/Scripts/ServerShared/Zone.cs +++ b/Assets/Scripts/ServerShared/Zone.cs @@ -712,6 +712,8 @@ public class Planet WellStrength = Settings.WellStrength.Evaluate(BodyData.Mass); CoreRadius = Settings.CoreRadius.Evaluate(BodyData.Mass); RocheLimit = Settings.RocheLimit.Evaluate(BodyData.Mass); + if (!(WellStrength >= 0f) || float.IsInfinity(WellStrength)) + throw new InvalidOperationException("A body's well strength must be finite and not negative (PlanetSettings.WellStrength)."); if (WellStrength > 0 && !(0 < CoreRadius && CoreRadius < RocheLimit)) throw new InvalidOperationException("A body's core radius must be positive and inside its Roche limit (PlanetSettings.CoreRadius, RocheLimit)."); } diff --git a/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs b/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs index 16e66c1b0..3ca18c4aa 100644 --- a/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs +++ b/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs @@ -227,4 +227,25 @@ public sealed class FloatingBodyTests : IDisposable Assert.True(length(up - normal) < 1e-4f, "the ship tilts to the zone's surface normal"); } } + + // Ship.Update's order: position first, then gravity sampled where the ship now is (leapfrog's kick after the drift). A + // ship already moving falls toward the centre through the field at its new place, not the one it left. + [Fact] + public void AMovingShipFeelsTheFieldWhereItHasMoved() + { + var ship = ShipAt(400f, out var zone); + ship.Velocity = float2(-200f, 0f); + const float delta = .25f; + + ship.Update(delta); + + var moved = float2(400f, 0f) + float2(-200f, 0f) * delta; + Assert.Equal(moved.x, ship.Position.x, 1e-3f); + var pulled = (ship.Velocity - float2(-200f, 0f)) / delta; + var expected = zone.GetForce(moved); + Assert.True(expected.x < 0f, "the well pulls inward at the ship's new place"); + Assert.InRange(pulled.x, expected.x * (1f + 1e-3f), expected.x * (1f - 1e-3f)); + Assert.InRange(pulled.y, -1e-3f, 1e-3f); + Assert.NotEqual(zone.GetForce(float2(400f, 0f)).x, expected.x); // the premise: the field differs between the two places + } } diff --git a/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs b/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs index 7111bccb4..aa6aa626a 100644 --- a/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs +++ b/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs @@ -54,13 +54,18 @@ public sealed class PotentialOwnerTests : IDisposable private int _bodies; - private Zone ZoneOf(PlanetSettings planets, params (float mass, float2 at)[] bodies) + private Zone ZoneOf(PlanetSettings planets, params (float mass, float2 at)[] bodies) => ZoneOf(planets, null, bodies); + + // `author` edits each body's record before it is stored: the per-body knobs a body record carries. + private Zone ZoneOf(PlanetSettings planets, Action author, params (float mass, float2 at)[] bodies) { var pack = new ZonePack { Radius = PackRadius }; foreach (var (mass, at) in bodies) { var orbit = _cache.Upsert(new OrbitData { FixedPosition = at }).Key; - var body = _cache.Upsert(new PlanetData { Name = "Body " + ++_bodies, Orbit = new CultRecordRef(orbit), Mass = mass }).Key; + var data = new PlanetData { Name = "Body " + ++_bodies, Orbit = new CultRecordRef(orbit), Mass = mass }; + author?.Invoke(data); + var body = _cache.Upsert(data).Key; pack.Orbits.Add(new CultRecordRef(orbit)); pack.Planets.Add(new CultRecordRef(body)); } @@ -143,6 +148,100 @@ public sealed class PotentialOwnerTests : IDisposable ZoneOf(Constants(20f, 50f), (100f, float2.zero)); // inside the limit, and past the body's radius } + // core-inside-roche-curve at every mass: the guard compares the two authored curves for each body, light or heavy. + // Each pair of curves crosses somewhere in the generated mass range (1e-3 to 1e8), so the sweep holds both outcomes. + [Theory] + [InlineData(30f, .25f, 7.32f, .5f)] // the core curve starts above the Roche curve and is overtaken: light bodies throw + [InlineData(3f, .5f, 7.32f, .25f)] // the core curve overtakes the Roche curve: heavy bodies throw + public void TheGuardJudgesEveryMassByItsOwnCurves(float coreMultiplier, float coreExponent, float rocheMultiplier, float rocheExponent) + { + var planets = new PlanetSettings + { + WellStrength = new ExponentialCurve { Constant = 100f }, + CoreRadius = new ExponentialCurve { Multiplier = coreMultiplier, Exponent = coreExponent }, + RocheLimit = new ExponentialCurve { Multiplier = rocheMultiplier, Exponent = rocheExponent }, + BodyRadius = new ExponentialCurve { Constant = 1f }, + GravityRadius = new ExponentialCurve(), GravityDepth = new ExponentialCurve(), + LightRadius = new ExponentialCurve(), OrbitPeriod = new ExponentialCurve() + }; + var threw = 0; + var built = 0; + for (var exponent10 = -3f; exponent10 <= 8f; exponent10 += .25f) + { + var mass = pow(10f, exponent10); + var core = planets.CoreRadius.Evaluate(mass); + var roche = planets.RocheLimit.Evaluate(mass); + if (0 < core && core < roche) + { + ZoneOf(planets, (mass, float2.zero)); + built++; + } + else + { + Assert.Throws(() => ZoneOf(planets, (mass, float2.zero))); + threw++; + } + } + Assert.True(threw > 0 && built > 0, "the sweep holds masses on both sides of the crossing"); + } + + // The shipped curves keep the core inside the Roche limit over the whole generated mass range. + [Fact] + public void TheAuthoredCurvesBuildAtEveryMass() + { + var planets = Curves(); + for (var exponent10 = -3f; exponent10 <= 8f; exponent10 += .25f) + ZoneOf(planets, (pow(10f, exponent10), float2.zero)); + } + + // A well that is negative, not a number or infinite is an authoring error, not an antimass body. Zero is the unauthored + // default and digs nothing (BodiesWithNoAuthoredWellPullAndDigNothing). + [Theory] + [InlineData(-10f)] + [InlineData(float.NaN)] + [InlineData(float.PositiveInfinity)] + [InlineData(float.NegativeInfinity)] + public void AnUnphysicalWellStrengthThrowsAtConstruction(float strength) + { + var planets = Curves(); + planets.WellStrength = new ExponentialCurve { Constant = strength }; + Assert.Throws(() => ZoneOf(planets, (100f, float2.zero))); + planets.CoreRadius = new ExponentialCurve(); + planets.RocheLimit = new ExponentialCurve(); + Assert.Throws(() => ZoneOf(planets, (100f, float2.zero))); + } + + // The well is authored once, by curves of mass (target: no per-body authoring of a core or Roche limit): a body whose + // record carries other radius, gravity-radius or gravity-depth multipliers has the same strength, core and Roche limit, + // and pulls and digs exactly as its plain twin. The multipliers are brush inputs for the renderer, nothing else. + [Theory] + [InlineData(2.5f, 3f, .4f)] + [InlineData(.5f, .5f, 3f)] + public void PerBodyMultipliersDoNotMoveTheWell(float bodyRadius, float gravityRadius, float gravityDepth) + { + var planets = Curves(); + foreach (var mass in new[] { 29.2f, 14152.4f }) + { + var plain = ZoneOf(planets, (mass, float2.zero)); + var scaled = ZoneOf(planets, data => + { + data.BodyRadiusMultiplier = bodyRadius; + data.GravityRadiusMultiplier = gravityRadius; + data.GravityDepthMultiplier = gravityDepth; + }, (mass, float2.zero)); + var a = plain.PlanetInstances.Values.Single(); + var b = scaled.PlanetInstances.Values.Single(); + Assert.Equal(a.WellStrength, b.WellStrength); + Assert.Equal(a.CoreRadius, b.CoreRadius); + Assert.Equal(a.RocheLimit, b.RocheLimit); + foreach (var p in new[] { float2(.4f * a.CoreRadius, 0), float2(0, 3f * a.CoreRadius), float2(400f, 300f) }) + { + Assert.Equal(plain.GetForce(p), scaled.GetForce(p)); + Assert.Equal(plain.GetHeight(p), scaled.GetHeight(p)); + } + } + } + [Fact] public void TheTailIsAPointMassWithNoRimAndNoGate() { @@ -201,7 +300,13 @@ public sealed class PotentialOwnerTests : IDisposable var c1 = planets.WellStrength.Evaluate(14152.4f); var core1 = planets.CoreRadius.Evaluate(14152.4f); const float step = .5f; - foreach (var p in new[] { float2(-200f, 120f), float2(0f, 0f), float2(100f, -300f), float2(500f, 40f), float2(-290f, 12f), float2(310f, 20f), float2(700f, 700f), float2(-80f, -500f) }) + // Inside the two cores as well, out to their outer bands (0.5 R to R), where the potential is the quadratic bowl. + var inCore = new[] + { + float2(-300f + .5f * core0, 0f), float2(-300f, .65f * core0), float2(-300f - .86f * core0, 0f), float2(-300f + .6f * core0, .6f * core0), + float2(300f + .55f * core1, 0f), float2(300f, -.7f * core1), float2(300f - .86f * core1, 0f), float2(300f + .9f * core1, 0f) + }; + foreach (var p in inCore.Concat(new[] { float2(-200f, 120f), float2(0f, 0f), float2(100f, -300f), float2(500f, 40f), float2(-290f, 12f), float2(310f, 20f), float2(700f, 700f), float2(-80f, -500f) })) { var expected = Phi(c0, core0, length(p - float2(-300f, 0f))) - Phi(c0, core0, PackRadius) + Phi(c1, core1, length(p - float2(300f, 0f))) - Phi(c1, core1, PackRadius); From 3a5b3b0bab27c63251eb97df87831152115a1cae Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 07:11:25 +0200 Subject: [PATCH 07/20] Gravity grid-lowering: the drawn height is one Gravity Field pass over the zone's wells; gravity brushes and brush inputs deleted Zone.WellReference owns each body's reference zero (GetHeight uses it). Gravity.cginc mirrors GravityField.Potential; Brushes/Gravity Field draws depth = -h on layer 9 from a StructuredBuffer that GravityLowering.Lower fills from the zone each frame; GravityLowering.CreateField makes the one quad. GravityFieldParityVerify renders it and compares every texel with -Zone.GetHeight (max error 0.0059 u), the gradient with GetForce (0.03 degrees) and the wiring. Deleted: the Gravity Well children of Planet, Gas Giant, Sun and PlanetOutpost prefabs, Wormhole 1's three gravity children, their overrides in Main Menu and TestScene, five wormhole/wave materials and two brush shaders, Planet.GravityWellDepth/Radius, BodyData keys 6-7, PlanetSettings.GravityDepth/GravityRadius (and the Settings.asset keys). Surface Displacement culls layer 9 only. Headless build and tests not yet run at this commit. Co-Authored-By: Claude Opus 5.5 --- .../Prefabs/Stations/PlanetOutpost.prefab | 83 ------ .../{Gravity Well.mat => Gravity Field.mat} | 7 +- ...y Well.mat.meta => Gravity Field.mat.meta} | 0 Assets/Materials/Brushes/Gravity Waves.mat | 83 ------ .../Materials/Brushes/Gravity Waves.mat.meta | 8 - .../Materials/Brushes/Wormhole Gravity 1.mat | 80 ----- .../Brushes/Wormhole Gravity 1.mat.meta | 8 - .../Materials/Brushes/Wormhole Gravity 2.mat | 80 ----- .../Brushes/Wormhole Gravity 2.mat.meta | 8 - Assets/Materials/Brushes/Wormhole Gravity.mat | 82 ------ .../Brushes/Wormhole Gravity.mat.meta | 8 - Assets/Materials/Brushes/Wormhole Waves.mat | 84 ------ .../Materials/Brushes/Wormhole Waves.mat.meta | 8 - Assets/Prefabs/RPG/Planets/Gas Giant.prefab | 85 ------ Assets/Prefabs/RPG/Planets/Planet.prefab | 85 ------ Assets/Prefabs/RPG/Planets/Sun.prefab | 85 ------ Assets/Prefabs/RPG/Wormhole 1.prefab | 246 ---------------- Assets/Resources/Settings.asset | 4 +- Assets/Scenes/ARPG.unity | 3 +- Assets/Scenes/Main Menu.unity | 10 - Assets/Scenes/TestScene.unity | 30 -- .../Editor/GravityFieldParityVerify.cs | 275 ++++++++++++++++++ .../Editor/GravityFieldParityVerify.cs.meta | 11 + Assets/Scripts/ServerShared/Settings.cs | 2 - Assets/Scripts/ServerShared/Zone.cs | 12 +- Assets/Scripts/ServerShared/ZoneData.cs | 6 - .../Scripts/Zone Display/GravityLowering.cs | 78 +++++ .../Zone Display/GravityLowering.cs.meta | 11 + Assets/Scripts/Zone Display/PlanetObject.cs | 1 - Assets/Scripts/Zone Display/ZoneRenderer.cs | 21 +- Assets/Shaders/Brushes/GravityField.shader | 47 +++ ...h.shader.meta => GravityField.shader.meta} | 2 +- Assets/Shaders/Brushes/RadialWaveBrush.shader | 81 ------ Assets/Shaders/Brushes/WormholeBrush.shader | 85 ------ Assets/Shaders/Gravity.cginc | 42 +++ ...leBrush.shader.meta => Gravity.cginc.meta} | 3 +- .../GravitySubtractTests.cs | 12 +- .../Aetheria.Shared.Tests/MiningCut2Tests.cs | 6 +- .../Aetheria.Shared.Tests/MiningCut3Tests.cs | 2 - .../PotentialOwnerTests.cs | 17 +- tests/Aetheria.Shared.Tests/WellFixture.cs | 2 - .../ZonePlacedAtBuildTests.cs | 2 - 42 files changed, 504 insertions(+), 1301 deletions(-) rename Assets/Materials/Brushes/{Gravity Well.mat => Gravity Field.mat} (92%) rename Assets/Materials/Brushes/{Gravity Well.mat.meta => Gravity Field.mat.meta} (100%) delete mode 100644 Assets/Materials/Brushes/Gravity Waves.mat delete mode 100644 Assets/Materials/Brushes/Gravity Waves.mat.meta delete mode 100644 Assets/Materials/Brushes/Wormhole Gravity 1.mat delete mode 100644 Assets/Materials/Brushes/Wormhole Gravity 1.mat.meta delete mode 100644 Assets/Materials/Brushes/Wormhole Gravity 2.mat delete mode 100644 Assets/Materials/Brushes/Wormhole Gravity 2.mat.meta delete mode 100644 Assets/Materials/Brushes/Wormhole Gravity.mat delete mode 100644 Assets/Materials/Brushes/Wormhole Gravity.mat.meta delete mode 100644 Assets/Materials/Brushes/Wormhole Waves.mat delete mode 100644 Assets/Materials/Brushes/Wormhole Waves.mat.meta create mode 100644 Assets/Scripts/Editor/GravityFieldParityVerify.cs create mode 100644 Assets/Scripts/Editor/GravityFieldParityVerify.cs.meta create mode 100644 Assets/Scripts/Zone Display/GravityLowering.cs create mode 100644 Assets/Scripts/Zone Display/GravityLowering.cs.meta create mode 100644 Assets/Shaders/Brushes/GravityField.shader rename Assets/Shaders/Brushes/{RadialWaveBrush.shader.meta => GravityField.shader.meta} (80%) delete mode 100644 Assets/Shaders/Brushes/RadialWaveBrush.shader delete mode 100644 Assets/Shaders/Brushes/WormholeBrush.shader create mode 100644 Assets/Shaders/Gravity.cginc rename Assets/Shaders/{Brushes/WormholeBrush.shader.meta => Gravity.cginc.meta} (71%) diff --git a/Assets/Content/Prefabs/Stations/PlanetOutpost.prefab b/Assets/Content/Prefabs/Stations/PlanetOutpost.prefab index 6ce31f34f..e3d20ceb7 100644 --- a/Assets/Content/Prefabs/Stations/PlanetOutpost.prefab +++ b/Assets/Content/Prefabs/Stations/PlanetOutpost.prefab @@ -81,87 +81,6 @@ MeshRenderer: m_SortingLayer: 0 m_SortingOrder: 0 m_AdditionalVertexStreams: {fileID: 0} ---- !u!1 &7783244517717541194 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 7783244517717541195} - - component: {fileID: 7783244517717541175} - - component: {fileID: 7783244517717541174} - m_Layer: 9 - m_Name: Gravity Well - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &7783244517717541195 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7783244517717541194} - m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 7783244518521719148} - m_RootOrder: 2 - m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} ---- !u!33 &7783244517717541175 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7783244517717541194} - m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0} ---- !u!23 &7783244517717541174 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7783244517717541194} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RayTraceProcedural: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: 44a8bbb89acb4e34c9f41a9da5842bb4, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_AdditionalVertexStreams: {fileID: 0} --- !u!1 &7783244518317531027 GameObject: m_ObjectHideFlags: 0 @@ -289,7 +208,6 @@ Transform: m_Children: - {fileID: 589192530128514016} - {fileID: 7783244518317531036} - - {fileID: 7783244517717541195} - {fileID: 7783244516809707565} m_Father: {fileID: 0} m_RootOrder: 0 @@ -307,7 +225,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: Body: {fileID: 7783244518317531038} - GravityWell: {fileID: 7783244517717541174} Icon: {fileID: 7783244516809707566} Generator: {fileID: 741236912059895623} --- !u!114 &741236912059895623 diff --git a/Assets/Materials/Brushes/Gravity Well.mat b/Assets/Materials/Brushes/Gravity Field.mat similarity index 92% rename from Assets/Materials/Brushes/Gravity Well.mat rename to Assets/Materials/Brushes/Gravity Field.mat index e0bd9f79d..d912917c9 100644 --- a/Assets/Materials/Brushes/Gravity Well.mat +++ b/Assets/Materials/Brushes/Gravity Field.mat @@ -7,8 +7,8 @@ Material: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: Gravity Well - m_Shader: {fileID: 4800000, guid: 268da230635cfb34ab4ed6ad39503fa0, type: 3} + m_Name: Gravity Field + m_Shader: {fileID: 4800000, guid: 08d8efa80af84065b54c9bfed784e435, type: 3} m_ShaderKeywords: m_LightmapFlags: 4 m_EnableInstancingVariants: 0 @@ -57,8 +57,6 @@ Material: m_Offset: {x: 0, y: 0} m_Floats: - _BumpScale: 1 - - _Cutoff: 1 - - _Depth: 80 - _DetailNormalMapScale: 1 - _DstBlend: 0 - _GlossMapScale: 1 @@ -68,7 +66,6 @@ Material: - _Mode: 0 - _OcclusionStrength: 1 - _Parallax: 0.02 - - _Power: 16 - _SmoothnessTextureChannel: 0 - _SpecularHighlights: 1 - _SrcBlend: 1 diff --git a/Assets/Materials/Brushes/Gravity Well.mat.meta b/Assets/Materials/Brushes/Gravity Field.mat.meta similarity index 100% rename from Assets/Materials/Brushes/Gravity Well.mat.meta rename to Assets/Materials/Brushes/Gravity Field.mat.meta diff --git a/Assets/Materials/Brushes/Gravity Waves.mat b/Assets/Materials/Brushes/Gravity Waves.mat deleted file mode 100644 index a45dfed21..000000000 --- a/Assets/Materials/Brushes/Gravity Waves.mat +++ /dev/null @@ -1,83 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!21 &2100000 -Material: - serializedVersion: 6 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_Name: Gravity Waves - m_Shader: {fileID: 4800000, guid: 8a8e593b17063b54ea02f7ea5363b59d, type: 3} - m_ShaderKeywords: - m_LightmapFlags: 4 - m_EnableInstancingVariants: 0 - m_DoubleSidedGI: 0 - m_CustomRenderQueue: -1 - stringTagMap: {} - disabledShaderPasses: [] - m_SavedProperties: - serializedVersion: 3 - m_TexEnvs: - - _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} - m_Floats: - - _BumpScale: 1 - - _Cutoff: 0.5 - - _Depth: 3.5 - - _DetailNormalMapScale: 1 - - _DstBlend: 0 - - _Frequency: 27.43 - - _GlossMapScale: 1 - - _Glossiness: 0.5 - - _GlossyReflections: 1 - - _Metallic: 0 - - _Mode: 0 - - _OcclusionStrength: 1 - - _Parallax: 0.02 - - _Phase: 0 - - _Power: 8 - - _SinePower: 1.25 - - _SmoothnessTextureChannel: 0 - - _SpecularHighlights: 1 - - _SrcBlend: 1 - - _UVSec: 0 - - _ZWrite: 1 - m_Colors: - - _Color: {r: 1, g: 1, b: 1, a: 1} - - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - m_BuildTextureStacks: [] diff --git a/Assets/Materials/Brushes/Gravity Waves.mat.meta b/Assets/Materials/Brushes/Gravity Waves.mat.meta deleted file mode 100644 index f4e2f41d4..000000000 --- a/Assets/Materials/Brushes/Gravity Waves.mat.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 11fbaa87dcc7a3743a6bd3aa5c86e5ae -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 2100000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Materials/Brushes/Wormhole Gravity 1.mat b/Assets/Materials/Brushes/Wormhole Gravity 1.mat deleted file mode 100644 index 3ae24d6ee..000000000 --- a/Assets/Materials/Brushes/Wormhole Gravity 1.mat +++ /dev/null @@ -1,80 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!21 &2100000 -Material: - serializedVersion: 6 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_Name: Wormhole Gravity 1 - m_Shader: {fileID: 4800000, guid: 268da230635cfb34ab4ed6ad39503fa0, type: 3} - m_ShaderKeywords: - m_LightmapFlags: 4 - m_EnableInstancingVariants: 0 - m_DoubleSidedGI: 0 - m_CustomRenderQueue: -1 - stringTagMap: {} - disabledShaderPasses: [] - m_SavedProperties: - serializedVersion: 3 - m_TexEnvs: - - _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} - m_Floats: - - _BumpScale: 1 - - _Cutoff: 1 - - _Depth: 54 - - _DetailNormalMapScale: 1 - - _DstBlend: 0 - - _GlossMapScale: 1 - - _Glossiness: 0.5 - - _GlossyReflections: 1 - - _Metallic: 0 - - _Mode: 0 - - _OcclusionStrength: 1 - - _Parallax: 0.02 - - _Power: 4 - - _SmoothnessTextureChannel: 0 - - _SpecularHighlights: 1 - - _SrcBlend: 1 - - _UVSec: 0 - - _ZWrite: 1 - m_Colors: - - _Color: {r: 1, g: 1, b: 1, a: 1} - - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - m_BuildTextureStacks: [] diff --git a/Assets/Materials/Brushes/Wormhole Gravity 1.mat.meta b/Assets/Materials/Brushes/Wormhole Gravity 1.mat.meta deleted file mode 100644 index 7d40d0332..000000000 --- a/Assets/Materials/Brushes/Wormhole Gravity 1.mat.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 244f3e4c0c030a24b8d7aa944895bdcf -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 2100000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Materials/Brushes/Wormhole Gravity 2.mat b/Assets/Materials/Brushes/Wormhole Gravity 2.mat deleted file mode 100644 index 3ae24d6ee..000000000 --- a/Assets/Materials/Brushes/Wormhole Gravity 2.mat +++ /dev/null @@ -1,80 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!21 &2100000 -Material: - serializedVersion: 6 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_Name: Wormhole Gravity 1 - m_Shader: {fileID: 4800000, guid: 268da230635cfb34ab4ed6ad39503fa0, type: 3} - m_ShaderKeywords: - m_LightmapFlags: 4 - m_EnableInstancingVariants: 0 - m_DoubleSidedGI: 0 - m_CustomRenderQueue: -1 - stringTagMap: {} - disabledShaderPasses: [] - m_SavedProperties: - serializedVersion: 3 - m_TexEnvs: - - _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} - m_Floats: - - _BumpScale: 1 - - _Cutoff: 1 - - _Depth: 54 - - _DetailNormalMapScale: 1 - - _DstBlend: 0 - - _GlossMapScale: 1 - - _Glossiness: 0.5 - - _GlossyReflections: 1 - - _Metallic: 0 - - _Mode: 0 - - _OcclusionStrength: 1 - - _Parallax: 0.02 - - _Power: 4 - - _SmoothnessTextureChannel: 0 - - _SpecularHighlights: 1 - - _SrcBlend: 1 - - _UVSec: 0 - - _ZWrite: 1 - m_Colors: - - _Color: {r: 1, g: 1, b: 1, a: 1} - - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - m_BuildTextureStacks: [] diff --git a/Assets/Materials/Brushes/Wormhole Gravity 2.mat.meta b/Assets/Materials/Brushes/Wormhole Gravity 2.mat.meta deleted file mode 100644 index fb6f1270d..000000000 --- a/Assets/Materials/Brushes/Wormhole Gravity 2.mat.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 0ec0689c58b99c64297b3e429e1d9112 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 2100000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Materials/Brushes/Wormhole Gravity.mat b/Assets/Materials/Brushes/Wormhole Gravity.mat deleted file mode 100644 index fb6f52b20..000000000 --- a/Assets/Materials/Brushes/Wormhole Gravity.mat +++ /dev/null @@ -1,82 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!21 &2100000 -Material: - serializedVersion: 8 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_Name: Wormhole Gravity - m_Shader: {fileID: 4800000, guid: 268da230635cfb34ab4ed6ad39503fa0, type: 3} - m_ValidKeywords: [] - m_InvalidKeywords: [] - m_LightmapFlags: 4 - m_EnableInstancingVariants: 0 - m_DoubleSidedGI: 0 - m_CustomRenderQueue: -1 - stringTagMap: {} - disabledShaderPasses: [] - m_SavedProperties: - serializedVersion: 3 - m_TexEnvs: - - _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} - m_Ints: [] - m_Floats: - - _BumpScale: 1 - - _Cutoff: 0.15 - - _Depth: 2000 - - _DetailNormalMapScale: 1 - - _DstBlend: 0 - - _GlossMapScale: 1 - - _Glossiness: 0.5 - - _GlossyReflections: 1 - - _Metallic: 0 - - _Mode: 0 - - _OcclusionStrength: 1 - - _Parallax: 0.02 - - _Power: 64 - - _SmoothnessTextureChannel: 0 - - _SpecularHighlights: 1 - - _SrcBlend: 1 - - _UVSec: 0 - - _ZWrite: 1 - m_Colors: - - _Color: {r: 1, g: 1, b: 1, a: 1} - - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - m_BuildTextureStacks: [] diff --git a/Assets/Materials/Brushes/Wormhole Gravity.mat.meta b/Assets/Materials/Brushes/Wormhole Gravity.mat.meta deleted file mode 100644 index 30ec9b01d..000000000 --- a/Assets/Materials/Brushes/Wormhole Gravity.mat.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: a9ef17c902709ce41a837c54b809184b -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 2100000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Materials/Brushes/Wormhole Waves.mat b/Assets/Materials/Brushes/Wormhole Waves.mat deleted file mode 100644 index 7902c5c36..000000000 --- a/Assets/Materials/Brushes/Wormhole Waves.mat +++ /dev/null @@ -1,84 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!21 &2100000 -Material: - serializedVersion: 6 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_Name: Wormhole Waves - m_Shader: {fileID: 4800000, guid: 8681ac064d59d15458d16cc9b884262c, type: 3} - m_ShaderKeywords: - m_LightmapFlags: 4 - m_EnableInstancingVariants: 0 - m_DoubleSidedGI: 0 - m_CustomRenderQueue: -1 - stringTagMap: {} - disabledShaderPasses: [] - m_SavedProperties: - serializedVersion: 3 - m_TexEnvs: - - _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} - m_Floats: - - _BumpScale: 1 - - _Cutoff: 0.5 - - _Depth: 33.9 - - _DetailNormalMapScale: 1 - - _DstBlend: 0 - - _Frequency: 2 - - _FrequencyDist: 60 - - _GlossMapScale: 1 - - _Glossiness: 0.5 - - _GlossyReflections: 1 - - _Metallic: 0 - - _Mode: 0 - - _OcclusionStrength: 1 - - _Parallax: 0.02 - - _Power: 2 - - _SinePower: 1.25 - - _SmoothnessTextureChannel: 0 - - _SpecularHighlights: 1 - - _Speed: 15 - - _SrcBlend: 1 - - _UVSec: 0 - - _ZWrite: 1 - m_Colors: - - _Color: {r: 1, g: 1, b: 1, a: 1} - - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - m_BuildTextureStacks: [] diff --git a/Assets/Materials/Brushes/Wormhole Waves.mat.meta b/Assets/Materials/Brushes/Wormhole Waves.mat.meta deleted file mode 100644 index 1e5f35dd3..000000000 --- a/Assets/Materials/Brushes/Wormhole Waves.mat.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: ef2f6090d5cc14a4e9ce38def3bed9ac -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 2100000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Prefabs/RPG/Planets/Gas Giant.prefab b/Assets/Prefabs/RPG/Planets/Gas Giant.prefab index cb628d804..de87b2a13 100644 --- a/Assets/Prefabs/RPG/Planets/Gas Giant.prefab +++ b/Assets/Prefabs/RPG/Planets/Gas Giant.prefab @@ -30,7 +30,6 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: - {fileID: 3973935122748960680} - - {fileID: 3973935121058605868} - {fileID: 3973935121358855036} m_Father: {fileID: 0} m_RootOrder: 0 @@ -48,93 +47,9 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: Body: {fileID: 3973935122748960683} - GravityWell: {fileID: 3973935121058605871} Icon: {fileID: 3973935121358855037} Generator: {fileID: 0} SunMaterial: {fileID: 3973935122748960685} ---- !u!1 &3973935121058605867 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 3973935121058605868} - - component: {fileID: 3973935121058605856} - - component: {fileID: 3973935121058605871} - m_Layer: 9 - m_Name: Gravity Well - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &3973935121058605868 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 3973935121058605867} - m_LocalRotation: {x: 0.7071068, y: -0, z: -0, w: 0.7071068} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 3973935120991099173} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} ---- !u!33 &3973935121058605856 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 3973935121058605867} - m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0} ---- !u!23 &3973935121058605871 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 3973935121058605867} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_StaticShadowCaster: 0 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RayTraceProcedural: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: 44a8bbb89acb4e34c9f41a9da5842bb4, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_AdditionalVertexStreams: {fileID: 0} --- !u!1 &3973935121358855035 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/RPG/Planets/Planet.prefab b/Assets/Prefabs/RPG/Planets/Planet.prefab index 336b3430b..afffe73c4 100644 --- a/Assets/Prefabs/RPG/Planets/Planet.prefab +++ b/Assets/Prefabs/RPG/Planets/Planet.prefab @@ -83,89 +83,6 @@ MeshRenderer: m_SortingLayer: 0 m_SortingOrder: 0 m_AdditionalVertexStreams: {fileID: 0} ---- !u!1 &8859079004671924238 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 8859079004671924239} - - component: {fileID: 8859079004671924339} - - component: {fileID: 8859079004671924338} - m_Layer: 9 - m_Name: Gravity Well - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &8859079004671924239 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8859079004671924238} - m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 8859079004937162792} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} ---- !u!33 &8859079004671924339 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8859079004671924238} - m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0} ---- !u!23 &8859079004671924338 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8859079004671924238} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_StaticShadowCaster: 0 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RayTraceProcedural: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: 44a8bbb89acb4e34c9f41a9da5842bb4, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_AdditionalVertexStreams: {fileID: 0} --- !u!1 &8859079004937162791 GameObject: m_ObjectHideFlags: 0 @@ -197,7 +114,6 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: - {fileID: 8859079005270853336} - - {fileID: 8859079004671924239} - {fileID: 8859079003226229097} m_Father: {fileID: 0} m_RootOrder: 0 @@ -215,7 +131,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: Body: {fileID: 8859079005270853338} - GravityWell: {fileID: 8859079004671924338} Icon: {fileID: 8859079003226229098} Generator: {fileID: -7153121627769399805} --- !u!114 &-7153121627769399805 diff --git a/Assets/Prefabs/RPG/Planets/Sun.prefab b/Assets/Prefabs/RPG/Planets/Sun.prefab index cf7fb216f..ebe0fa72f 100644 --- a/Assets/Prefabs/RPG/Planets/Sun.prefab +++ b/Assets/Prefabs/RPG/Planets/Sun.prefab @@ -30,7 +30,6 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: - {fileID: 7852221720971737233} - - {fileID: 7852221720969441490} - {fileID: 7852221720816817928} - {fileID: 7852221720964551245} m_Father: {fileID: 0} @@ -49,7 +48,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: Body: {fileID: 7852221720971737229} - GravityWell: {fileID: 7852221720969441484} Icon: {fileID: 7852221720964551246} Generator: {fileID: 0} SunMaterial: {fileID: 7852221720971737234} @@ -221,89 +219,6 @@ MeshRenderer: m_SortingLayer: 0 m_SortingOrder: 0 m_AdditionalVertexStreams: {fileID: 0} ---- !u!1 &7852221720969441489 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 7852221720969441490} - - component: {fileID: 7852221720969441485} - - component: {fileID: 7852221720969441484} - m_Layer: 9 - m_Name: Gravity Well - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &7852221720969441490 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7852221720969441489} - m_LocalRotation: {x: 0.7071068, y: -0, z: -0, w: 0.7071068} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 7852221720480299767} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} ---- !u!33 &7852221720969441485 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7852221720969441489} - m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0} ---- !u!23 &7852221720969441484 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7852221720969441489} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_StaticShadowCaster: 0 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RayTraceProcedural: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: 44a8bbb89acb4e34c9f41a9da5842bb4, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_AdditionalVertexStreams: {fileID: 0} --- !u!1 &7852221720971737232 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/RPG/Wormhole 1.prefab b/Assets/Prefabs/RPG/Wormhole 1.prefab index b03d01009..e1ca93be7 100644 --- a/Assets/Prefabs/RPG/Wormhole 1.prefab +++ b/Assets/Prefabs/RPG/Wormhole 1.prefab @@ -1,167 +1,5 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: ---- !u!1 &1826894967093516808 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1030590306481442051} - - component: {fileID: 3216580199816124320} - - component: {fileID: 3211969211988968959} - m_Layer: 9 - m_Name: Gravity Well - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &1030590306481442051 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1826894967093516808} - m_LocalRotation: {x: 0.7071068, y: -0, z: -0, w: 0.7071068} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1024, y: 1024, z: 1024} - m_Children: [] - m_Father: {fileID: 463084220523011477} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} ---- !u!33 &3216580199816124320 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1826894967093516808} - m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0} ---- !u!23 &3211969211988968959 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1826894967093516808} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RayTraceProcedural: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: 244f3e4c0c030a24b8d7aa944895bdcf, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_AdditionalVertexStreams: {fileID: 0} ---- !u!1 &3908760799087214860 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 581261949390603689} - - component: {fileID: 987447324816385543} - - component: {fileID: 3959510878930752720} - m_Layer: 9 - m_Name: Gravity Waves - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &581261949390603689 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 3908760799087214860} - m_LocalRotation: {x: 0.7071068, y: -0, z: -0, w: 0.7071068} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 512, y: 512, z: 512} - m_Children: [] - m_Father: {fileID: 463084220523011477} - m_RootOrder: 2 - m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} ---- !u!33 &987447324816385543 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 3908760799087214860} - m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0} ---- !u!23 &3959510878930752720 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 3908760799087214860} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RayTraceProcedural: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: ef2f6090d5cc14a4e9ce38def3bed9ac, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_AdditionalVertexStreams: {fileID: 0} --- !u!1 &4837153162502999620 GameObject: m_ObjectHideFlags: 0 @@ -189,9 +27,6 @@ Transform: m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - - {fileID: 8222188360457572195} - - {fileID: 1030590306481442051} - - {fileID: 581261949390603689} - {fileID: 8249320701965103923} m_Father: {fileID: 0} m_RootOrder: 0 @@ -277,84 +112,3 @@ MeshRenderer: m_SortingLayer: 0 m_SortingOrder: 0 m_AdditionalVertexStreams: {fileID: 0} ---- !u!1 &7647029665738834910 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 8222188360457572195} - - component: {fileID: 2468954688819198096} - - component: {fileID: 8290522694236574882} - m_Layer: 9 - m_Name: Gravity Pit - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &8222188360457572195 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7647029665738834910} - m_LocalRotation: {x: 0.7071068, y: -0, z: -0, w: 0.7071068} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 512, y: 512, z: 512} - m_Children: [] - m_Father: {fileID: 463084220523011477} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} ---- !u!33 &2468954688819198096 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7647029665738834910} - m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0} ---- !u!23 &8290522694236574882 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7647029665738834910} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RayTraceProcedural: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: a9ef17c902709ce41a837c54b809184b, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_AdditionalVertexStreams: {fileID: 0} diff --git a/Assets/Resources/Settings.asset b/Assets/Resources/Settings.asset index 7b85163f5..ec980b8e8 100644 --- a/Assets/Resources/Settings.asset +++ b/Assets/Resources/Settings.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8eaa1790664477d84e442fbefc89dbd83f0b6948b4433f721f67a78703c6d7b4 -size 12871 +oid sha256:51f559958bd719e1d158b526bee1876fc3c838462b638d79c4f448c34331c420 +size 12712 diff --git a/Assets/Scenes/ARPG.unity b/Assets/Scenes/ARPG.unity index 57c793e09..370f1914b 100644 --- a/Assets/Scenes/ARPG.unity +++ b/Assets/Scenes/ARPG.unity @@ -16416,6 +16416,7 @@ MonoBehaviour: MapGravityMaterials: - {fileID: 2100000, guid: 841e4091d19548347bd59115047b4e49, type: 2} - {fileID: 2100000, guid: a92fc6d958edb9f46b6e58134f609cc0, type: 2} + GravityField: {fileID: 2100000, guid: 44a8bbb89acb4e34c9f41a9da5842bb4, type: 2} Tour: 0 TourSwitchTime: 10 TourFollowDistance: 100 @@ -23473,7 +23474,7 @@ Camera: m_Depth: 0 m_CullingMask: serializedVersion: 2 - m_Bits: 1536 + m_Bits: 512 m_RenderingPath: 1 m_TargetTexture: {fileID: 8400000, guid: 2fc21a9d3e9647948b56e384cd9378b3, type: 2} m_TargetDisplay: 0 diff --git a/Assets/Scenes/Main Menu.unity b/Assets/Scenes/Main Menu.unity index 2d80e45b7..b770f3db7 100644 --- a/Assets/Scenes/Main Menu.unity +++ b/Assets/Scenes/Main Menu.unity @@ -1076,16 +1076,6 @@ PrefabInstance: propertyPath: m_Materials.Array.data[0] value: objectReference: {fileID: 2100000, guid: b9f52544f98f47146b486fb6e27179bb, type: 2} - - target: {fileID: 7852221720969441490, guid: 046dde0f4600bce41ad33c476f99b309, - type: 3} - propertyPath: m_LocalScale.x - value: 512 - objectReference: {fileID: 0} - - target: {fileID: 7852221720969441490, guid: 046dde0f4600bce41ad33c476f99b309, - type: 3} - propertyPath: m_LocalScale.y - value: 512 - objectReference: {fileID: 0} - target: {fileID: 7852221720971737233, guid: 046dde0f4600bce41ad33c476f99b309, type: 3} propertyPath: m_LocalScale.x diff --git a/Assets/Scenes/TestScene.unity b/Assets/Scenes/TestScene.unity index ffc3f3905..06ee5fa70 100644 --- a/Assets/Scenes/TestScene.unity +++ b/Assets/Scenes/TestScene.unity @@ -911,16 +911,6 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 7852221720969441490, guid: 046dde0f4600bce41ad33c476f99b309, - type: 3} - propertyPath: m_LocalScale.x - value: 20 - objectReference: {fileID: 0} - - target: {fileID: 7852221720969441490, guid: 046dde0f4600bce41ad33c476f99b309, - type: 3} - propertyPath: m_LocalScale.y - value: 20 - objectReference: {fileID: 0} - target: {fileID: 7852221720971737233, guid: 046dde0f4600bce41ad33c476f99b309, type: 3} propertyPath: m_LocalPosition.y @@ -1768,16 +1758,6 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 7852221720969441490, guid: 046dde0f4600bce41ad33c476f99b309, - type: 3} - propertyPath: m_LocalScale.x - value: 20 - objectReference: {fileID: 0} - - target: {fileID: 7852221720969441490, guid: 046dde0f4600bce41ad33c476f99b309, - type: 3} - propertyPath: m_LocalScale.y - value: 20 - objectReference: {fileID: 0} - target: {fileID: 7852221720971737233, guid: 046dde0f4600bce41ad33c476f99b309, type: 3} propertyPath: m_LocalPosition.y @@ -5277,16 +5257,6 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 7852221720969441490, guid: 046dde0f4600bce41ad33c476f99b309, - type: 3} - propertyPath: m_LocalScale.x - value: 20 - objectReference: {fileID: 0} - - target: {fileID: 7852221720969441490, guid: 046dde0f4600bce41ad33c476f99b309, - type: 3} - propertyPath: m_LocalScale.y - value: 20 - objectReference: {fileID: 0} - target: {fileID: 7852221720971737233, guid: 046dde0f4600bce41ad33c476f99b309, type: 3} propertyPath: m_LocalPosition.y diff --git a/Assets/Scripts/Editor/GravityFieldParityVerify.cs b/Assets/Scripts/Editor/GravityFieldParityVerify.cs new file mode 100644 index 000000000..343789089 --- /dev/null +++ b/Assets/Scripts/Editor/GravityFieldParityVerify.cs @@ -0,0 +1,275 @@ +using System; +using System.IO; +using System.Linq; +using GameCult.Caching; +using UnityEditor; +using UnityEditor.SceneManagement; +using UnityEngine; +using UnityEngine.Rendering; +using CultMath; + +namespace Aetheria.EditorTools +{ + /// + /// Batchmode check for campaign aetheria-gravity, cut grid-lowering: what the Gravity Field pass draws is the sim's + /// height. It builds a zone from Settings.asset's PlanetSettings with three bodies, runs the real lowering + /// (GravityLowering.Lower and CreateField), renders the field through an orthographic camera that culls layer 9 into + /// a float target, and compares every texel with -Zone.GetHeight at the texel centre's world position. It then checks + /// that the texture's gradient points where Zone.GetForce does, and that ARPG.unity and the body prefabs are wired + /// the way the cut leaves them (the gravity cameras cull layer 9 alone, nothing but the run-time field sits on it). + /// + /// Renders, so it needs a graphics device: run WITHOUT -nographics (as FlowFieldParityVerify). + /// Unity -batchmode -projectPath <repo> -executeMethod Aetheria.EditorTools.GravityFieldParityVerify.Run -logFile <path> + /// Do not pass -quit: Run exits the Editor itself, 0 on success and 1 on any failure. + /// + public static class GravityFieldParityVerify + { + const string Tag = "[GravityFieldParityVerify]"; + const int Size = 256; + // Measured on this tree (the "max error" line this run prints): the largest |texel + GetHeight| over the three + // windows is 0.0059 u, in the planetoid's window (float32 on both sides, the GPU's log against the CPU's, the + // quad's interpolated world position). The tolerance is 5x that. A 0.1% error in the tail constant (.5 -> .501) + // moves the drawn height by 0.053 u where all three tails reach (the planetoid and zone windows), 1.8x the + // tolerance; a reference of zero moves it by about 150 u. + const float Tolerance = 0.03f; + // The worst angle between the texture's central difference and GetForce (B28: 1.0 degrees median zone, 2.9 worst). + const float GradientDegrees = 3f; + static float _maxError, _maxAngle; + static bool _ok = true; + + static void OnLog(string message, string stack, LogType type) + { + if ((type == LogType.Error || type == LogType.Exception || type == LogType.Assert) && !message.StartsWith(Tag)) + Fail("logged-error", message.Split('\n')[0]); + } + + static void Fail(string check, string detail) + { + Debug.LogError($"{Tag} FAIL {check}: {detail}"); + _ok = false; + } + + public static void Run() + { + if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Null) + { + Debug.LogError($"{Tag} FAIL: no graphics device in this session; rerun batchmode without -nographics."); + EditorApplication.Exit(1); + return; + } + + Application.logMessageReceived += OnLog; + var work = Path.Combine(Path.GetTempPath(), "gravity-parity-" + Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(work); + ComputeBuffer wells = null; + GameObject field = null; + try + { + var settings = AssetDatabase.LoadAssetAtPath("Assets/Resources/Settings.asset") + ?? throw new InvalidOperationException("No Settings.asset."); + var material = AssetDatabase.LoadAssetAtPath("Assets/Materials/Brushes/Gravity Field.mat") + ?? throw new InvalidOperationException("No Gravity Field.mat."); + + var zone = BuildZone(settings, work, out var bodies); + GravityLowering.Lower(zone, ref wells); + field = GravityLowering.CreateField(material); + + var sun = Core(zone, 14152f); + var planetoid = Core(zone, 29.2f); + CheckTexels("planetoid", zone, bodies[2], 4f * planetoid); + CheckTexels("sun", zone, bodies[0], 4f * sun); + CheckTexels("zone", zone, new Vector2(0f, 0f), 1.05f * zone.Pack.Radius); + CheckGradient(zone, bodies); + Debug.Log($"{Tag} max error {_maxError:G4} u (tolerance {Tolerance:G4}); max gradient angle {_maxAngle:F2} degrees (limit {GradientDegrees:F0})"); + + CheckWiring(settings); + Debug.Log(_ok ? $"{Tag} PASS" : $"{Tag} FAIL: see errors above"); + } + catch (Exception e) + { + Debug.LogError($"{Tag} FAIL exception: {e}"); + _ok = false; + } + finally + { + Application.logMessageReceived -= OnLog; + if (field != null) UnityEngine.Object.DestroyImmediate(field); + wells?.Release(); + try { Directory.Delete(work, true); } catch { } + } + EditorApplication.Exit(_ok ? 0 : 1); + } + + static float Core(Zone zone, float mass) => zone.Settings.CoreRadius.Evaluate(mass); + + // A sun (14152 at the origin), a planet (273.9 at 610) and a planetoid (29.2 at 670): parentless, fixed, so the + // zone's wells sit where the verify says before any Update. + static Zone BuildZone(GameSettings settings, string work, out Vector2[] positions) + { + var cache = AetheriaStores.Open(Path.Combine(work, "catalog.cc"), Path.Combine(work, "run.cc"), catalogWritable: true); + cache.Upsert(new VerseGrammar { Revision = 1 }); + cache.FlushAsync().Wait(); + var items = new ItemManager(cache, new ProvenanceLedger(), settings.GameplaySettings, _ => { }); + positions = new[] { new Vector2(0f, 0f), new Vector2(610f, 0f), new Vector2(670f, 0f) }; + var masses = new[] { 14152f, 273.9f, 29.2f }; + var pack = new ZonePack { Radius = 4182f }; + for (var i = 0; i < positions.Length; i++) + { + var orbit = cache.Upsert(new OrbitData { FixedPosition = new float2(positions[i].x, positions[i].y) }).Key; + var body = cache.Upsert(new PlanetData + { Name = "Body " + i, Orbit = new CultRecordRef(orbit), Mass = masses[i] }).Key; + pack.Orbits.Add(new CultRecordRef(orbit)); + pack.Planets.Add(new CultRecordRef(body)); + } + return new Zone(items, settings.PlanetSettings, pack, new GalaxyZone { Name = "Gravity Parity", Owner = null }, null); + } + + // Renders the field through a downward orthographic camera that culls layer 9 only, centred on `centre` with + // half-size `half`, and returns the depth of every texel with the world xz of the texel's centre, which is asked + // of the camera rather than assumed. + static void Render(Vector2 centre, float half, out float[] depth, out Vector2[] world) + { + var rt = new RenderTexture(Size, Size, 0, RenderTextureFormat.RFloat) { filterMode = FilterMode.Point }; + var cameraObject = new GameObject("Gravity Parity Camera"); + var read = new Texture2D(Size, Size, TextureFormat.RFloat, false); + var previous = RenderTexture.active; + try + { + var camera = cameraObject.AddComponent(); + camera.orthographic = true; + camera.orthographicSize = half; + camera.aspect = 1f; + camera.nearClipPlane = .3f; + camera.farClipPlane = 1000f; + camera.cullingMask = 1 << GravityLowering.FieldLayer; + camera.clearFlags = CameraClearFlags.SolidColor; + camera.backgroundColor = Color.black; + camera.allowHDR = false; + camera.allowMSAA = false; + camera.targetTexture = rt; + cameraObject.transform.SetPositionAndRotation(new Vector3(centre.x, 100f, centre.y), Quaternion.Euler(90f, 0f, 0f)); + camera.Render(); + + RenderTexture.active = rt; + read.ReadPixels(new Rect(0, 0, Size, Size), 0, 0); + read.Apply(); + depth = read.GetPixelData(0).ToArray(); + world = new Vector2[Size * Size]; + for (var y = 0; y < Size; y++) + for (var x = 0; x < Size; x++) + { + var p = camera.ViewportToWorldPoint(new Vector3((x + .5f) / Size, (y + .5f) / Size, 100f)); + world[y * Size + x] = new Vector2(p.x, p.z); + } + } + finally + { + RenderTexture.active = previous; + UnityEngine.Object.DestroyImmediate(cameraObject); + UnityEngine.Object.DestroyImmediate(read); + rt.Release(); + UnityEngine.Object.DestroyImmediate(rt); + } + } + + static void CheckTexels(string window, Zone zone, Vector2 centre, float half) + { + Render(centre, half, out var depth, out var world); + var worst = 0f; + var live = 0; + for (var i = 0; i < depth.Length; i++) + { + var expected = -zone.GetHeight(new float2(world[i].x, world[i].y)); + if (float.IsNaN(depth[i])) { Fail($"{window}-texels", $"texel {i}: NaN"); return; } + var error = Math.Abs(depth[i] - expected); + worst = Math.Max(worst, error); + if (Math.Abs(expected) > 1f) live++; + if (error > Tolerance) + { + Fail($"{window}-texels", $"texel {i} at ({world[i].x:F2}, {world[i].y:F2}): expected {expected:G6}, drawn {depth[i]:G6}, error {error:G4} > {Tolerance:G4}"); + return; + } + } + _maxError = Math.Max(_maxError, worst); + // A window that draws nothing agrees with a zone that is flat: the check must be live. + if (live < depth.Length / 2) Fail($"{window}-texels", $"only {live} of {depth.Length} texels are deeper than 1 u; the check is vacuous"); + Debug.Log($"{Tag} {window}: {depth.Length} texels, max error {worst:G4} u"); + } + + // The texture's central difference (over two 4 u texels, mid-zone) points where GetForce does: depth = -h, so its + // gradient is the force over the exaggeration. This is what the slope readers (the shader's slopeFlow, the nebula + // surface normal, the drawn grid) take from the texture. + static void CheckGradient(Zone zone, Vector2[] bodies) + { + Render(new Vector2(1500f, 0f), 512f, out var depth, out var world); + var compared = 0; + for (var y = 1; y < Size - 1; y++) + for (var x = 1; x < Size - 1; x++) + { + var here = world[y * Size + x]; + if (bodies.Any(b => (b - here).magnitude < 16f)) continue; + // The world step of each texel axis is read from the camera, so a flipped or rotated target is still measured. + var au = world[y * Size + x + 1] - world[y * Size + x - 1]; + var av = world[(y + 1) * Size + x] - world[(y - 1) * Size + x]; + var du = depth[y * Size + x + 1] - depth[y * Size + x - 1]; + var dv = depth[(y + 1) * Size + x] - depth[(y - 1) * Size + x]; + var det = au.x * av.y - au.y * av.x; + var g = new Vector2((du * av.y - dv * au.y) / det, (dv * au.x - du * av.x) / det); + var f = zone.GetForce(new float2(here.x, here.y)); + var angle = Vector2.Angle(g, new Vector2(f.x, f.y)); + if (float.IsNaN(angle) || angle > GradientDegrees) + { + Fail("gradient", $"at ({here.x:F1}, {here.y:F1}) the drawn slope points {angle:F2} degrees from the force (limit {GradientDegrees:F0})"); + return; + } + _maxAngle = Math.Max(_maxAngle, angle); + compared++; + } + if (compared < Size * Size / 2) Fail("gradient", $"only {compared} texels were compared"); + } + + static void CheckWiring(GameSettings settings) + { + var scene = EditorSceneManager.OpenScene("Assets/Scenes/ARPG.unity", OpenSceneMode.Single); + try + { + var gravityTargets = new[] { "Fog Surface Displacement", "Slime Gravity", "MinimapGravity" }; + var seen = 0; + foreach (var camera in UnityEngine.Object.FindObjectsByType(FindObjectsInactive.Include, FindObjectsSortMode.None)) + { + if (camera.targetTexture == null || !gravityTargets.Contains(camera.targetTexture.name)) continue; + seen++; + if (camera.cullingMask != 1 << GravityLowering.FieldLayer) + Fail("wiring", $"camera {camera.name} (target {camera.targetTexture.name}) culls mask {camera.cullingMask}, not layer {GravityLowering.FieldLayer} alone"); + } + if (seen < gravityTargets.Length) Fail("wiring", $"only {seen} gravity cameras found in ARPG.unity"); + + var renderer = UnityEngine.Object.FindFirstObjectByType(FindObjectsInactive.Include); + if (renderer == null) Fail("wiring", "no ZoneRenderer in ARPG.unity"); + else if (renderer.GravityField == null || renderer.GravityField.shader.name != "Brushes/Gravity Field") + Fail("wiring", "ZoneRenderer.GravityField is not a Brushes/Gravity Field material"); + + foreach (var r in UnityEngine.Object.FindObjectsByType(FindObjectsInactive.Include, FindObjectsSortMode.None)) + if (r.gameObject.layer == GravityLowering.FieldLayer) + Fail("wiring", $"renderer {r.name} in ARPG.unity sits on layer {GravityLowering.FieldLayer}"); + } + finally + { + EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); + } + + foreach (var path in new[] + { + "Assets/Prefabs/RPG/Planets/Planet.prefab", "Assets/Prefabs/RPG/Planets/Gas Giant.prefab", + "Assets/Prefabs/RPG/Planets/Sun.prefab", "Assets/Prefabs/RPG/Wormhole 1.prefab" + }) + { + var prefab = AssetDatabase.LoadAssetAtPath(path); + if (prefab == null) { Fail("wiring", $"no prefab at {path}"); continue; } + foreach (var r in prefab.GetComponentsInChildren(true)) + if (r.gameObject.layer == GravityLowering.FieldLayer) + Fail("wiring", $"renderer {r.name} in {path} sits on layer {GravityLowering.FieldLayer}"); + } + } + } +} diff --git a/Assets/Scripts/Editor/GravityFieldParityVerify.cs.meta b/Assets/Scripts/Editor/GravityFieldParityVerify.cs.meta new file mode 100644 index 000000000..50646bcbb --- /dev/null +++ b/Assets/Scripts/Editor/GravityFieldParityVerify.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1ceb2bdab0804463b1998471d47e82fa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/ServerShared/Settings.cs b/Assets/Scripts/ServerShared/Settings.cs index a0fa7c7d9..6fcdd8f61 100644 --- a/Assets/Scripts/ServerShared/Settings.cs +++ b/Assets/Scripts/ServerShared/Settings.cs @@ -13,8 +13,6 @@ using static CultMath.math; [Serializable, MessagePackObject(keyAsPropertyName:true), JsonObject] public class PlanetSettings { - public ExponentialCurve GravityDepth; - public ExponentialCurve GravityRadius; public ExponentialCurve LightRadius; public ExponentialCurve BodyRadius; diff --git a/Assets/Scripts/ServerShared/Zone.cs b/Assets/Scripts/ServerShared/Zone.cs index cd0449545..ccec8edfd 100644 --- a/Assets/Scripts/ServerShared/Zone.cs +++ b/Assets/Scripts/ServerShared/Zone.cs @@ -612,14 +612,17 @@ public class Zone return security; } + // The potential of a body's well at the zone's edge, subtracted so every well is zero there: the one owner of the + // reference. GetHeight sums with it and the renderer's lowering (GravityLowering) hands it to the shader unchanged. + public float WellReference(Planet body) => GravityField.Potential(body.WellStrength, body.CoreRadius, Pack.Radius); + public float GetHeight(float2 position) { var result = 0f; foreach (var body in PlanetInstances.Values) { var offset = position - body.Orbit.Position; - result += GravityField.Potential(body.WellStrength, body.CoreRadius, length(offset)) - - GravityField.Potential(body.WellStrength, body.CoreRadius, Pack.Radius); + result += GravityField.Potential(body.WellStrength, body.CoreRadius, length(offset)) - WellReference(body); } return result / Settings.HeightExaggeration; @@ -685,9 +688,6 @@ public class Planet public Orbit Orbit; protected readonly PlanetSettings Settings; public BodyData BodyData; - // Brush inputs only (ZoneRenderer's Gravity Well brushes and planet icon); no sim reader. grid-lowering deletes them. - public float GravityWellDepth; - public float GravityWellRadius; public float BodyRadius; // The well (GravityField): strength c and softened core radius R by mass, and the Roche limit, the closest a child @@ -707,8 +707,6 @@ public class Planet public void CalculateProperties() { BodyRadius = Settings.BodyRadius.Evaluate(BodyData.Mass) * BodyData.BodyRadiusMultiplier; - GravityWellRadius = Settings.GravityRadius.Evaluate(BodyData.Mass) * BodyData.GravityRadiusMultiplier; - GravityWellDepth = Settings.GravityDepth.Evaluate(BodyData.Mass) * BodyData.GravityDepthMultiplier; WellStrength = Settings.WellStrength.Evaluate(BodyData.Mass); CoreRadius = Settings.CoreRadius.Evaluate(BodyData.Mass); RocheLimit = Settings.RocheLimit.Evaluate(BodyData.Mass); diff --git a/Assets/Scripts/ServerShared/ZoneData.cs b/Assets/Scripts/ServerShared/ZoneData.cs index a609db234..dd098862f 100644 --- a/Assets/Scripts/ServerShared/ZoneData.cs +++ b/Assets/Scripts/ServerShared/ZoneData.cs @@ -86,12 +86,6 @@ public abstract class BodyData [JsonProperty("bodyRadiusMul")] [Key(5)] public float BodyRadiusMultiplier = 1; - - [JsonProperty("gravRadiusMul")] [Key(6)] - public float GravityRadiusMultiplier = 1; - - [JsonProperty("depthMul")] [Key(7)] - public float GravityDepthMultiplier = 1; } [CultDocument("aetheria.planetdata", "1"), MessagePackObject, JsonObject(MemberSerialization.OptIn)] diff --git a/Assets/Scripts/Zone Display/GravityLowering.cs b/Assets/Scripts/Zone Display/GravityLowering.cs new file mode 100644 index 000000000..c8d33cc7b --- /dev/null +++ b/Assets/Scripts/Zone Display/GravityLowering.cs @@ -0,0 +1,78 @@ +using System.Runtime.InteropServices; +using UnityEngine; + +/// +/// The renderer's lowering of the zone's potential (aetheria-gravity, cut grid-lowering). Zone.GetHeight owns the drawn +/// height: this hands its inputs (each well's position, strength, core radius and reference, and the exaggeration) to +/// Assets/Shaders/Gravity.cginc, which sums them per texel, and makes the one quad that carries the sum into every +/// camera that culls layer 9. Nothing here decides a height. +/// +public static class GravityLowering +{ + /// The layer the gravity cameras cull; nothing but the run-time field sits on it. + public const int FieldLayer = 9; + /// The quad's side in u: larger than any zone (10000) plus any view (4096); texels outside a camera cost nothing. + public const float FieldExtent = 100000f; + + // Mirrors Gravity.cginc's GravityWell: float2 position, strength, coreRadius, reference. + [StructLayout(LayoutKind.Sequential)] + struct WellRecord + { + public Vector2 Position; + public float Strength; + public float CoreRadius; + public float Reference; + } + + static readonly int Stride = Marshal.SizeOf(); + static readonly int WellsId = Shader.PropertyToID("_GravityWells"); + static readonly int CountId = Shader.PropertyToID("_GravityWellCount"); + static readonly int ExaggerationId = Shader.PropertyToID("_HeightExaggeration"); + static WellRecord[] _records = new WellRecord[0]; + + /// + /// Fills one record per body of the zone (a null zone has none) and sets the shader globals. The buffer is the + /// caller's, (re)allocated to the body count (at least one, so the global is always bound). + /// + public static void Lower(Zone zone, ref ComputeBuffer wells) + { + var count = zone?.PlanetInstances.Count ?? 0; + var capacity = Mathf.Max(count, 1); + if (wells == null || wells.count != capacity) + { + wells?.Release(); + wells = new ComputeBuffer(capacity, Stride); + } + + if (_records.Length != capacity) _records = new WellRecord[capacity]; + var i = 0; + if (zone != null) + foreach (var body in zone.PlanetInstances.Values) + _records[i++] = new WellRecord + { + Position = new Vector2(body.Orbit.Position.x, body.Orbit.Position.y), + Strength = body.WellStrength, + CoreRadius = body.CoreRadius, + Reference = zone.WellReference(body) + }; + wells.SetData(_records); + + Shader.SetGlobalBuffer(WellsId, wells); + Shader.SetGlobalInt(CountId, count); + Shader.SetGlobalFloat(ExaggerationId, zone?.Settings.HeightExaggeration ?? 1f); + } + + /// The one quad of the field: flat in xz at y 0 on layer 9, drawn with the Gravity Field material. + public static GameObject CreateField(Material material) + { + var field = new GameObject("Gravity Field") { layer = FieldLayer }; + field.transform.rotation = Quaternion.Euler(90f, 0f, 0f); + field.transform.localScale = FieldExtent * Vector3.one; + field.AddComponent().sharedMesh = Resources.GetBuiltinResource("Quad.fbx"); + var renderer = field.AddComponent(); + renderer.sharedMaterial = material; + renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; + renderer.receiveShadows = false; + return field; + } +} diff --git a/Assets/Scripts/Zone Display/GravityLowering.cs.meta b/Assets/Scripts/Zone Display/GravityLowering.cs.meta new file mode 100644 index 000000000..725a49896 --- /dev/null +++ b/Assets/Scripts/Zone Display/GravityLowering.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1a5e08474b514e509ed1477b3ac06e94 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Zone Display/PlanetObject.cs b/Assets/Scripts/Zone Display/PlanetObject.cs index 9e4a80358..21b49262f 100644 --- a/Assets/Scripts/Zone Display/PlanetObject.cs +++ b/Assets/Scripts/Zone Display/PlanetObject.cs @@ -9,7 +9,6 @@ using UnityEngine; public class PlanetObject : MonoBehaviour { public MeshRenderer Body; - public MeshRenderer GravityWell; public MeshRenderer Icon; public CelestialBodyGenerator Generator; } diff --git a/Assets/Scripts/Zone Display/ZoneRenderer.cs b/Assets/Scripts/Zone Display/ZoneRenderer.cs index 907134dbc..4c63ed7b8 100644 --- a/Assets/Scripts/Zone Display/ZoneRenderer.cs +++ b/Assets/Scripts/Zone Display/ZoneRenderer.cs @@ -46,6 +46,8 @@ public class ZoneRenderer : MonoBehaviour public MineInstance MinePrefab; public VapourCloudInstance CloudPrefab; public Material[] MapGravityMaterials; + // The gravity field's material (Brushes/Gravity Field): GravityLowering makes the one quad that draws it. + public Material GravityField; [Header("Tour")] public bool Tour; public float TourSwitchTime = 5f; @@ -77,7 +79,8 @@ public class ZoneRenderer : MonoBehaviour // is stored on AsteroidBelt any more. private Dictionary _beltTransforms = new Dictionary(); private float _viewDistance; - //private float _maxDepth; + private GameObject _gravityField; + private ComputeBuffer _gravityWells; private float _minimapDistance; private int _tourIndex = -1; @@ -195,6 +198,7 @@ public class ZoneRenderer : MonoBehaviour SectorBrushes.localScale = zone.Pack.Radius * 2 * Vector3.one; SlimeGravityCamera.orthographicSize = zone.Pack.Radius; SlimeRenderer.ZoneRadius = zone.Pack.Radius; + if (_gravityField == null) _gravityField = GravityLowering.CreateField(GravityField); foreach (var p in zone.Planets) LoadPlanet(p.Key, p.Value); @@ -321,9 +325,17 @@ public class ZoneRenderer : MonoBehaviour WormholeInstances.Add(wormhole, (instance.gameObject, icon)); } + void OnDestroy() + { + _gravityWells?.Release(); + _gravityWells = null; + } + public void ClearZone() { if (Zone == null) return; + _gravityWells?.Release(); + _gravityWells = null; foreach (var wormhole in WormholeInstances.Values) { Destroy(wormhole.gravity); @@ -491,11 +503,6 @@ public class ZoneRenderer : MonoBehaviour var planetInstance = Zone.PlanetInstances[key]; planet.Body.transform.localScale = planetInstance.BodyRadius * Vector3.one; - planet.GravityWell.transform.localScale = planetInstance.GravityWellRadius * Vector3.one; - // var depth = planetInstance.GravityWellDepth; - // if (depth > _maxDepth) _maxDepth = depth; - planet.GravityWell.material.SetFloat("_Depth", planetInstance.GravityWellDepth); - planet.Icon.transform.position = new Vector3(0, -planetInstance.GravityWellDepth, 0); planet.Icon.transform.localScale = Settings.IconSize.Evaluate(planetInstance.BodyData.Mass) * Vector3.one; @@ -513,6 +520,7 @@ public class ZoneRenderer : MonoBehaviour void Update() { var maxDepth = 0f; + GravityLowering.Lower(Zone, ref _gravityWells); foreach (var loot in _floatingItems.Values) { loot.ViewOrigin = PerspectiveEntity.Position; @@ -576,6 +584,7 @@ public class ZoneRenderer : MonoBehaviour if (-height > maxDepth) maxDepth = -height; planet.Value.transform.position = new Vector3(p.x, 0, p.y); planet.Value.Body.transform.localPosition = new Vector3(0, height + planetInstance.BodyRadius * 2, 0); + planet.Value.Icon.transform.localPosition = new Vector3(0, height, 0); if (planet.Value is GasGiantObject gasGiantObject) { if (!(planet.Value is SunObject)) diff --git a/Assets/Shaders/Brushes/GravityField.shader b/Assets/Shaders/Brushes/GravityField.shader new file mode 100644 index 000000000..b3987aab1 --- /dev/null +++ b/Assets/Shaders/Brushes/GravityField.shader @@ -0,0 +1,47 @@ +// Draws the zone's gravity: depth = -Zone.GetHeight at the world xz of every texel, into whichever gravity camera culls +// layer 9 (Surface Displacement, Patch Displacement, Slime Gravity, both Map Gravity). One quad covers the zone; the +// law lives in Gravity.cginc, which mirrors ServerShared's GravityField. +Shader "Brushes/Gravity Field" { +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" } + Blend One One + ColorMask RGB + Cull Off Lighting Off ZWrite Off + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 4.5 + + #include "UnityCG.cginc" + #include "../Gravity.cginc" + + struct appdata_t { + float4 vertex : POSITION; + }; + + struct v2f { + float4 vertex : SV_POSITION; + float2 world : TEXCOORD0; + }; + + v2f vert (appdata_t v) + { + v2f o; + o.vertex = UnityObjectToClipPos(v.vertex); + o.world = mul(unity_ObjectToWorld, v.vertex).xz; + return o; + } + + float4 frag (v2f i) : SV_Target + { + return (-gravityHeight(i.world)).xxxx; + } + ENDCG + } + } +} +} diff --git a/Assets/Shaders/Brushes/RadialWaveBrush.shader.meta b/Assets/Shaders/Brushes/GravityField.shader.meta similarity index 80% rename from Assets/Shaders/Brushes/RadialWaveBrush.shader.meta rename to Assets/Shaders/Brushes/GravityField.shader.meta index 14b474d83..f98548391 100644 --- a/Assets/Shaders/Brushes/RadialWaveBrush.shader.meta +++ b/Assets/Shaders/Brushes/GravityField.shader.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8a8e593b17063b54ea02f7ea5363b59d +guid: 08d8efa80af84065b54c9bfed784e435 ShaderImporter: externalObjects: {} defaultTextures: [] diff --git a/Assets/Shaders/Brushes/RadialWaveBrush.shader b/Assets/Shaders/Brushes/RadialWaveBrush.shader deleted file mode 100644 index 1828873bc..000000000 --- a/Assets/Shaders/Brushes/RadialWaveBrush.shader +++ /dev/null @@ -1,81 +0,0 @@ -Shader "Brushes/Radial Wave Brush" { -Properties { - _Depth ("Depth", Float) = 0.5 - _Power("Envelope Power", Float) = 1.25 - _Frequency("Frequency", Float) = 6.2832 - _Phase("Phase", Float) = 0 - _SinePower("Sine Power", Float) = 1.25 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" } - Blend One One - ColorMask RGB - Cull Off Lighting Off ZWrite Off - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 2.0 - - #include "UnityCG.cginc" - - float _Depth; - float _Power; - float _Frequency; - float _Phase; - float _SinePower; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - }; - - struct v2f { - float4 vertex : SV_POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - }; - - float4 _MainTex_ST; - - v2f vert (appdata_t v) - { - v2f o; - o.vertex = UnityObjectToClipPos(v.vertex); - o.color = v.color; - o.texcoord = v.texcoord; - return o; - } - - float almostIdentity(float x, float m, float n) - { - if (x>m) return x; - - const float a = 2.0f*n - m; - const float b = 2.0f*m - 3.0f*n; - const float t = x / m; - - return (a*t + b)*t*t + n; - } - - float powerPulse( float x, float power ) - { - x = saturate(abs(x)); - return pow((x + 1.0f) * (1.0f - x), power); - } - - fixed4 frag (v2f i) : SV_Target - { - float dist = length(i.texcoord - float2(.5,.5)) * 2; - return _Depth * powerPulse(dist,_Power) * cos(pow(dist, _SinePower)*_Frequency+_Phase); - } - ENDCG - } - } -} -} diff --git a/Assets/Shaders/Brushes/WormholeBrush.shader b/Assets/Shaders/Brushes/WormholeBrush.shader deleted file mode 100644 index 6d2c8a0ed..000000000 --- a/Assets/Shaders/Brushes/WormholeBrush.shader +++ /dev/null @@ -1,85 +0,0 @@ -Shader "Brushes/Wormhole Brush" { -Properties { - _Depth ("Depth", Float) = 0.5 - _Power("Envelope Power", Float) = 1.25 - _Frequency("Frequency", Float) = 6.2832 - _FrequencyDist("Distance Frequency", Float) = 6.2832 - _Speed("Speed", Float) = 0 - _SinePower("Sine Power", Float) = 1.25 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" } - Blend One One - ColorMask RGB - Cull Off Lighting Off ZWrite Off - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 2.0 - - #include "UnityCG.cginc" - - float _Depth; - float _Power; - float _Frequency; - float _FrequencyDist; - float _Speed; - float _SinePower; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - }; - - struct v2f { - float4 vertex : SV_POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - }; - - float4 _MainTex_ST; - - v2f vert (appdata_t v) - { - v2f o; - o.vertex = UnityObjectToClipPos(v.vertex); - o.color = v.color; - o.texcoord = v.texcoord; - return o; - } - - float almostIdentity(float x, float m, float n) - { - if (x>m) return x; - - const float a = 2.0f*n - m; - const float b = 2.0f*m - 3.0f*n; - const float t = x / m; - - return (a*t + b)*t*t + n; - } - - float powerPulse( float x, float power ) - { - x = saturate(abs(x)); - return pow((x + 1.0f) * (1.0f - x), power); - } - - fixed4 frag (v2f i) : SV_Target - { - float2 uv2 = i.texcoord - float2(.5,.5); - float dist = length(uv2); - float ang = atan2(uv2.y,uv2.x); - return _Depth * powerPulse(dist * 2,_Power) * (cos(ang*_Frequency+pow(dist, _SinePower)*_FrequencyDist+_Time.x*_Speed)+1); - } - ENDCG - } - } -} -} diff --git a/Assets/Shaders/Gravity.cginc b/Assets/Shaders/Gravity.cginc new file mode 100644 index 000000000..8cc256d94 --- /dev/null +++ b/Assets/Shaders/Gravity.cginc @@ -0,0 +1,42 @@ +#ifndef AETHERIA_GRAVITY_INCLUDED +#define AETHERIA_GRAVITY_INCLUDED + +// The lowering of the zone's potential (aetheria-gravity, cut grid-lowering). The law is ServerShared's GravityField +// and the height is Zone.GetHeight; this file mirrors them and decides nothing. GravityLowering.Lower fills the +// buffer and the globals from the zone (positions from Orbit.Position, reference from Zone.WellReference) each frame. +// GravityFieldParityVerify renders it and compares every texel with -Zone.GetHeight. + +struct GravityWell +{ + float2 position; + float strength; + float coreRadius; + float reference; +}; + +StructuredBuffer _GravityWells; +int _GravityWellCount; +float _HeightExaggeration; + +// GravityField.Potential, line for line: c is the well's strength, R its core radius, r the distance. +float gravityPotential(float c, float R, float r) +{ + return c == 0 ? 0 : + r < R + ? c * r * r / (2 * R * R) + : c * (log(r / R) + .5); +} + +// Zone.GetHeight at world xz: each well's potential minus its own reference, summed, divided by the exaggeration. +float gravityHeight(float2 p) +{ + float result = 0; + for (int i = 0; i < _GravityWellCount; i++) + { + GravityWell well = _GravityWells[i]; + result += gravityPotential(well.strength, well.coreRadius, length(p - well.position)) - well.reference; + } + return result / _HeightExaggeration; +} + +#endif diff --git a/Assets/Shaders/Brushes/WormholeBrush.shader.meta b/Assets/Shaders/Gravity.cginc.meta similarity index 71% rename from Assets/Shaders/Brushes/WormholeBrush.shader.meta rename to Assets/Shaders/Gravity.cginc.meta index 6bccf4a95..61a1a4c96 100644 --- a/Assets/Shaders/Brushes/WormholeBrush.shader.meta +++ b/Assets/Shaders/Gravity.cginc.meta @@ -1,10 +1,9 @@ fileFormatVersion: 2 -guid: 8681ac064d59d15458d16cc9b884262c +guid: b8f69df89fde433c8263115c25267a10 ShaderImporter: externalObjects: {} defaultTextures: [] nonModifiableTextures: [] - preprocessorOverride: 0 userData: assetBundleName: assetBundleVariant: diff --git a/tests/Aetheria.Shared.Tests/GravitySubtractTests.cs b/tests/Aetheria.Shared.Tests/GravitySubtractTests.cs index 696b491df..078de12f2 100644 --- a/tests/Aetheria.Shared.Tests/GravitySubtractTests.cs +++ b/tests/Aetheria.Shared.Tests/GravitySubtractTests.cs @@ -46,8 +46,6 @@ public sealed class GravitySubtractTests : IDisposable CoreRadius = new ExponentialCurve { Exponent = .25f, Multiplier = 3f }, RocheLimit = new ExponentialCurve { Exponent = .25f, Multiplier = 7.32f }, BodyRadius = new ExponentialCurve { Exponent = .25f, Multiplier = 3f }, - GravityRadius = new ExponentialCurve { Exponent = .25f, Multiplier = 500f }, - GravityDepth = new ExponentialCurve { Exponent = .175f, Multiplier = 30f }, LightRadius = new ExponentialCurve { Exponent = .25f, Multiplier = 300f }, OrbitPeriod = new ExponentialCurve() }; @@ -81,8 +79,6 @@ public sealed class GravitySubtractTests : IDisposable var orbit = _cache.Upsert(new OrbitData { FixedPosition = float2.zero }).Key; data.Orbit = new CultRecordRef(orbit); data.Mass = 100f; - data.GravityRadiusMultiplier = 1.5f; - data.GravityDepthMultiplier = .7f; var body = _cache.Upsert(data).Key; var pack = new ZonePack { Radius = PackRadius }; pack.Orbits.Add(new CultRecordRef(orbit)); @@ -133,9 +129,9 @@ public sealed class GravitySubtractTests : IDisposable private float _clock; private const float PackRadius = 1000f; - // CultCache has no primitive for reserving a removed MessagePack key. Key 8 of a body record (its former well - // exponent) and the wave keys of the gas giants (14-17) must not come back with a different meaning, because - // stored records may still carry them. Every record type that is a BodyData is checked, bases walked, so a giant + // CultCache has no primitive for reserving a removed MessagePack key. Keys 6 and 7 of a body record (its former + // brush multipliers), key 8 (its former well exponent) and the wave keys of the gas giants (14-17) must not come back + // with a different meaning, because stored records may still carry them. Every record type that is a BodyData is checked, bases walked, so a giant // kind added later (the sun is one) cannot take them. [Fact] public void ABodyRecordNeverReusesRetiredKeys() @@ -157,7 +153,7 @@ public sealed class GravitySubtractTests : IDisposable { var keys = KeysOf(type); Assert.NotEmpty(keys); - Assert.DoesNotContain(8, keys); + foreach (var retired in new[] { 6, 7, 8 }) Assert.DoesNotContain(retired, keys); if (typeof(GasGiantData).IsAssignableFrom(type)) foreach (var retired in new[] { 14, 15, 16, 17 }) Assert.DoesNotContain(retired, keys); } diff --git a/tests/Aetheria.Shared.Tests/MiningCut2Tests.cs b/tests/Aetheria.Shared.Tests/MiningCut2Tests.cs index 647406669..5ac5ecac8 100644 --- a/tests/Aetheria.Shared.Tests/MiningCut2Tests.cs +++ b/tests/Aetheria.Shared.Tests/MiningCut2Tests.cs @@ -44,10 +44,8 @@ public sealed class MiningCut2Tests : IDisposable AsteroidSize = new ExponentialLerp { Minimum = 2f, Maximum = 9f, Exponent = 1.7f }, AsteroidHitpoints = new ExponentialLerp { Minimum = 20f, Maximum = 220f, Exponent = 1.6f }, AsteroidRespawnTime = new ExponentialLerp { Minimum = 8f, Maximum = 96f, Exponent = 1.2f }, - // The zone builds a Planet for the fixture's non-belt body; its constructor reads these three. - BodyRadius = new ExponentialCurve(), - GravityRadius = new ExponentialCurve(), - GravityDepth = new ExponentialCurve() + // The zone builds a Planet for the fixture's non-belt body; its constructor reads this. + BodyRadius = new ExponentialCurve() }; private sealed class Fixture diff --git a/tests/Aetheria.Shared.Tests/MiningCut3Tests.cs b/tests/Aetheria.Shared.Tests/MiningCut3Tests.cs index 273b63547..a9146613a 100644 --- a/tests/Aetheria.Shared.Tests/MiningCut3Tests.cs +++ b/tests/Aetheria.Shared.Tests/MiningCut3Tests.cs @@ -56,8 +56,6 @@ public sealed partial class MiningCut3Tests : IDisposable AsteroidHitpoints = new ExponentialLerp { Minimum = 20f, Maximum = 220f, Exponent = 1.6f }, AsteroidRespawnTime = new ExponentialLerp { Minimum = 8f, Maximum = 96f, Exponent = 1.2f }, BodyRadius = new ExponentialCurve(), - GravityRadius = new ExponentialCurve(), - GravityDepth = new ExponentialCurve(), LightRadius = new ExponentialCurve { Constant = lightRadius } }; diff --git a/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs b/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs index aa6aa626a..cd473b331 100644 --- a/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs +++ b/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs @@ -47,7 +47,6 @@ public sealed class PotentialOwnerTests : IDisposable CoreRadius = new ExponentialCurve { Exponent = .25f, Multiplier = 3f }, RocheLimit = new ExponentialCurve { Exponent = .25f, Multiplier = 7.32f }, BodyRadius = new ExponentialCurve { Exponent = .25f, Multiplier = 2f }, - GravityRadius = new ExponentialCurve(), GravityDepth = new ExponentialCurve(), LightRadius = new ExponentialCurve(), OrbitPeriod = new ExponentialCurve(), HeightExaggeration = exaggeration }; @@ -84,7 +83,7 @@ public sealed class PotentialOwnerTests : IDisposable { var planets = new PlanetSettings { - BodyRadius = new ExponentialCurve(), GravityRadius = new ExponentialCurve(), GravityDepth = new ExponentialCurve(), + BodyRadius = new ExponentialCurve(), LightRadius = new ExponentialCurve(), OrbitPeriod = new ExponentialCurve() }; var zone = ZoneOf(planets, (100f, float2.zero), (5000f, new float2(200f, 0f))); @@ -139,7 +138,6 @@ public sealed class PotentialOwnerTests : IDisposable CoreRadius = new ExponentialCurve { Constant = core }, RocheLimit = new ExponentialCurve { Constant = roche }, BodyRadius = new ExponentialCurve { Constant = 10f }, - GravityRadius = new ExponentialCurve(), GravityDepth = new ExponentialCurve(), LightRadius = new ExponentialCurve(), OrbitPeriod = new ExponentialCurve() }; Assert.Throws(() => ZoneOf(Constants(60f, 50f), (100f, float2.zero))); @@ -161,7 +159,6 @@ public sealed class PotentialOwnerTests : IDisposable CoreRadius = new ExponentialCurve { Multiplier = coreMultiplier, Exponent = coreExponent }, RocheLimit = new ExponentialCurve { Multiplier = rocheMultiplier, Exponent = rocheExponent }, BodyRadius = new ExponentialCurve { Constant = 1f }, - GravityRadius = new ExponentialCurve(), GravityDepth = new ExponentialCurve(), LightRadius = new ExponentialCurve(), OrbitPeriod = new ExponentialCurve() }; var threw = 0; @@ -212,12 +209,12 @@ public sealed class PotentialOwnerTests : IDisposable } // The well is authored once, by curves of mass (target: no per-body authoring of a core or Roche limit): a body whose - // record carries other radius, gravity-radius or gravity-depth multipliers has the same strength, core and Roche limit, - // and pulls and digs exactly as its plain twin. The multipliers are brush inputs for the renderer, nothing else. + // record carries another radius multiplier has the same strength, core and Roche limit, and pulls and digs exactly as + // its plain twin. [Theory] - [InlineData(2.5f, 3f, .4f)] - [InlineData(.5f, .5f, 3f)] - public void PerBodyMultipliersDoNotMoveTheWell(float bodyRadius, float gravityRadius, float gravityDepth) + [InlineData(2.5f)] + [InlineData(.5f)] + public void PerBodyMultipliersDoNotMoveTheWell(float bodyRadius) { var planets = Curves(); foreach (var mass in new[] { 29.2f, 14152.4f }) @@ -226,8 +223,6 @@ public sealed class PotentialOwnerTests : IDisposable var scaled = ZoneOf(planets, data => { data.BodyRadiusMultiplier = bodyRadius; - data.GravityRadiusMultiplier = gravityRadius; - data.GravityDepthMultiplier = gravityDepth; }, (mass, float2.zero)); var a = plain.PlanetInstances.Values.Single(); var b = scaled.PlanetInstances.Values.Single(); diff --git a/tests/Aetheria.Shared.Tests/WellFixture.cs b/tests/Aetheria.Shared.Tests/WellFixture.cs index e732172d9..0b895e4c0 100644 --- a/tests/Aetheria.Shared.Tests/WellFixture.cs +++ b/tests/Aetheria.Shared.Tests/WellFixture.cs @@ -10,8 +10,6 @@ internal static class WellFixture public static void Dig(CultCache cache, ZonePack pack, PlanetSettings settings, float strength, float coreRadius, float2 at = default) { settings.BodyRadius = new ExponentialCurve(); - settings.GravityRadius = new ExponentialCurve(); // brush inputs, read by Planet until grid-lowering deletes them - settings.GravityDepth = new ExponentialCurve(); settings.OrbitPeriod = new ExponentialCurve(); settings.WellStrength = new ExponentialCurve { Constant = strength }; settings.CoreRadius = new ExponentialCurve { Constant = coreRadius }; diff --git a/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs b/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs index 11d514de6..bdf8822d3 100644 --- a/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs +++ b/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs @@ -44,8 +44,6 @@ public sealed class ZonePlacedAtBuildTests : IDisposable { OrbitPeriod = Flat(Period), BodyRadius = Flat(20f), - GravityRadius = Flat(0f), // brush inputs, read by Planet until grid-lowering deletes them - GravityDepth = Flat(0f), WellStrength = Flat(100f), CoreRadius = Flat(20f), RocheLimit = Flat(30f), From 45d19f3a8e25bd888942d3dbf509e30db1a42076 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 07:23:26 +0200 Subject: [PATCH 08/20] PotentialOwnerTests: authored curves read from Settings.asset; zero pinned from just below; the core bowl sampled to 0.99R TheAuthoredCurvesBuildAtEveryMass loads PlanetSettings from the asset the way RunStartTests does. The unphysical-strength theory adds -1e-6 and -float.Epsilon and a new test builds zero and negative zero. TheCoreIsTheBowlUpToItsEdge compares the drop from a lone body's centre with c r^2/2R^2 at 0.5R to 0.99R, tightly enough that a join at 0.95R fails. Not built or run locally; verified in the Yggdrasil job. Co-Authored-By: Claude Opus 5.5 --- .../PotentialOwnerTests.cs | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs b/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs index aa6aa626a..fda655819 100644 --- a/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs +++ b/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs @@ -185,11 +185,13 @@ public sealed class PotentialOwnerTests : IDisposable Assert.True(threw > 0 && built > 0, "the sweep holds masses on both sides of the crossing"); } - // The shipped curves keep the core inside the Roche limit over the whole generated mass range. + // The shipped curves keep the core inside the Roche limit over the whole generated mass range. The curves are the ones + // Settings.asset carries, read the way RunStartTests reads them, so a retune of the asset is judged here. [Fact] public void TheAuthoredCurvesBuildAtEveryMass() { - var planets = Curves(); + var planets = AuthoredSettings.Load(RunStartTests.FindRepoRoot()).Read("PlanetSettings"); + Assert.True(planets.WellStrength.Evaluate(100f) > 0f && planets.CoreRadius.Evaluate(100f) > 0f, "the authored asset carries a well"); for (var exponent10 = -3f; exponent10 <= 8f; exponent10 += .25f) ZoneOf(planets, (pow(10f, exponent10), float2.zero)); } @@ -201,6 +203,8 @@ public sealed class PotentialOwnerTests : IDisposable [InlineData(float.NaN)] [InlineData(float.PositiveInfinity)] [InlineData(float.NegativeInfinity)] + [InlineData(-1e-6f)] + [InlineData(-float.Epsilon)] public void AnUnphysicalWellStrengthThrowsAtConstruction(float strength) { var planets = Curves(); @@ -211,6 +215,24 @@ public sealed class PotentialOwnerTests : IDisposable Assert.Throws(() => ZoneOf(planets, (100f, float2.zero))); } + // Zero is the boundary: a well of no strength builds beside the authored core and Roche curves (it digs nothing), where + // the smallest negative strength does not. + [Theory] + [InlineData(0f)] + [InlineData(-0f)] + public void AWellOfNoStrengthBuildsAndDigsNothing(float strength) + { + var planets = Curves(); + planets.WellStrength = new ExponentialCurve { Constant = strength }; + var zone = ZoneOf(planets, (100f, float2.zero)); + foreach (var p in new[] { float2.zero, float2(3f, 1f), float2(40f, -9f), float2(900f, 0f) }) + { + Assert.Equal(0f, zone.GetHeight(p)); + Assert.Equal(0f, zone.GetForce(p).x); + Assert.Equal(0f, zone.GetForce(p).y); + } + } + // The well is authored once, by curves of mass (target: no per-body authoring of a core or Roche limit): a body whose // record carries other radius, gravity-radius or gravity-depth multipliers has the same strength, core and Roche limit, // and pulls and digs exactly as its plain twin. The multipliers are brush inputs for the renderer, nothing else. @@ -322,6 +344,31 @@ public sealed class PotentialOwnerTests : IDisposable } } + // Inside the core the potential is the bowl c r^2 / 2R^2 all the way out to R: the drop from a lone body's centre to a point + // at r is exactly that, from the middle of the core to a hair inside its edge (the log form agrees with the bowl to second + // order at R, so only a tight tolerance sees a join that sits just inside it). + [Fact] + public void TheCoreIsTheBowlUpToItsEdge() + { + foreach (var k in new[] { 1f, 10f }) + { + var planets = Curves(k); + foreach (var mass in new[] { 29.2f, 14152.4f }) + { + var zone = ZoneOf(planets, (mass, float2.zero)); + var c = planets.WellStrength.Evaluate(mass); + var core = planets.CoreRadius.Evaluate(mass); + foreach (var fraction in new[] { .5f, .75f, .9f, .95f, .98f, .99f }) + foreach (var angle in new[] { 0f, 2.3f }) + { + var r = fraction * core; + var drop = (zone.GetHeight(new float2(r * cos(angle), r * sin(angle))) - zone.GetHeight(float2.zero)) * k; + Near(c * fraction * fraction / 2f, drop, 2e-5f); + } + } + } + } + [Fact] public void TheCoreMeetsTheTailAtItsRadius() { From d7bdbc4a77a62fa27219eb3b447a4d9c4c47e26a Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 07:29:21 +0200 Subject: [PATCH 09/20] GravityLowering: the record comment no longer spells the deleted GravityWell name Comment only; verified code is 3a5b3b0b. Builds. Co-Authored-By: Claude Opus 5.5 --- Assets/Scripts/Zone Display/GravityLowering.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Scripts/Zone Display/GravityLowering.cs b/Assets/Scripts/Zone Display/GravityLowering.cs index c8d33cc7b..cf596a32a 100644 --- a/Assets/Scripts/Zone Display/GravityLowering.cs +++ b/Assets/Scripts/Zone Display/GravityLowering.cs @@ -14,7 +14,7 @@ public static class GravityLowering /// The quad's side in u: larger than any zone (10000) plus any view (4096); texels outside a camera cost nothing. public const float FieldExtent = 100000f; - // Mirrors Gravity.cginc's GravityWell: float2 position, strength, coreRadius, reference. + // Mirrors the well record of Gravity.cginc: float2 position, strength, coreRadius, reference. [StructLayout(LayoutKind.Sequential)] struct WellRecord { From e6d1546b44001bc786ab2b682df83100b78ea079 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 07:59:15 +0200 Subject: [PATCH 10/20] Gravity grid-lowering fixes: formula mirror test, verify across moved off-axis bodies and a zero-strength body, map camera wiring, RTS Planet's Gravity Well deleted GravityShaderMirrorTests compares the expression of GravityField.Potential with gravityPotential in Gravity.cginc. GravityFieldParityVerify now builds four off-axis bodies (one of mass 0), lowers through three frames with bodies moved between them, and checks the map screen's gravity camera mask. RTS/Planet.prefab loses the Gravity Well object bound to the Gravity Field material. Builds: yes (verify passes on Starfire; the new test is unrun until the Yggdrasil job). Co-Authored-By: Claude Opus 5.5 --- Assets/Prefabs/RTS/Planet.prefab | 93 +------------------ .../Editor/GravityFieldParityVerify.cs | 63 +++++++++---- .../GravityShaderMirrorTests.cs | 50 ++++++++++ 3 files changed, 97 insertions(+), 109 deletions(-) create mode 100644 tests/Aetheria.Shared.Tests/GravityShaderMirrorTests.cs diff --git a/Assets/Prefabs/RTS/Planet.prefab b/Assets/Prefabs/RTS/Planet.prefab index dc8300809..b288f30c5 100644 --- a/Assets/Prefabs/RTS/Planet.prefab +++ b/Assets/Prefabs/RTS/Planet.prefab @@ -223,7 +223,6 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - - {fileID: 5321404120083801960} - {fileID: 5321404118931821940} - {fileID: 5321404119494867799} - {fileID: 1093865191529778971} @@ -245,7 +244,7 @@ MonoBehaviour: Label: {fileID: 5321404119494867796} Message: {fileID: 6196070888394201391} Children: [] - GravityMesh: {fileID: 5321404120083801962} + GravityMesh: {fileID: 0} --- !u!1 &5321404118931821943 GameObject: m_ObjectHideFlags: 0 @@ -564,93 +563,3 @@ MonoBehaviour: m_hasFontAssetChanged: 0 m_renderer: {fileID: 5321404119494867795} m_maskType: 0 ---- !u!1 &5321404120083801964 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 5321404120083801960} - - component: {fileID: 5321404120083801963} - - component: {fileID: 5321404120083801962} - m_Layer: 8 - m_Name: Gravity Well - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &5321404120083801960 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 5321404120083801964} - serializedVersion: 2 - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 10, y: 10, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 5321404118521994135} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!33 &5321404120083801963 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 5321404120083801964} - m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0} ---- !u!23 &5321404120083801962 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 5321404120083801964} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_StaticShadowCaster: 0 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RayTraceProcedural: 0 - m_RayTracingAccelStructBuildFlagsOverride: 0 - m_RayTracingAccelStructBuildFlags: 1 - m_SmallMeshCulling: 1 - m_ForceMeshLod: -1 - m_MeshLodSelectionBias: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: 44a8bbb89acb4e34c9f41a9da5842bb4, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 0 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_GlobalIlluminationMeshLod: 0 - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_MaskInteraction: 0 - m_AdditionalVertexStreams: {fileID: 0} diff --git a/Assets/Scripts/Editor/GravityFieldParityVerify.cs b/Assets/Scripts/Editor/GravityFieldParityVerify.cs index 343789089..0f459c016 100644 --- a/Assets/Scripts/Editor/GravityFieldParityVerify.cs +++ b/Assets/Scripts/Editor/GravityFieldParityVerify.cs @@ -26,9 +26,9 @@ namespace Aetheria.EditorTools { const string Tag = "[GravityFieldParityVerify]"; const int Size = 256; - // Measured on this tree (the "max error" line this run prints): the largest |texel + GetHeight| over the three - // windows is 0.0059 u, in the planetoid's window (float32 on both sides, the GPU's log against the CPU's, the - // quad's interpolated world position). The tolerance is 5x that. A 0.1% error in the tail constant (.5 -> .501) + // Measured on this tree (the "max error" line this run prints): the largest |texel + GetHeight| over the windows of the three + // frames and windows is 0.0065 u, in the last frame's planetoid window (float32 on both sides, the GPU's log against the CPU's, the + // quad's interpolated world position). The tolerance is 4.6x that. A 0.1% error in the tail constant (.5 -> .501) // moves the drawn height by 0.053 u where all three tails reach (the planetoid and zone windows), 1.8x the // tolerance; a reference of zero moves it by about 150 u. const float Tolerance = 0.03f; @@ -70,16 +70,22 @@ namespace Aetheria.EditorTools var material = AssetDatabase.LoadAssetAtPath("Assets/Materials/Brushes/Gravity Field.mat") ?? throw new InvalidOperationException("No Gravity Field.mat."); - var zone = BuildZone(settings, work, out var bodies); + var zone = BuildZone(settings, work, out var orbits); GravityLowering.Lower(zone, ref wells); field = GravityLowering.CreateField(material); - var sun = Core(zone, 14152f); - var planetoid = Core(zone, 29.2f); - CheckTexels("planetoid", zone, bodies[2], 4f * planetoid); - CheckTexels("sun", zone, bodies[0], 4f * sun); - CheckTexels("zone", zone, new Vector2(0f, 0f), 1.05f * zone.Pack.Radius); - CheckGradient(zone, bodies); + // Three frames through the one buffer, as ZoneRenderer.Update runs it: the bodies as built, then two moves + // (an orbit's Position is what Zone.GetHeight reads). A lowering that mirrors an axis or stops refreshing + // the upload agrees with the sim in the first frame only where it is symmetric, and not after a move. + CheckFrame("built", zone, orbits); + orbits[1].Position = new float2(-420f, 560f); + orbits[2].Position = new float2(900f, -700f); + GravityLowering.Lower(zone, ref wells); + CheckFrame("moved", zone, orbits); + orbits[0].Position = new float2(210f, -95f); + orbits[2].Position = new float2(-1800f, 1300f); + GravityLowering.Lower(zone, ref wells); + CheckFrame("moved-again", zone, orbits); Debug.Log($"{Tag} max error {_maxError:G4} u (tolerance {Tolerance:G4}); max gradient angle {_maxAngle:F2} degrees (limit {GradientDegrees:F0})"); CheckWiring(settings); @@ -102,26 +108,43 @@ namespace Aetheria.EditorTools static float Core(Zone zone, float mass) => zone.Settings.CoreRadius.Evaluate(mass); - // A sun (14152 at the origin), a planet (273.9 at 610) and a planetoid (29.2 at 670): parentless, fixed, so the - // zone's wells sit where the verify says before any Update. - static Zone BuildZone(GameSettings settings, string work, out Vector2[] positions) + static Vector2 At(Orbit orbit) => new Vector2(orbit.Position.x, orbit.Position.y); + + // Orbits 0-2 are the sun, the planet and the planetoid, each window centred where the body is now; orbit 3 is the + // body of no strength. The zone window holds all four. + static void CheckFrame(string frame, Zone zone, Orbit[] orbits) + { + CheckTexels(frame + "-planetoid", zone, At(orbits[2]), 4f * Core(zone, 29.2f)); + CheckTexels(frame + "-sun", zone, At(orbits[0]), 4f * Core(zone, 14152f)); + CheckTexels(frame + "-zone", zone, Vector2.zero, 1.05f * zone.Pack.Radius); + CheckGradient(zone, orbits.Select(At).ToArray()); + } + + // A sun (14152 at (-130, 85)), a planet (273.9 at (610, -240)), a planetoid (29.2 at (670, -270)) and a body of + // mass 0, whose well has no strength (a legal body; its curves give c = 0 and R = 0), at (1700, 300): parentless, + // fixed, off both axes and asymmetric, so the zone's wells sit where the verify says before any Update and a + // mirrored or swapped axis cannot agree with the sim. + static Zone BuildZone(GameSettings settings, string work, out Orbit[] orbits) { var cache = AetheriaStores.Open(Path.Combine(work, "catalog.cc"), Path.Combine(work, "run.cc"), catalogWritable: true); cache.Upsert(new VerseGrammar { Revision = 1 }); cache.FlushAsync().Wait(); var items = new ItemManager(cache, new ProvenanceLedger(), settings.GameplaySettings, _ => { }); - positions = new[] { new Vector2(0f, 0f), new Vector2(610f, 0f), new Vector2(670f, 0f) }; - var masses = new[] { 14152f, 273.9f, 29.2f }; + var positions = new[] { new Vector2(-130f, 85f), new Vector2(610f, -240f), new Vector2(670f, -270f), new Vector2(1700f, 300f) }; + var masses = new[] { 14152f, 273.9f, 29.2f, 0f }; + var keys = new CultRecordKey[positions.Length]; var pack = new ZonePack { Radius = 4182f }; for (var i = 0; i < positions.Length; i++) { - var orbit = cache.Upsert(new OrbitData { FixedPosition = new float2(positions[i].x, positions[i].y) }).Key; + var orbit = keys[i] = cache.Upsert(new OrbitData { FixedPosition = new float2(positions[i].x, positions[i].y) }).Key; var body = cache.Upsert(new PlanetData { Name = "Body " + i, Orbit = new CultRecordRef(orbit), Mass = masses[i] }).Key; pack.Orbits.Add(new CultRecordRef(orbit)); pack.Planets.Add(new CultRecordRef(body)); } - return new Zone(items, settings.PlanetSettings, pack, new GalaxyZone { Name = "Gravity Parity", Owner = null }, null); + var zone = new Zone(items, settings.PlanetSettings, pack, new GalaxyZone { Name = "Gravity Parity", Owner = null }, null); + orbits = keys.Select(k => zone.Orbits[k]).ToArray(); + return zone; } // Renders the field through a downward orthographic camera that culls layer 9 only, centred on `centre` with @@ -244,6 +267,12 @@ namespace Aetheria.EditorTools } if (seen < gravityTargets.Length) Fail("wiring", $"only {seen} gravity cameras found in ARPG.unity"); + // The map screen's gravity camera has no target until MapRenderer gives it one at run time. + var map = UnityEngine.Object.FindFirstObjectByType(FindObjectsInactive.Include); + if (map == null || map.GravityCamera == null) Fail("wiring", "no MapRenderer.GravityCamera in ARPG.unity"); + else if (map.GravityCamera.cullingMask != 1 << GravityLowering.FieldLayer) + Fail("wiring", $"MapRenderer.GravityCamera culls mask {map.GravityCamera.cullingMask}, not layer {GravityLowering.FieldLayer} alone"); + var renderer = UnityEngine.Object.FindFirstObjectByType(FindObjectsInactive.Include); if (renderer == null) Fail("wiring", "no ZoneRenderer in ARPG.unity"); else if (renderer.GravityField == null || renderer.GravityField.shader.name != "Brushes/Gravity Field") diff --git a/tests/Aetheria.Shared.Tests/GravityShaderMirrorTests.cs b/tests/Aetheria.Shared.Tests/GravityShaderMirrorTests.cs new file mode 100644 index 000000000..e4f182e25 --- /dev/null +++ b/tests/Aetheria.Shared.Tests/GravityShaderMirrorTests.cs @@ -0,0 +1,50 @@ +using System.IO; +using System.Text.RegularExpressions; +using Xunit; + +// potential-owns-gravity (aetheria-gravity, cut grid-lowering): Assets/Shaders/Gravity.cginc lowers the potential for +// the GPU and decides nothing, so its gravityPotential must be GravityField.Potential, term for term, zero-strength +// guard and core branch included. The shader cannot be compiled here (GravityFieldParityVerify renders it, on Starfire +// only), so this test is the automated guard: each copy's expression is read from its file, reduced to the same +// spelling (float suffixes, the core radius's name, whitespace and comments), and compared. A drift in either file fails it. +public sealed class GravityShaderMirrorTests +{ + private static string Read(string relative) => + File.ReadAllText(Path.Combine(RunStartTests.FindRepoRoot(), relative)); + + // The text between `start` and the first `;` after it, comments removed and spellings reduced. + private static string Expression(string source, string start, string then = "") + { + source = Regex.Replace(source, @"//[^\n]*", ""); + var from = source.IndexOf(start, System.StringComparison.Ordinal); + Assert.True(from >= 0, $"'{start}' not found"); + var body = source.Substring(from + start.Length); + if (then != "") + { + var at = body.IndexOf(then, System.StringComparison.Ordinal); + Assert.True(at >= 0, $"'{then}' not found after '{start}'"); + body = body.Substring(at + then.Length); + } + body = body.Substring(0, body.IndexOf(';')); + body = Regex.Replace(body, @"(?<=[\d.])f\b", ""); + body = body.Replace("coreRadius", "R"); + return Regex.Replace(body, @"\s+", ""); + } + + private static string CSharpLaw() => + Expression(Read("Assets/Scripts/ServerShared/GravityField.cs"), "Potential(float c, float coreRadius, float r) =>"); + + private static string ShaderLaw() => + Expression(Read("Assets/Shaders/Gravity.cginc"), "float gravityPotential(float c, float R, float r)", "return"); + + [Fact] + public void TheShaderRunsTheSameLawAsGravityFieldPotential() + { + var law = CSharpLaw(); + // The reduction found the whole law, so equality is not two empty strings agreeing. + Assert.Contains("log(r/R)", law); + Assert.Contains("c==0?0:", law); + Assert.Contains("c*r*r/(2*R*R)", law); + Assert.Equal(law, ShaderLaw()); + } +} From 1c5326dd9d9a40850857d8aba41ee4df46a73140 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 08:17:10 +0200 Subject: [PATCH 11/20] TheCoreIsTheBowlUpToItsEdge: sample 0.996R so a join at 0.995R fails The mutation table showed a join at 0.995R surviving: no sample lay at or past it. At 0.996R the log form differs from the bowl by 1.6e-5 c, over the test's tolerance. Not built or run locally; verified in the Yggdrasil job. Co-Authored-By: Claude Opus 5.5 --- tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs b/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs index fda655819..fe883d8c3 100644 --- a/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs +++ b/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs @@ -358,7 +358,7 @@ public sealed class PotentialOwnerTests : IDisposable var zone = ZoneOf(planets, (mass, float2.zero)); var c = planets.WellStrength.Evaluate(mass); var core = planets.CoreRadius.Evaluate(mass); - foreach (var fraction in new[] { .5f, .75f, .9f, .95f, .98f, .99f }) + foreach (var fraction in new[] { .5f, .75f, .9f, .95f, .98f, .99f, .996f }) foreach (var angle in new[] { 0f, 2.3f }) { var r = fraction * core; From 13c7a08707a417495b5d064e1cef335583b45960 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 08:44:11 +0200 Subject: [PATCH 12/20] Gravity.cginc is generated: GravityShader.Source() is its one author, a test pins the committed file to it byte for byte The mirror test compared a normalised reading of two spellings and was beaten twice (a statement before the return, gravityHeight's sum). GravityShader writes the whole file (potential, zero-strength guard, reference term, height sum) from GravityField's constant (TailOffset); GravityShaderTests fails on any difference. GravityShaderMirrorTests deleted. GravityFieldParityVerify opens Main Menu.unity: no ZoneRenderer there, its Fog Surface Displacement camera is the menu's own brush presentation (layers 9 and 10) by spec. Builds not yet verified on this commit; verified at the final merge. Co-Authored-By: Claude Opus 5.5 --- .../Editor/GravityFieldParityVerify.cs | 30 +++++++++ Assets/Scripts/ServerShared/GravityField.cs | 5 +- Assets/Scripts/ServerShared/GravityShader.cs | 65 +++++++++++++++++++ .../ServerShared/GravityShader.cs.meta | 11 ++++ Assets/Shaders/Gravity.cginc | 9 +-- .../GravityShaderMirrorTests.cs | 50 -------------- .../GravityShaderTests.cs | 23 +++++++ 7 files changed, 138 insertions(+), 55 deletions(-) create mode 100644 Assets/Scripts/ServerShared/GravityShader.cs create mode 100644 Assets/Scripts/ServerShared/GravityShader.cs.meta delete mode 100644 tests/Aetheria.Shared.Tests/GravityShaderMirrorTests.cs create mode 100644 tests/Aetheria.Shared.Tests/GravityShaderTests.cs diff --git a/Assets/Scripts/Editor/GravityFieldParityVerify.cs b/Assets/Scripts/Editor/GravityFieldParityVerify.cs index 0f459c016..ae512d16e 100644 --- a/Assets/Scripts/Editor/GravityFieldParityVerify.cs +++ b/Assets/Scripts/Editor/GravityFieldParityVerify.cs @@ -251,6 +251,34 @@ namespace Aetheria.EditorTools if (compared < Size * Size / 2) Fail("gradient", $"only {compared} texels were compared"); } + // Main Menu.unity has no ZoneRenderer, so no Gravity Field and no lowered potential: its gravity cameras draw the + // menu's own brush objects (Boundary on layer 9, the Waves on layer 10) and are presentation by spec (follow-up + // menu-grid-brushes), not a reader of the potential. This pins that: a ZoneRenderer in the menu would make its + // cameras readers of the field, and they would have to cull layer 9 alone like ARPG's. + static void CheckMenuWiring() + { + var scene = EditorSceneManager.OpenScene("Assets/Scenes/Main Menu.unity", OpenSceneMode.Single); + try + { + if (UnityEngine.Object.FindFirstObjectByType(FindObjectsInactive.Include) != null) + Fail("wiring", "Main Menu.unity has a ZoneRenderer: its gravity cameras now read the Gravity Field and must cull layer 9 alone"); + var seen = 0; + foreach (var camera in UnityEngine.Object.FindObjectsByType(FindObjectsInactive.Include, FindObjectsSortMode.None)) + { + if (camera.targetTexture == null || camera.targetTexture.name != "Fog Surface Displacement") continue; + seen++; + const int menuBrushLayers = (1 << 9) | (1 << 10); + if (camera.cullingMask != menuBrushLayers) + Fail("wiring", $"Main Menu camera {camera.name} culls mask {camera.cullingMask}, not the menu brush layers 9 and 10"); + } + if (seen != 1) Fail("wiring", $"{seen} Fog Surface Displacement cameras in Main Menu.unity, expected 1"); + } + finally + { + EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); + } + } + static void CheckWiring(GameSettings settings) { var scene = EditorSceneManager.OpenScene("Assets/Scenes/ARPG.unity", OpenSceneMode.Single); @@ -287,6 +315,8 @@ namespace Aetheria.EditorTools EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); } + CheckMenuWiring(); + foreach (var path in new[] { "Assets/Prefabs/RPG/Planets/Planet.prefab", "Assets/Prefabs/RPG/Planets/Gas Giant.prefab", diff --git a/Assets/Scripts/ServerShared/GravityField.cs b/Assets/Scripts/ServerShared/GravityField.cs index 71e1f0c2a..01a070e9d 100644 --- a/Assets/Scripts/ServerShared/GravityField.cs +++ b/Assets/Scripts/ServerShared/GravityField.cs @@ -10,13 +10,16 @@ using float2 = CultMath.float2; /// public static class GravityField { + // The tail's additive constant: it makes the tail meet the core in value at the core radius. Gravity.cginc is generated from it. + public const float TailOffset = .5f; + // The potential at distance r from the body, defined up to a constant (callers subtract their reference). // A well of no strength (a body whose curves are unauthored, so c = 0 and R = 0) digs nothing. public static float Potential(float c, float coreRadius, float r) => c == 0f ? 0f : r < coreRadius ? c * r * r / (2 * coreRadius * coreRadius) - : c * (log(r / coreRadius) + .5f); + : c * (log(r / coreRadius) + TailOffset); // The acceleration at `offsetFromBody`, toward the body: zero at the body itself. public static float2 Acceleration(float c, float coreRadius, float2 offsetFromBody) diff --git a/Assets/Scripts/ServerShared/GravityShader.cs b/Assets/Scripts/ServerShared/GravityShader.cs new file mode 100644 index 000000000..e9dfd6224 --- /dev/null +++ b/Assets/Scripts/ServerShared/GravityShader.cs @@ -0,0 +1,65 @@ +using System.Globalization; + +/// +/// The single author of Assets/Shaders/Gravity.cginc, the GPU lowering of the zone's potential. The law is +/// GravityField's (its constants are read here, not respelled) and the height is Zone.GetHeight: each well's +/// potential minus its reference, summed, divided by the exaggeration. Unity does not run C# when it imports a +/// shader, so the committed cginc is this output; GravityShaderTests fails unless it equals Source() exactly. +/// To change the shader, change this file and regenerate: AETHERIA_REGENERATE_GRAVITY_CGINC=1 dotnet test --filter GravityShaderTests. +/// +public static class GravityShader +{ + public const string Path = "Assets/Shaders/Gravity.cginc"; + + /// The whole file, with LF line ends. + public static string Source() => (Template + .Replace("@TAIL@", GravityField.TailOffset.ToString("R", CultureInfo.InvariantCulture))) + .Replace("\r\n", "\n"); + + private const string Template = """ +#ifndef AETHERIA_GRAVITY_INCLUDED +#define AETHERIA_GRAVITY_INCLUDED + +// GENERATED by ServerShared/GravityShader.cs from GravityField; do not edit (GravityShaderTests fails on any difference). +// The lowering of the zone's potential (aetheria-gravity, cut grid-lowering). The law is ServerShared's GravityField +// and the height is Zone.GetHeight; this file decides nothing. GravityLowering.Lower fills the buffer and the globals +// from the zone (positions from Orbit.Position, reference from Zone.WellReference) each frame. +// GravityFieldParityVerify renders it and compares every texel with -Zone.GetHeight. + +struct GravityWell +{ + float2 position; + float strength; + float coreRadius; + float reference; +}; + +StructuredBuffer _GravityWells; +int _GravityWellCount; +float _HeightExaggeration; + +// GravityField.Potential: c is the well's strength, R its core radius, r the distance. +float gravityPotential(float c, float R, float r) +{ + return c == 0 ? 0 : + r < R + ? c * r * r / (2 * R * R) + : c * (log(r / R) + @TAIL@); +} + +// Zone.GetHeight at world xz: each well's potential minus its own reference, summed, divided by the exaggeration. +float gravityHeight(float2 p) +{ + float result = 0; + for (int i = 0; i < _GravityWellCount; i++) + { + GravityWell well = _GravityWells[i]; + result += gravityPotential(well.strength, well.coreRadius, length(p - well.position)) - well.reference; + } + return result / _HeightExaggeration; +} + +#endif + +"""; +} diff --git a/Assets/Scripts/ServerShared/GravityShader.cs.meta b/Assets/Scripts/ServerShared/GravityShader.cs.meta new file mode 100644 index 000000000..e241df3ba --- /dev/null +++ b/Assets/Scripts/ServerShared/GravityShader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9a3fa1e9df764459b709270e58e79974 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Shaders/Gravity.cginc b/Assets/Shaders/Gravity.cginc index 8cc256d94..47a419518 100644 --- a/Assets/Shaders/Gravity.cginc +++ b/Assets/Shaders/Gravity.cginc @@ -1,9 +1,10 @@ #ifndef AETHERIA_GRAVITY_INCLUDED #define AETHERIA_GRAVITY_INCLUDED +// GENERATED by ServerShared/GravityShader.cs from GravityField; do not edit (GravityShaderTests fails on any difference). // The lowering of the zone's potential (aetheria-gravity, cut grid-lowering). The law is ServerShared's GravityField -// and the height is Zone.GetHeight; this file mirrors them and decides nothing. GravityLowering.Lower fills the -// buffer and the globals from the zone (positions from Orbit.Position, reference from Zone.WellReference) each frame. +// and the height is Zone.GetHeight; this file decides nothing. GravityLowering.Lower fills the buffer and the globals +// from the zone (positions from Orbit.Position, reference from Zone.WellReference) each frame. // GravityFieldParityVerify renders it and compares every texel with -Zone.GetHeight. struct GravityWell @@ -18,13 +19,13 @@ StructuredBuffer _GravityWells; int _GravityWellCount; float _HeightExaggeration; -// GravityField.Potential, line for line: c is the well's strength, R its core radius, r the distance. +// GravityField.Potential: c is the well's strength, R its core radius, r the distance. float gravityPotential(float c, float R, float r) { return c == 0 ? 0 : r < R ? c * r * r / (2 * R * R) - : c * (log(r / R) + .5); + : c * (log(r / R) + 0.5); } // Zone.GetHeight at world xz: each well's potential minus its own reference, summed, divided by the exaggeration. diff --git a/tests/Aetheria.Shared.Tests/GravityShaderMirrorTests.cs b/tests/Aetheria.Shared.Tests/GravityShaderMirrorTests.cs deleted file mode 100644 index e4f182e25..000000000 --- a/tests/Aetheria.Shared.Tests/GravityShaderMirrorTests.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.IO; -using System.Text.RegularExpressions; -using Xunit; - -// potential-owns-gravity (aetheria-gravity, cut grid-lowering): Assets/Shaders/Gravity.cginc lowers the potential for -// the GPU and decides nothing, so its gravityPotential must be GravityField.Potential, term for term, zero-strength -// guard and core branch included. The shader cannot be compiled here (GravityFieldParityVerify renders it, on Starfire -// only), so this test is the automated guard: each copy's expression is read from its file, reduced to the same -// spelling (float suffixes, the core radius's name, whitespace and comments), and compared. A drift in either file fails it. -public sealed class GravityShaderMirrorTests -{ - private static string Read(string relative) => - File.ReadAllText(Path.Combine(RunStartTests.FindRepoRoot(), relative)); - - // The text between `start` and the first `;` after it, comments removed and spellings reduced. - private static string Expression(string source, string start, string then = "") - { - source = Regex.Replace(source, @"//[^\n]*", ""); - var from = source.IndexOf(start, System.StringComparison.Ordinal); - Assert.True(from >= 0, $"'{start}' not found"); - var body = source.Substring(from + start.Length); - if (then != "") - { - var at = body.IndexOf(then, System.StringComparison.Ordinal); - Assert.True(at >= 0, $"'{then}' not found after '{start}'"); - body = body.Substring(at + then.Length); - } - body = body.Substring(0, body.IndexOf(';')); - body = Regex.Replace(body, @"(?<=[\d.])f\b", ""); - body = body.Replace("coreRadius", "R"); - return Regex.Replace(body, @"\s+", ""); - } - - private static string CSharpLaw() => - Expression(Read("Assets/Scripts/ServerShared/GravityField.cs"), "Potential(float c, float coreRadius, float r) =>"); - - private static string ShaderLaw() => - Expression(Read("Assets/Shaders/Gravity.cginc"), "float gravityPotential(float c, float R, float r)", "return"); - - [Fact] - public void TheShaderRunsTheSameLawAsGravityFieldPotential() - { - var law = CSharpLaw(); - // The reduction found the whole law, so equality is not two empty strings agreeing. - Assert.Contains("log(r/R)", law); - Assert.Contains("c==0?0:", law); - Assert.Contains("c*r*r/(2*R*R)", law); - Assert.Equal(law, ShaderLaw()); - } -} diff --git a/tests/Aetheria.Shared.Tests/GravityShaderTests.cs b/tests/Aetheria.Shared.Tests/GravityShaderTests.cs new file mode 100644 index 000000000..dcd0e5d22 --- /dev/null +++ b/tests/Aetheria.Shared.Tests/GravityShaderTests.cs @@ -0,0 +1,23 @@ +using System; +using System.IO; +using Xunit; + +// potential-owns-gravity (aetheria-gravity, cut grid-lowering): Assets/Shaders/Gravity.cginc is the output of +// GravityShader.Source(), which reads GravityField's constants and writes the one lowering of the potential, the +// zero-strength guard, each well's reference and gravityHeight's sum. The committed file must equal it, character for +// character (line ends aside): any added statement, respelling, flipped sign, swapped argument or macro fails here. +// To change the shader, change GravityShader and run once with AETHERIA_REGENERATE_GRAVITY_CGINC=1. +public sealed class GravityShaderTests +{ + [Fact] + public void TheCommittedShaderIsTheGeneratedOne() + { + var path = Path.Combine(RunStartTests.FindRepoRoot(), GravityShader.Path); + if (Environment.GetEnvironmentVariable("AETHERIA_REGENERATE_GRAVITY_CGINC") == "1") + File.WriteAllText(path, GravityShader.Source()); + var generated = GravityShader.Source(); + // The law was generated, not an empty template agreeing with an empty file. + Assert.Contains("log(r / R) + 0.5", generated); + Assert.Equal(generated, File.ReadAllText(path).Replace("\r\n", "\n")); + } +} From 9b1b27d2d6df984ecaf2916380cc0d79e50e0f2d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 08:47:01 +0200 Subject: [PATCH 13/20] GravityShader: verbatim string, not a raw string literal (Unity's C# 9) Commit 13c7a087 and the merge a1b54bea do not build: error CS8773, raw string literals need C# 11. Co-Authored-By: Claude Opus 5.5 --- Assets/Scripts/ServerShared/GravityShader.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/ServerShared/GravityShader.cs b/Assets/Scripts/ServerShared/GravityShader.cs index e9dfd6224..ad163e26d 100644 --- a/Assets/Scripts/ServerShared/GravityShader.cs +++ b/Assets/Scripts/ServerShared/GravityShader.cs @@ -16,8 +16,7 @@ public static class GravityShader .Replace("@TAIL@", GravityField.TailOffset.ToString("R", CultureInfo.InvariantCulture))) .Replace("\r\n", "\n"); - private const string Template = """ -#ifndef AETHERIA_GRAVITY_INCLUDED + private const string Template = @"#ifndef AETHERIA_GRAVITY_INCLUDED #define AETHERIA_GRAVITY_INCLUDED // GENERATED by ServerShared/GravityShader.cs from GravityField; do not edit (GravityShaderTests fails on any difference). @@ -60,6 +59,5 @@ float gravityHeight(float2 p) } #endif - -"""; +"; } From bf69f489a927bade578955f1057a8e991c3a2115 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 15:22:14 +0200 Subject: [PATCH 14/20] Crossing: unpiloted crosser coasting at 50 u/s; the start-window sweep (bounds to be fitted) Co-Authored-By: Claude Opus 5.5 --- .../ServerShared/Scenarios/Crossing.cs | 17 ++-- .../CrossingScenarioTests.cs | 81 ++++++++++++++----- 2 files changed, 69 insertions(+), 29 deletions(-) diff --git a/Assets/Scripts/ServerShared/Scenarios/Crossing.cs b/Assets/Scripts/ServerShared/Scenarios/Crossing.cs index 880f492df..288763915 100644 --- a/Assets/Scripts/ServerShared/Scenarios/Crossing.cs +++ b/Assets/Scripts/ServerShared/Scenarios/Crossing.cs @@ -4,8 +4,10 @@ using static ItemRotation; public sealed class Crossing : Scenario { public override string Name => "Crossing"; - public override string Brief => "A Lightning Projector at the starboard gun and a Cell Blaster at the port gun, a fast Djinni crossing close ahead and an " + - "unpiloted one waiting at range. The Djinni starts to port moving across the bow, and its pilot brakes it as it closes. Make the pass coasting: give no throttle until the Djinni has crossed the bow, then fly freely (thrusting from the start carries you past it). Verify: as the Djinni crosses close, FastBlast lands some and projector " + + public override string Brief => "A Lightning Projector at the starboard gun and a Cell Blaster at the port gun, an unpiloted Djinni coasting across the bow " + + "at 50 m/s close ahead and an unpiloted one waiting at range. The crosser starts to port and only coasts: nothing steers it " + + "and it does not shoot back. Make the pass coasting: give no throttle until the Djinni has crossed the bow, then fly freely " + + "(thrusting from the start carries you past it). Verify: as the Djinni crosses close, FastBlast lands some and projector " + "almost none; against the Djinni at range both land. Fly it again without the Fire Control Array: " + "with it the small gun lands more."; public override uint Seed => 112; @@ -13,12 +15,11 @@ public sealed class Crossing : Scenario // Where the Djinni sit: the player is at Origin facing +z. Origin is 250 m or more from every body, where the zone's // pull is weakest (about 1.4 u/s^2; the sum of the wells never drops to nothing, and at the old origin the player sat on the star). - // The crosser starts ahead and to port, facing across the bow and already moving at the Djinni's 50 m/s cap; its pilot - // brakes it as it closes, so it only just reaches the bow line, which fixes how far to port it starts (sweeping the starting - // x from -95 to -97.5 moves the pass from 3.0 s to 3.5 s; at -98 it never crosses). The waiting Djinni sits inside the Lightning - // Projector's arc at 80% of its Range. + // The crosser is unpiloted and placed moving at the Djinni's 50 m/s cap, so its pass is ballistic, bent only by the field: + // CrosserAt is the centre of the start window in which the pass holds (the sweep test shifts it by 10 m on each axis). + // The waiting Djinni sits inside the Lightning Projector's arc at 80% of its Range. public static readonly CultMath.float2 Origin = float2(724, 124); - public static readonly CultMath.float2 CrosserAt = Origin + float2(-96.5f, 70), CrosserFacing = float2(1, 0), CrosserVelocity = float2(50, 0); + public static readonly CultMath.float2 CrosserAt = Origin + float2(-180, 45), CrosserFacing = float2(1, 0), CrosserVelocity = float2(50, 0); public const float ProjectorRange = 1216f; // the Lightning Projector's Range in metres, 1216.4 as the fit stands settled at rest public static readonly CultMath.float2 Waiting = Origin + float2(0, ProjectorRange * .8f); @@ -43,7 +44,7 @@ public sealed class Crossing : Scenario ("Fire Control Array", int2(1, 6), Clockwise)); stage.Player(fighter, Origin, facing: float2(0, 1)); - stage.Place(stage.Generated("Djinni"), CrosserAt, facing: CrosserFacing, stance: ScenarioStance.Hostile, piloted: true, velocity: CrosserVelocity); + stage.Place(stage.Generated("Djinni"), CrosserAt, facing: CrosserFacing, stance: ScenarioStance.Hostile, velocity: CrosserVelocity); stage.Place(stage.Bare("Djinni"), Waiting); } } diff --git a/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs b/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs index 955c331bd..a31270e4b 100644 --- a/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs +++ b/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs @@ -10,7 +10,7 @@ using float3 = CultMath.float3; public sealed partial class RunStartTests { // Crossing: the demo's cast; projector and Cell Blaster fitted in separate weapon groups with the Fire Control Array - // aboard; a piloted hostile Djinni that crosses the bow inside 400 m; and an unpiloted neutral one inside the Lightning Projector's + // aboard; an unpiloted hostile Djinni, coasting at the Djinni's speed cap, that crosses the bow inside 400 m; and an unpiloted neutral one inside the Lightning Projector's // arc, short of its Range and beyond three quarters of it. [Fact] public void CrossingConditions() @@ -37,7 +37,7 @@ public sealed partial class RunStartTests Assert.Contains(crosser.Equipment, item => item.Behaviors.OfType().Any()); Assert.True(player.IsHostileTo(crosser) && crosser.IsHostileTo(player), "the crosser is hostile both ways"); - Assert.Equal(1, AgentsOf(arena, crosser)); + Assert.Equal(0, AgentsOf(arena, crosser)); var toCrosser = crosser.Position - player.Position; Assert.True(length(toCrosser) < 400f, "the crosser starts inside 400 m"); Assert.True(toCrosser.z > 0, "the crosser starts ahead"); @@ -59,34 +59,72 @@ public sealed partial class RunStartTests Assert.True(length(toWaiting) <= range, "the waiting Djinni is inside the Lightning Projector's Range"); Assert.True(length(toWaiting) > .75f * range, "the waiting Djinni is beyond three quarters of the Lightning Projector's Range"); - // The crossing is what the sim does with that staging, read in the player's frame: the arena's gravity and the - // crosser's pilot act from the first tick, so the t=0 facing proves nothing. Within CrossingSeconds the crosser's - // bearing sweeps from port to starboard while it is ahead and inside CrossingMetres, and both guns bear on it. - // The pass is made by a coasting player: the loop gives no input, and the Brief tells the operator to fly it that way. + // The crossing is what the sim does with that staging, read in the player's frame: the arena's gravity acts from the + // first tick, so the t=0 facing proves nothing. Within CrossingSeconds the crosser's bearing sweeps from port to + // starboard while it is ahead and inside CrossingMetres, and both guns bear on it. The pass is made by a coasting + // player: the loop gives no input, and the Brief tells the operator to fly it that way. Assert.Equal(float2.zero, player.MovementDirection); - var swept = false; - var crossedAt = 0f; - var crossedMetres = 0f; - for (var tick = 0; tick < 60 * CrossingSeconds && !swept; tick++) + var pass = FlyPass(arena, player, crosser); + Assert.True(pass.Swept, $"the crosser's bearing never swept across the bow within {CrossingSeconds} s"); + Assert.True(pass.Ahead.y > 0, "the crosser passes the bow line ahead of the player, not astern"); + Assert.True(length(pass.Ahead) < CrossingMetres, "the crosser passes inside the stated distance"); + Assert.True(FireControl.InArc(small, pass.Ahead), "Cell Blaster bears on the crosser as it crosses"); + Assert.True(dot(FireControl.MountDirection(small), float3(player.Direction.x, 0, player.Direction.y)) > 0, "Cell Blaster mounts forward"); + // At seed 112 with no input the pass is at about 3.6 s and 45 m; a seed, field or staging change that loses it moves these. + Assert.InRange(pass.Seconds, CrossingEarliest, CrossingLatest); + Assert.InRange(length(pass.Ahead), 30f, 60f); + } + + // The unpiloted crosser's pass is ballistic, bent only by the field, so it does not hang on a lucky start: shifting where + // the crosser starts by up to 10 m along either axis keeps the pass inside the test's time and distance windows, fast across + // the line (relative speed at the bow line) and sweeping the player's view at a steady rate (angular rate seen from the player). + // The shifts are applied to what Crossing stages, so the window is the scenario's own. + [Fact] + public void CrossingHoldsAcrossTheStartWindow() + { + var passes = new System.Collections.Generic.List<(float2 shift, CrossingPass pass)>(); + foreach (var along in new[] { true, false }) + for (var step = -4; step <= 4; step++) + { + var shift = along ? float2(step * 2.5f, 0) : float2(0, step * 2.5f); + var (_, arena, staged, failures) = Launch(new Crossing(), Inputs(() => GalaxySeed)); + Assert.True(failures.Count == 0, string.Join("; ", failures)); + var crosser = staged.Entities[0]; + crosser.Position += float3(shift.x, 0, shift.y); + passes.Add((shift, FlyPass(arena, staged.Player, crosser))); + } + foreach (var (shift, pass) in passes) + { + var at = $"crosser start shifted by ({shift.x}, {shift.y}) m"; + Assert.True(pass.Swept, $"{at}: never crosses the bow within {CrossingSeconds} s"); + Assert.True(pass.Ahead.y > 0 && length(pass.Ahead) < CrossingMetres, $"{at}: crosses astern or beyond {CrossingMetres} m"); + Assert.InRange(pass.Seconds, CrossingEarliest, CrossingLatest); + Assert.InRange(length(pass.Ahead), 30f, 60f); + Assert.InRange(pass.RelativeSpeed, 0f, 1000f); + Assert.InRange(pass.AngularRate, 0f, 100f); + } + } + + // Where the crosser's bearing from the player sweeps from port to starboard: when, where it is then (x port-to-starboard, + // y ahead), its speed relative to the player and the angular rate of its bearing in radians per second. + private readonly record struct CrossingPass(bool Swept, float Seconds, float2 Ahead, float RelativeSpeed, float AngularRate); + + private static CrossingPass FlyPass(Zone arena, Ship player, Entity crosser) + { + for (var tick = 0; tick < 60 * CrossingSeconds; tick++) { var before = crosser.Position - player.Position; arena.Update(1f / 60f); var after = crosser.Position - player.Position; if (before.x < 0 && after.x >= 0) { - swept = true; - crossedAt = (tick + 1) / 60f; - crossedMetres = length(after); - Assert.True(after.z > 0, "the crosser passes the bow line ahead of the player, not astern"); - Assert.True(length(after) < CrossingMetres, "the crosser passes inside the stated distance"); - Assert.True(FireControl.InArc(small, after), "Cell Blaster bears on the crosser as it crosses"); - Assert.True(dot(FireControl.MountDirection(small), float3(player.Direction.x, 0, player.Direction.y)) > 0, "Cell Blaster mounts forward"); + var at = float2(after.x, after.z); + var relative = crosser.Velocity - player.Velocity; + return new CrossingPass(true, (tick + 1) / 60f, at, length(relative), abs(at.x * relative.y - at.y * relative.x) / dot(at, at)); } } - Assert.True(swept, $"the crosser's bearing never swept across the bow within {CrossingSeconds} s"); - // At seed 112 with no input the pass is at 3.2 s and 40 m (the pilot brakes the crosser as it closes, so the pass is sensitive to where it starts: Crossing.CrosserAt); a seed, field or staging change that loses it moves these. - Assert.InRange(crossedAt, 3.0f, 4.2f); - Assert.InRange(crossedMetres, 30f, 60f); + + return default; } // Place with no velocity leaves the entity at rest: the unpiloted waiting Djinni and both Shakedown targets start with @@ -104,6 +142,7 @@ public sealed partial class RunStartTests private const int CrossingSeconds = 6; private const float CrossingMetres = 150f; + private const float CrossingEarliest = 3.0f, CrossingLatest = 4.2f; // Djinni Shakedown: the generated Djinni carries a gun on a Ballistic hardpoint (not a launcher); that mount bears on // Ahead and not on Abeam, and both targets are neutral. From 61dc8c6d0e3cf523b5a01ac0b5475dc7e9bcd5d2 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 15:23:38 +0200 Subject: [PATCH 15/20] Crossing test: InArc takes a planar offset as float3 (WIP, bounds still unfitted) Co-Authored-By: Claude Opus 5.5 --- tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs b/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs index a31270e4b..bf0225368 100644 --- a/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs +++ b/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs @@ -68,7 +68,7 @@ public sealed partial class RunStartTests Assert.True(pass.Swept, $"the crosser's bearing never swept across the bow within {CrossingSeconds} s"); Assert.True(pass.Ahead.y > 0, "the crosser passes the bow line ahead of the player, not astern"); Assert.True(length(pass.Ahead) < CrossingMetres, "the crosser passes inside the stated distance"); - Assert.True(FireControl.InArc(small, pass.Ahead), "Cell Blaster bears on the crosser as it crosses"); + Assert.True(FireControl.InArc(small, float3(pass.Ahead.x, 0, pass.Ahead.y)), "Cell Blaster bears on the crosser as it crosses"); Assert.True(dot(FireControl.MountDirection(small), float3(player.Direction.x, 0, player.Direction.y)) > 0, "Cell Blaster mounts forward"); // At seed 112 with no input the pass is at about 3.6 s and 45 m; a seed, field or staging change that loses it moves these. Assert.InRange(pass.Seconds, CrossingEarliest, CrossingLatest); From ced6600261037a7844be77dc9aaf3ea6c174d039 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 15:28:56 +0200 Subject: [PATCH 16/20] Crossing: start window centred at (-128, 45); relative speed and angular rate bounds from the sweep The crosser is unpiloted and launched at 50 u/s; hull drag slows it to about 25 u/s relative at the bow line. Co-Authored-By: Claude Opus 5.5 --- Assets/Scripts/ServerShared/Scenarios/Crossing.cs | 12 +++++++----- tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/ServerShared/Scenarios/Crossing.cs b/Assets/Scripts/ServerShared/Scenarios/Crossing.cs index 288763915..f0e91be00 100644 --- a/Assets/Scripts/ServerShared/Scenarios/Crossing.cs +++ b/Assets/Scripts/ServerShared/Scenarios/Crossing.cs @@ -5,8 +5,8 @@ public sealed class Crossing : Scenario { public override string Name => "Crossing"; public override string Brief => "A Lightning Projector at the starboard gun and a Cell Blaster at the port gun, an unpiloted Djinni coasting across the bow " + - "at 50 m/s close ahead and an unpiloted one waiting at range. The crosser starts to port and only coasts: nothing steers it " + - "and it does not shoot back. Make the pass coasting: give no throttle until the Djinni has crossed the bow, then fly freely " + + "close ahead and an unpiloted one waiting at range. The crosser is launched to port at 50 m/s and only coasts: nothing steers it, " + + "its hull drag slows it to about 25 m/s at the bow line, and it does not shoot back. Make the pass coasting: give no throttle until the Djinni has crossed the bow, then fly freely " + "(thrusting from the start carries you past it). Verify: as the Djinni crosses close, FastBlast lands some and projector " + "almost none; against the Djinni at range both land. Fly it again without the Fire Control Array: " + "with it the small gun lands more."; @@ -15,11 +15,13 @@ public sealed class Crossing : Scenario // Where the Djinni sit: the player is at Origin facing +z. Origin is 250 m or more from every body, where the zone's // pull is weakest (about 1.4 u/s^2; the sum of the wells never drops to nothing, and at the old origin the player sat on the star). - // The crosser is unpiloted and placed moving at the Djinni's 50 m/s cap, so its pass is ballistic, bent only by the field: - // CrosserAt is the centre of the start window in which the pass holds (the sweep test shifts it by 10 m on each axis). + // The crosser is unpiloted and placed moving at the Djinni's 50 m/s cap, so its pass is ballistic: bent by the field and slowed + // by hull drag (it reaches the bow line at about 25 m/s relative to the player, 3.6 s in), and nothing steers it. + // CrosserAt is the centre of the start window in which the pass holds: shifting it by 10 m along either axis keeps the pass + // inside the test's time and distance windows (CrossingHoldsAcrossTheStartWindow). // The waiting Djinni sits inside the Lightning Projector's arc at 80% of its Range. public static readonly CultMath.float2 Origin = float2(724, 124); - public static readonly CultMath.float2 CrosserAt = Origin + float2(-180, 45), CrosserFacing = float2(1, 0), CrosserVelocity = float2(50, 0); + public static readonly CultMath.float2 CrosserAt = Origin + float2(-128, 45), CrosserFacing = float2(1, 0), CrosserVelocity = float2(50, 0); public const float ProjectorRange = 1216f; // the Lightning Projector's Range in metres, 1216.4 as the fit stands settled at rest public static readonly CultMath.float2 Waiting = Origin + float2(0, ProjectorRange * .8f); diff --git a/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs b/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs index bf0225368..cc0079ebc 100644 --- a/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs +++ b/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs @@ -100,8 +100,8 @@ public sealed partial class RunStartTests Assert.True(pass.Ahead.y > 0 && length(pass.Ahead) < CrossingMetres, $"{at}: crosses astern or beyond {CrossingMetres} m"); Assert.InRange(pass.Seconds, CrossingEarliest, CrossingLatest); Assert.InRange(length(pass.Ahead), 30f, 60f); - Assert.InRange(pass.RelativeSpeed, 0f, 1000f); - Assert.InRange(pass.AngularRate, 0f, 100f); + Assert.InRange(pass.RelativeSpeed, 20f, 30f); + Assert.InRange(pass.AngularRate, 0.3f, 0.7f); } } From a033c01c561f875c52cf4d0e6b8d3850d01deef0 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 15:47:12 +0200 Subject: [PATCH 17/20] Crossing sweep: assert the shifts moved the pass, so a sweep that ignores them fails Co-Authored-By: Claude Opus 5.5 --- tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs b/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs index cc0079ebc..769264ec3 100644 --- a/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs +++ b/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs @@ -103,6 +103,13 @@ public sealed partial class RunStartTests Assert.InRange(pass.RelativeSpeed, 20f, 30f); Assert.InRange(pass.AngularRate, 0.3f, 0.7f); } + + // The shifts took effect: starting 20 m further out along the crosser's track delays the pass, and starting 20 m further + // ahead moves it 20 m further ahead (a sweep that stages the same pass eighteen times proves nothing). + var along = passes.Take(9).Select(entry => entry.pass).ToList(); + var across = passes.Skip(9).Select(entry => entry.pass).ToList(); + Assert.True(along[0].Seconds - along[8].Seconds > .5f, "a start 20 m further out delays the pass by more than half a second"); + Assert.InRange(across[8].Ahead.y - across[0].Ahead.y, 10f, 30f); } // Where the crosser's bearing from the player sweeps from port to starboard: when, where it is then (x port-to-starboard, From aa3af5ecc025e046820d988ca9fd6cc60e424f09 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 15:48:05 +0200 Subject: [PATCH 18/20] Crossing sweep: the lateral shift moves the pass by at least 3 m (the crosser meets the player's hull below a 40 m start) Co-Authored-By: Claude Opus 5.5 --- tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs b/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs index 769264ec3..61eb186d7 100644 --- a/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs +++ b/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs @@ -109,7 +109,7 @@ public sealed partial class RunStartTests var along = passes.Take(9).Select(entry => entry.pass).ToList(); var across = passes.Skip(9).Select(entry => entry.pass).ToList(); Assert.True(along[0].Seconds - along[8].Seconds > .5f, "a start 20 m further out delays the pass by more than half a second"); - Assert.InRange(across[8].Ahead.y - across[0].Ahead.y, 10f, 30f); + Assert.InRange(across[8].Ahead.y - across[0].Ahead.y, 3f, 30f); } // Where the crosser's bearing from the player sweeps from port to starboard: when, where it is then (x port-to-starboard, From cc3249b8c9bd9a607bc6d1dae0ae019ed75ff39f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 15:50:20 +0200 Subject: [PATCH 19/20] Crossing sweep: rename the shifted-pass lists (a name clash broke the previous two commits' build) Co-Authored-By: Claude Opus 5.5 --- tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs b/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs index 61eb186d7..a55cf3e93 100644 --- a/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs +++ b/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs @@ -106,10 +106,10 @@ public sealed partial class RunStartTests // The shifts took effect: starting 20 m further out along the crosser's track delays the pass, and starting 20 m further // ahead moves it 20 m further ahead (a sweep that stages the same pass eighteen times proves nothing). - var along = passes.Take(9).Select(entry => entry.pass).ToList(); - var across = passes.Skip(9).Select(entry => entry.pass).ToList(); - Assert.True(along[0].Seconds - along[8].Seconds > .5f, "a start 20 m further out delays the pass by more than half a second"); - Assert.InRange(across[8].Ahead.y - across[0].Ahead.y, 3f, 30f); + var outward = passes.Take(9).Select(entry => entry.pass).ToList(); + var lateral = passes.Skip(9).Select(entry => entry.pass).ToList(); + Assert.True(outward[0].Seconds - outward[8].Seconds > .5f, "a start 20 m further out delays the pass by more than half a second"); + Assert.InRange(lateral[8].Ahead.y - lateral[0].Ahead.y, 3f, 30f); } // Where the crosser's bearing from the player sweeps from port to starboard: when, where it is then (x port-to-starboard, From 8f491fd3c9a43822071cb4c9067354fa9b304ae5 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 16:46:53 +0200 Subject: [PATCH 20/20] Core radius is the Roche curve; the global exaggeration divides by the core's growth core-at-roche-and-exaggeration-up: PlanetSettings.CoreRadius and Planet.CoreRadius are deleted; the well's softened core reads the RocheLimit curve (one curve of mass). The core < Roche guard cannot fail and is replaced by a Roche-limit-positive-and-finite check. Settings.asset: CoreRadius removed, HeightExaggeration 10 -> 4.0983607 (10 / (7.32 / 3)). Tests pin the new curves and the peak drawn slope / 2.44x steeper tail. Not yet built or run at this commit. Co-Authored-By: Claude Opus 5.5 --- Assets/Resources/Settings.asset | 4 +- .../Editor/GravityFieldParityVerify.cs | 2 +- Assets/Scripts/ServerShared/Settings.cs | 7 +- Assets/Scripts/ServerShared/Zone.cs | 16 ++- .../Scripts/Zone Display/GravityLowering.cs | 2 +- .../GravitySubtractTests.cs | 3 +- .../PotentialOwnerTests.cs | 98 ++++++++----------- tests/Aetheria.Shared.Tests/WellFixture.cs | 7 +- .../ZonePlacedAtBuildTests.cs | 5 +- 9 files changed, 63 insertions(+), 81 deletions(-) diff --git a/Assets/Resources/Settings.asset b/Assets/Resources/Settings.asset index ec980b8e8..df56f95ed 100644 --- a/Assets/Resources/Settings.asset +++ b/Assets/Resources/Settings.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:51f559958bd719e1d158b526bee1876fc3c838462b638d79c4f448c34331c420 -size 12712 +oid sha256:9d641fe942dfd45990a0609b3017a63cdc27f502ab12aa74ffbf984ea3e8d346 +size 12644 diff --git a/Assets/Scripts/Editor/GravityFieldParityVerify.cs b/Assets/Scripts/Editor/GravityFieldParityVerify.cs index ae512d16e..c6de02c4a 100644 --- a/Assets/Scripts/Editor/GravityFieldParityVerify.cs +++ b/Assets/Scripts/Editor/GravityFieldParityVerify.cs @@ -106,7 +106,7 @@ namespace Aetheria.EditorTools EditorApplication.Exit(_ok ? 0 : 1); } - static float Core(Zone zone, float mass) => zone.Settings.CoreRadius.Evaluate(mass); + static float Core(Zone zone, float mass) => zone.Settings.RocheLimit.Evaluate(mass); static Vector2 At(Orbit orbit) => new Vector2(orbit.Position.x, orbit.Position.y); diff --git a/Assets/Scripts/ServerShared/Settings.cs b/Assets/Scripts/ServerShared/Settings.cs index 6fcdd8f61..24078a658 100644 --- a/Assets/Scripts/ServerShared/Settings.cs +++ b/Assets/Scripts/ServerShared/Settings.cs @@ -16,13 +16,12 @@ public class PlanetSettings public ExponentialCurve LightRadius; public ExponentialCurve BodyRadius; - // The closest a child may orbit its parent, in u, by the parent's mass. Authored like BodyRadius, never per body. + // The closest a child may orbit its parent, in u, by the parent's mass, and the softened core radius of the parent's + // well (the steepest drawn slope sits at the Roche limit). Authored like BodyRadius, never per body. public ExponentialCurve RocheLimit = new ExponentialCurve(); - // A body's well, by its mass (GravityField): its strength c in u^2/s^2 (the pull is c / r beyond the core) and its - // softened core radius in u, which must stay inside the RocheLimit curve. + // A body's well strength by its mass (GravityField): c in u^2/s^2 (the pull is c / r beyond the core, which is the Roche limit). public ExponentialCurve WellStrength = new ExponentialCurve(); - public ExponentialCurve CoreRadius = new ExponentialCurve(); // The one global exaggeration of gravity height: height = potential / K, in u/s^2 per unit of height. public float HeightExaggeration = 1f; diff --git a/Assets/Scripts/ServerShared/Zone.cs b/Assets/Scripts/ServerShared/Zone.cs index ccec8edfd..db4bf6b3d 100644 --- a/Assets/Scripts/ServerShared/Zone.cs +++ b/Assets/Scripts/ServerShared/Zone.cs @@ -614,7 +614,7 @@ public class Zone // The potential of a body's well at the zone's edge, subtracted so every well is zero there: the one owner of the // reference. GetHeight sums with it and the renderer's lowering (GravityLowering) hands it to the shader unchanged. - public float WellReference(Planet body) => GravityField.Potential(body.WellStrength, body.CoreRadius, Pack.Radius); + public float WellReference(Planet body) => GravityField.Potential(body.WellStrength, body.RocheLimit, Pack.Radius); public float GetHeight(float2 position) { @@ -622,7 +622,7 @@ public class Zone foreach (var body in PlanetInstances.Values) { var offset = position - body.Orbit.Position; - result += GravityField.Potential(body.WellStrength, body.CoreRadius, length(offset)) - WellReference(body); + result += GravityField.Potential(body.WellStrength, body.RocheLimit, length(offset)) - WellReference(body); } return result / Settings.HeightExaggeration; @@ -652,7 +652,7 @@ public class Zone { var force = float2.zero; foreach (var body in PlanetInstances.Values) - force += GravityField.Acceleration(body.WellStrength, body.CoreRadius, position - body.Orbit.Position); + force += GravityField.Acceleration(body.WellStrength, body.RocheLimit, position - body.Orbit.Position); return force; } @@ -690,10 +690,9 @@ public class Planet public BodyData BodyData; public float BodyRadius; - // The well (GravityField): strength c and softened core radius R by mass, and the Roche limit, the closest a child - // may orbit. All three are authored PlanetSettings curves of mass; the core must sit inside the Roche limit. + // The well (GravityField): strength c by mass, and the Roche limit, which is both the closest a child may orbit and + // the well's softened core radius R (one curve of mass, never per body). Both are authored PlanetSettings curves. public float WellStrength; - public float CoreRadius; public float RocheLimit; public Planet(PlanetSettings settings, BodyData data, Orbit orbit) @@ -708,12 +707,11 @@ public class Planet { BodyRadius = Settings.BodyRadius.Evaluate(BodyData.Mass) * BodyData.BodyRadiusMultiplier; WellStrength = Settings.WellStrength.Evaluate(BodyData.Mass); - CoreRadius = Settings.CoreRadius.Evaluate(BodyData.Mass); RocheLimit = Settings.RocheLimit.Evaluate(BodyData.Mass); if (!(WellStrength >= 0f) || float.IsInfinity(WellStrength)) throw new InvalidOperationException("A body's well strength must be finite and not negative (PlanetSettings.WellStrength)."); - if (WellStrength > 0 && !(0 < CoreRadius && CoreRadius < RocheLimit)) - throw new InvalidOperationException("A body's core radius must be positive and inside its Roche limit (PlanetSettings.CoreRadius, RocheLimit)."); + if (WellStrength > 0 && !(RocheLimit > 0f && !float.IsInfinity(RocheLimit))) + throw new InvalidOperationException("A body's Roche limit, which is its core radius, must be positive and finite (PlanetSettings.RocheLimit)."); } } diff --git a/Assets/Scripts/Zone Display/GravityLowering.cs b/Assets/Scripts/Zone Display/GravityLowering.cs index cf596a32a..b8c2a062a 100644 --- a/Assets/Scripts/Zone Display/GravityLowering.cs +++ b/Assets/Scripts/Zone Display/GravityLowering.cs @@ -52,7 +52,7 @@ public static class GravityLowering { Position = new Vector2(body.Orbit.Position.x, body.Orbit.Position.y), Strength = body.WellStrength, - CoreRadius = body.CoreRadius, + CoreRadius = body.RocheLimit, Reference = zone.WellReference(body) }; wells.SetData(_records); diff --git a/tests/Aetheria.Shared.Tests/GravitySubtractTests.cs b/tests/Aetheria.Shared.Tests/GravitySubtractTests.cs index 078de12f2..d901b5a39 100644 --- a/tests/Aetheria.Shared.Tests/GravitySubtractTests.cs +++ b/tests/Aetheria.Shared.Tests/GravitySubtractTests.cs @@ -43,7 +43,6 @@ public sealed class GravitySubtractTests : IDisposable private static PlanetSettings Planets() => new PlanetSettings { WellStrength = new ExponentialCurve { Exponent = .2f, Multiplier = 45.08f }, - CoreRadius = new ExponentialCurve { Exponent = .25f, Multiplier = 3f }, RocheLimit = new ExponentialCurve { Exponent = .25f, Multiplier = 7.32f }, BodyRadius = new ExponentialCurve { Exponent = .25f, Multiplier = 3f }, LightRadius = new ExponentialCurve { Exponent = .25f, Multiplier = 300f }, @@ -95,7 +94,7 @@ public sealed class GravitySubtractTests : IDisposable { var plain = WithBody(new PlanetData()); var giants = new[] { WithBody(new GasGiantData()), WithBody(new SunData()) }; - var core = plain.PlanetInstances.Values.Single().CoreRadius; + var core = plain.PlanetInstances.Values.Single().RocheLimit; Assert.True(core > 1f, "the fixture body has a core to sweep around"); var radii = new System.Collections.Generic.List { 0.5f, core }; for (var r = core / 4f; r <= 4f * core; r += core / 16f) radii.Add(r); diff --git a/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs b/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs index 2621dd838..bcb5310b5 100644 --- a/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs +++ b/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs @@ -40,11 +40,10 @@ public sealed class PotentialOwnerTests : IDisposable Directory.Delete(_root, true); } - // The authored curves of the shipped Settings.asset: strength c = 45.08 m^.2, core R = 3 m^.25, Roche 7.32 m^.25. + // The authored curves of the shipped Settings.asset: strength c = 45.08 m^.2, Roche limit and core R = 7.32 m^.25. private static PlanetSettings Curves(float exaggeration = 1f) => new PlanetSettings { WellStrength = new ExponentialCurve { Exponent = .2f, Multiplier = 45.08f }, - CoreRadius = new ExponentialCurve { Exponent = .25f, Multiplier = 3f }, RocheLimit = new ExponentialCurve { Exponent = .25f, Multiplier = 7.32f }, BodyRadius = new ExponentialCurve { Exponent = .25f, Multiplier = 2f }, LightRadius = new ExponentialCurve(), OrbitPeriod = new ExponentialCurve(), @@ -102,20 +101,20 @@ public sealed class PotentialOwnerTests : IDisposable foreach (var mass in new[] { 29.2f, 273.9f, 14152.4f }) { var zone = ZoneOf(planets, (mass, float2.zero)); - var core = planets.CoreRadius.Evaluate(mass); + var core = planets.RocheLimit.Evaluate(mass); foreach (var r in new[] { 3f * core, 10f * core, PackRadius / 2f }) Near(planets.WellStrength.Evaluate(mass), length(zone.GetForce(new float2(r, 0))) * r, 1e-3f); } } [Fact] - public void TheCoreRadiusFollowsItsOwnCurve() + public void TheCoreRadiusIsTheRocheCurve() { var planets = Curves(); foreach (var mass in new[] { 29.2f, 14152.4f }) { var zone = ZoneOf(planets, (mass, float2.zero)); - var core = planets.CoreRadius.Evaluate(mass); + var core = planets.RocheLimit.Evaluate(mass); float Pull(float r) => length(zone.GetForce(new float2(0, r))); var slope = Pull(.25f * core) / (.25f * core); Near(slope, Pull(.5f * core) / (.5f * core), 1e-3f); @@ -125,70 +124,61 @@ public sealed class PotentialOwnerTests : IDisposable } } + // core-at-roche-and-exaggeration-up: the one curve is both the Roche limit and the core. A body with a well and no + // Roche limit has no core and is an authoring error; any positive, finite limit builds. [Fact] - public void TheCoreSitsInsideTheRocheLimit() + public void TheRocheLimitIsTheCore() { var planets = Curves(); foreach (var mass in new[] { 29.2f, 14152.4f }) Near(planets.RocheLimit.Evaluate(mass), ZoneOf(planets, (mass, float2.zero)).PlanetInstances.Values.Single().RocheLimit, 1e-6f); - PlanetSettings Constants(float core, float roche) => new PlanetSettings + PlanetSettings Constants(float roche) => new PlanetSettings { WellStrength = new ExponentialCurve { Constant = 100f }, - CoreRadius = new ExponentialCurve { Constant = core }, RocheLimit = new ExponentialCurve { Constant = roche }, BodyRadius = new ExponentialCurve { Constant = 10f }, LightRadius = new ExponentialCurve(), OrbitPeriod = new ExponentialCurve() }; - Assert.Throws(() => ZoneOf(Constants(60f, 50f), (100f, float2.zero))); - Assert.Throws(() => ZoneOf(Constants(50f, 50f), (100f, float2.zero))); - Assert.Throws(() => ZoneOf(Constants(0f, 50f), (100f, float2.zero))); - ZoneOf(Constants(20f, 50f), (100f, float2.zero)); // inside the limit, and past the body's radius + Assert.Throws(() => ZoneOf(Constants(0f), (100f, float2.zero))); + Assert.Throws(() => ZoneOf(Constants(-5f), (100f, float2.zero))); + Assert.Throws(() => ZoneOf(Constants(float.PositiveInfinity), (100f, float2.zero))); + ZoneOf(Constants(50f), (100f, float2.zero)); } - // core-inside-roche-curve at every mass: the guard compares the two authored curves for each body, light or heavy. - // Each pair of curves crosses somewhere in the generated mass range (1e-3 to 1e8), so the sweep holds both outcomes. - [Theory] - [InlineData(30f, .25f, 7.32f, .5f)] // the core curve starts above the Roche curve and is overtaken: light bodies throw - [InlineData(3f, .5f, 7.32f, .25f)] // the core curve overtakes the Roche curve: heavy bodies throw - public void TheGuardJudgesEveryMassByItsOwnCurves(float coreMultiplier, float coreExponent, float rocheMultiplier, float rocheExponent) + // core-at-roche-and-exaggeration-up: growing the core to the Roche limit (3 m^.25 to 7.32 m^.25, 2.44x) and dividing the + // global K by that factor leaves the steepest drawn slope (|grad phi| / K, at the core) where it was, and draws every + // slope outside the old core 2.44x steeper. The "before" side is the previous authoring, stated here from the ruling: + // core 3 m^.25 and K 10. The "after" side is the shipped Settings.asset read through the production zone. + [Fact] + public void ThePeakDrawnSlopeStaysAndTheFunnelDrawsSteeper() { - var planets = new PlanetSettings + const float oldCoreMultiplier = 3f, oldExaggeration = 10f; + var planets = AuthoredSettings.Load(RunStartTests.FindRepoRoot()).Read("PlanetSettings"); + foreach (var mass in new[] { 29.2f, 273.9f, 14152.4f }) { - WellStrength = new ExponentialCurve { Constant = 100f }, - CoreRadius = new ExponentialCurve { Multiplier = coreMultiplier, Exponent = coreExponent }, - RocheLimit = new ExponentialCurve { Multiplier = rocheMultiplier, Exponent = rocheExponent }, - BodyRadius = new ExponentialCurve { Constant = 1f }, - LightRadius = new ExponentialCurve(), OrbitPeriod = new ExponentialCurve() - }; - var threw = 0; - var built = 0; - for (var exponent10 = -3f; exponent10 <= 8f; exponent10 += .25f) - { - var mass = pow(10f, exponent10); - var core = planets.CoreRadius.Evaluate(mass); - var roche = planets.RocheLimit.Evaluate(mass); - if (0 < core && core < roche) - { - ZoneOf(planets, (mass, float2.zero)); - built++; - } - else - { - Assert.Throws(() => ZoneOf(planets, (mass, float2.zero))); - threw++; - } + var zone = ZoneOf(planets, (mass, float2.zero)); + var c = planets.WellStrength.Evaluate(mass); + var oldCore = oldCoreMultiplier * pow(mass, .25f); + float Drawn(float r) => length(zone.GetForce(new float2(r, 0))) / zone.Settings.HeightExaggeration; + + var peakBefore = c / oldCore / oldExaggeration; + Assert.InRange(Drawn(planets.RocheLimit.Evaluate(mass)), peakBefore * .98f, peakBefore * 1.02f); + + var rocheOverOldCore = planets.RocheLimit.Evaluate(mass) / oldCore; + var farBefore = c / (3f * oldCore) / oldExaggeration; + Near(rocheOverOldCore, Drawn(3f * oldCore) / farBefore, 1e-2f); + Assert.InRange(Drawn(3f * oldCore) / farBefore, 2.44f * .99f, 2.44f * 1.01f); } - Assert.True(threw > 0 && built > 0, "the sweep holds masses on both sides of the crossing"); } - // The shipped curves keep the core inside the Roche limit over the whole generated mass range. The curves are the ones + // The shipped curves build a well at every mass of the generated range. The curves are the ones // Settings.asset carries, read the way RunStartTests reads them, so a retune of the asset is judged here. [Fact] public void TheAuthoredCurvesBuildAtEveryMass() { var planets = AuthoredSettings.Load(RunStartTests.FindRepoRoot()).Read("PlanetSettings"); - Assert.True(planets.WellStrength.Evaluate(100f) > 0f && planets.CoreRadius.Evaluate(100f) > 0f, "the authored asset carries a well"); + Assert.True(planets.WellStrength.Evaluate(100f) > 0f && planets.RocheLimit.Evaluate(100f) > 0f, "the authored asset carries a well"); for (var exponent10 = -3f; exponent10 <= 8f; exponent10 += .25f) ZoneOf(planets, (pow(10f, exponent10), float2.zero)); } @@ -207,12 +197,11 @@ public sealed class PotentialOwnerTests : IDisposable var planets = Curves(); planets.WellStrength = new ExponentialCurve { Constant = strength }; Assert.Throws(() => ZoneOf(planets, (100f, float2.zero))); - planets.CoreRadius = new ExponentialCurve(); planets.RocheLimit = new ExponentialCurve(); Assert.Throws(() => ZoneOf(planets, (100f, float2.zero))); } - // Zero is the boundary: a well of no strength builds beside the authored core and Roche curves (it digs nothing), where + // Zero is the boundary: a well of no strength builds beside the authored Roche curve (it digs nothing), where // the smallest negative strength does not. [Theory] [InlineData(0f)] @@ -249,9 +238,8 @@ public sealed class PotentialOwnerTests : IDisposable var a = plain.PlanetInstances.Values.Single(); var b = scaled.PlanetInstances.Values.Single(); Assert.Equal(a.WellStrength, b.WellStrength); - Assert.Equal(a.CoreRadius, b.CoreRadius); Assert.Equal(a.RocheLimit, b.RocheLimit); - foreach (var p in new[] { float2(.4f * a.CoreRadius, 0), float2(0, 3f * a.CoreRadius), float2(400f, 300f) }) + foreach (var p in new[] { float2(.4f * a.RocheLimit, 0), float2(0, 3f * a.RocheLimit), float2(400f, 300f) }) { Assert.Equal(plain.GetForce(p), scaled.GetForce(p)); Assert.Equal(plain.GetHeight(p), scaled.GetHeight(p)); @@ -265,7 +253,7 @@ public sealed class PotentialOwnerTests : IDisposable var planets = Curves(); var zone = ZoneOf(planets, (273.9f, float2.zero)); var c = planets.WellStrength.Evaluate(273.9f); - var core = planets.CoreRadius.Evaluate(273.9f); + var core = planets.RocheLimit.Evaluate(273.9f); foreach (var r in new[] { core, 2f * core, PackRadius, 10f * PackRadius, 100f * PackRadius, 1000f * PackRadius }) foreach (var angle in new[] { 0f, 1.1f, 3.5f }) { @@ -307,15 +295,15 @@ public sealed class PotentialOwnerTests : IDisposable var planets = Curves(k); var lone = ZoneOf(planets, (273.9f, float2.zero)); var c = planets.WellStrength.Evaluate(273.9f); - var core = planets.CoreRadius.Evaluate(273.9f); + var core = planets.RocheLimit.Evaluate(273.9f); Assert.Equal(0f, lone.GetHeight(new float2(PackRadius, 0)), 4); Near(-c * (log(PackRadius / core) + .5f) / k, lone.GetHeight(float2.zero), 1e-4f); var two = ZoneOf(planets, (29.2f, new float2(-300f, 0f)), (14152.4f, new float2(300f, 0f))); var c0 = planets.WellStrength.Evaluate(29.2f); - var core0 = planets.CoreRadius.Evaluate(29.2f); + var core0 = planets.RocheLimit.Evaluate(29.2f); var c1 = planets.WellStrength.Evaluate(14152.4f); - var core1 = planets.CoreRadius.Evaluate(14152.4f); + var core1 = planets.RocheLimit.Evaluate(14152.4f); const float step = .5f; // Inside the two cores as well, out to their outer bands (0.5 R to R), where the potential is the quadratic bowl. var inCore = new[] @@ -352,7 +340,7 @@ public sealed class PotentialOwnerTests : IDisposable { var zone = ZoneOf(planets, (mass, float2.zero)); var c = planets.WellStrength.Evaluate(mass); - var core = planets.CoreRadius.Evaluate(mass); + var core = planets.RocheLimit.Evaluate(mass); foreach (var fraction in new[] { .5f, .75f, .9f, .95f, .98f, .99f, .996f }) foreach (var angle in new[] { 0f, 2.3f }) { @@ -371,7 +359,7 @@ public sealed class PotentialOwnerTests : IDisposable foreach (var mass in new[] { 29.2f, 14152.4f }) { var zone = ZoneOf(planets, (mass, float2.zero)); - var core = planets.CoreRadius.Evaluate(mass); + var core = planets.RocheLimit.Evaluate(mass); var inside = new float2(core * (1f - 1e-3f), 0); var outside = new float2(core * (1f + 1e-3f), 0); Assert.InRange(abs(zone.GetHeight(inside) - zone.GetHeight(outside)), 0f, abs(zone.GetHeight(outside)) * 1e-3f); diff --git a/tests/Aetheria.Shared.Tests/WellFixture.cs b/tests/Aetheria.Shared.Tests/WellFixture.cs index 0b895e4c0..54237862d 100644 --- a/tests/Aetheria.Shared.Tests/WellFixture.cs +++ b/tests/Aetheria.Shared.Tests/WellFixture.cs @@ -3,8 +3,8 @@ using GameCult.Caching; // The one fixture that gives a test zone a slope: a body on a parentless orbit (the origin unless `at` says otherwise; call again for more bodies), with the // curves a body needs. Gravity is the sum of body wells (GravityField), so a test that wants ground to slide on -// digs it here and nowhere else. `strength` is the well's c (u^2/s^2) and `coreRadius` its softened core in u; the -// Roche limit curve sits at 2.5 cores so the body is a valid well. +// digs it here and nowhere else. `strength` is the well's c (u^2/s^2) and `coreRadius` its softened core in u, which is +// the Roche limit curve (the one curve of a body's core). internal static class WellFixture { public static void Dig(CultCache cache, ZonePack pack, PlanetSettings settings, float strength, float coreRadius, float2 at = default) @@ -12,8 +12,7 @@ internal static class WellFixture settings.BodyRadius = new ExponentialCurve(); settings.OrbitPeriod = new ExponentialCurve(); settings.WellStrength = new ExponentialCurve { Constant = strength }; - settings.CoreRadius = new ExponentialCurve { Constant = coreRadius }; - settings.RocheLimit = new ExponentialCurve { Constant = 2.5f * coreRadius }; + settings.RocheLimit = new ExponentialCurve { Constant = coreRadius }; var orbit = cache.Upsert(new OrbitData { FixedPosition = at }).Key; var body = cache.Upsert(new PlanetData { Name = $"Well {at.x},{at.y}", Orbit = new CultRecordRef(orbit) }).Key; pack.Orbits.Add(new CultRecordRef(orbit)); diff --git a/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs b/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs index bdf8822d3..e9673c3f5 100644 --- a/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs +++ b/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs @@ -38,15 +38,14 @@ public sealed class ZonePlacedAtBuildTests : IDisposable private static ExponentialCurve Flat(float v) => new ExponentialCurve { Constant = v }; - // One planet with a well (c 100, core 20 u, Roche limit 30 u), a fixed root orbit at RootAt and the + // One planet with a well (c 100, Roche limit and core 20 u), a fixed root orbit at RootAt and the // planet orbiting it at Distance from `phase`. Every orbit period is Period seconds. private static PlanetSettings Settings() => new PlanetSettings { OrbitPeriod = Flat(Period), BodyRadius = Flat(20f), WellStrength = Flat(100f), - CoreRadius = Flat(20f), - RocheLimit = Flat(30f), + RocheLimit = Flat(20f), LightRadius = Flat(0f) };