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 <noreply@anthropic.com>
This commit is contained in:
parent
ff63362f45
commit
021c4cbcbf
16 changed files with 433 additions and 171 deletions
|
|
@ -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<OrbitData>(orbit));
|
||||
pack.Planets.Add(new CultRecordRef<BodyData>(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<float> { 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<float> { 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<int>();
|
||||
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<int> KeysOf(System.Type type)
|
||||
{
|
||||
var keys = new System.Collections.Generic.List<int>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue