Merge eureka/aetheria-gravity-gravity-subtract

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-14 23:11:47 +02:00
commit 5dd1f6b71f
22 changed files with 407 additions and 425 deletions

View file

@ -15,7 +15,6 @@ public class GameSettings : ScriptableObject
public float HeatstrokePhasingFrequency = 5;
public float WormholeDistanceRatio;
public float DefaultViewDistance;
public float MinimapZoneGravityRange;
public float[] MinimapZoomLevels;
public int DefaultMinimapZoom;
public ExponentialCurve IconSize;

View file

@ -13,15 +13,8 @@ using static CultMath.math;
[Serializable, MessagePackObject(keyAsPropertyName:true), JsonObject]
public class PlanetSettings
{
public float ZoneDepthExponent;
public float ZoneDepth;
public float ZoneBoundaryFog;
public ExponentialCurve GravityDepth;
public ExponentialCurve GravityRadius;
public ExponentialCurve WaveDepth;
public ExponentialCurve WaveRadius;
public ExponentialCurve WaveFrequency;
public ExponentialCurve WaveSpeed;
public ExponentialCurve LightRadius;
public ExponentialCurve BodyRadius;
public float AsteroidVerticalOffset = -5f;

View file

@ -161,6 +161,12 @@ public class Zone
Orbits.Add(orbit.Key, new Orbit(Settings, cache.Get(orbit)));
}
// Aetheria gravity (target invariant zone-valid-before-tick): every orbit is placed at the pack's time
// when the zone is built, so each well, light and body pose read before the first Update is where the
// body is. Velocity stays zero until the first Update differences two placed positions.
foreach (var orbit in Orbits)
GetOrbitPosition(orbit.Key);
foreach (var body in pack.Planets)
{
var planet = cache.Get(body);
@ -266,18 +272,16 @@ public class Zone
private bool IsExpired(ChunkWear wear) => wear.Damage <= 0f && (!wear.BrokenUntil.HasValue || wear.BrokenUntil.Value <= _time);
public void AddOrbit(OrbitData orbit)
{
Orbits.Add(_itemManager.ItemData.RefOf(orbit).Key, new Orbit(Settings, orbit));
}
public void Update(float deltaTime)
{
_time += deltaTime;
_updatedOrbits.Clear();
// Every previous position is taken before any orbit is placed: GetOrbitPosition places a parent as a
// side effect of placing its child, so differencing inside one loop would depend on dictionary order.
foreach (var orbit in Orbits)
orbit.Value.PreviousPosition = orbit.Value.Position;
foreach (var orbit in Orbits)
{
orbit.Value.PreviousPosition = orbit.Value.Position;
orbit.Value.Position = GetOrbitPosition(orbit.Key);
orbit.Value.Velocity = (orbit.Value.Position - orbit.Value.PreviousPosition) / deltaTime;
}
@ -591,26 +595,6 @@ public class Zone
into[i] = beltInstance.Pose(i, _time, parentPosition, Settings, ChunkRadius(new ChunkId(belt, i)));
}
public OrbitData CreateOrbit(CultRecordKey parent, float2 position)
{
var parentPosition = GetOrbitPosition(parent);
var delta = position - parentPosition;
var distance = length(delta);
var period = Settings.OrbitPeriod.Evaluate(distance);
var phase = atan2(delta.y, delta.x) / (PI * 2);
var currentPhase = frac(_time / period);
var storedPhase = (float) frac(phase - currentPhase);
var orbit = new OrbitData
{
Distance = distance,
Parent = new CultRecordRef<OrbitData>(parent),
Phase = storedPhase
};
Orbits.Add(_itemManager.ItemData.Upsert(orbit).Key, new Orbit(Settings, orbit));
return orbit;
}
public SecurityLevel GetSecurityLevel(float2 pos)
{
if (GalaxyZone.Owner==null) return SecurityLevel.Open;
@ -630,7 +614,7 @@ public class Zone
public float GetHeight(float2 position)
{
var result = -PowerPulse(length(position)/(Pack.Radius*2), Settings.ZoneDepthExponent) * Settings.ZoneDepth;
var result = 0f;
foreach (var body in PlanetInstances.Values)
{
var p = position - body.Orbit.Position; //GetOrbitPosition(body.BodyData.Orbit)
@ -641,18 +625,6 @@ public class Zone
var depth = body.GravityWellDepth;
result -= PowerPulse(sqrt(distSqr) / gravityRadius, body.BodyData.GravityDepthExponent) * depth;
}
if (body is GasGiant gas)
{
var waveRadius = gas.GravityWavesRadius;
if(distSqr < waveRadius*waveRadius)
{
var depth = gas.GravityWavesDepth;
var frequency = Settings.WaveFrequency.Evaluate(body.BodyData.Mass);
var speed = gas.GravityWavesSpeed;
result -= RadialWaves(sqrt(distSqr) / waveRadius, 8, 1.25f, frequency, (float) (_time * speed)) * depth;
}
}
}
return result;
@ -716,12 +688,6 @@ public class Zone
return pow((x + 1) * (1 - x), exponent);
}
public static float RadialWaves(float x, float maskExponent, float sineExponent, float frequency, float phase)
{
//x *= 2;
return PowerPulse(x, maskExponent) * cos(pow(x*2, sineExponent) * frequency + phase);
}
public float3 GetNormal(float2 pos, float step = .1f, float mul = 1)
{
float hL = GetHeight(new float2(pos.x - step, pos.y)) * mul;
@ -763,22 +729,10 @@ public class Planet
public class GasGiant : Planet
{
public GasGiantData GasGiantData;
public float GravityWavesDepth;
public float GravityWavesRadius;
public float GravityWavesSpeed;
public GasGiant(PlanetSettings settings, GasGiantData data, Orbit orbit) : base(settings, data, orbit)
{
GasGiantData = data;
CalculateProperties();
}
public new void CalculateProperties()
{
base.CalculateProperties();
GravityWavesDepth = Settings.WaveDepth.Evaluate(BodyData.Mass) * GasGiantData.WaveDepthMultiplier;
GravityWavesRadius = Settings.WaveRadius.Evaluate(BodyData.Mass) * GasGiantData.WaveRadiusMultiplier;
GravityWavesSpeed = Settings.WaveSpeed.Evaluate(BodyData.Mass) * GasGiantData.WaveSpeedMultiplier;
}
}

View file

@ -186,18 +186,6 @@ public class GasGiantData : BodyData
[JsonProperty("albedoRotationSpeed"), Key(13)]
public float AlbedoRotationSpeed = 1;
[JsonProperty("gravRadiusMul")] [Key(14)]
public float WaveRadiusMultiplier = 1;
[JsonProperty("depthMul")] [Key(15)]
public float WaveDepthMultiplier = 1;
[JsonProperty("depthExp")] [Key(16)]
public float WaveDepthExponent = 8;
[JsonProperty("depthExp")] [Key(17)]
public float WaveSpeedMultiplier = 8;
[JsonProperty("materialOverrides"), Key(18)]
public List<string> MaterialOverrides = new List<string>();

View file

@ -9,5 +9,4 @@ using UnityEngine;
public class GasGiantObject : PlanetObject
{
public SunMaterial SunMaterial;
public MeshRenderer GravityWaves;
}

View file

@ -27,7 +27,6 @@ public class ZoneRenderer : MonoBehaviour
public GameSettings Settings;
public Transform ZoneRoot;
public Transform SectorBrushes;
public MeshRenderer SectorBoundaryBrush;
public CinemachineVirtualCamera SceneCamera;
public Camera[] FogCameras;
public Camera[] MinimapCameras;
@ -472,17 +471,12 @@ public class ZoneRenderer : MonoBehaviour
else planet = Instantiate(GasGiant, ZoneRoot);
var gas = (GasGiantObject) planet;
var gasGiant = Zone.PlanetInstances[key] as GasGiant;
gas.Body.material.SetTexture("_ColorRamp", gasGiantData.Colors.ToGradient(!(planetData is SunData)).ToTexture());
// gasGiantData.AlbedoRotationSpeed.Subscribe(f => gas.SunMaterial.AlbedoRotationSpeed = f);
// gasGiantData.FirstOffsetRotationSpeed.Subscribe(f => gas.SunMaterial.FirstOffsetRotationSpeed = f);
// gasGiantData.SecondOffsetRotationSpeed.Subscribe(f => gas.SunMaterial.SecondOffsetRotationSpeed = f);
// gasGiantData.FirstOffsetDomainRotationSpeed.Subscribe(f => gas.SunMaterial.FirstOffsetDomainRotationSpeed = f);
// gasGiantData.SecondOffsetDomainRotationSpeed.Subscribe(f => gas.SunMaterial.SecondOffsetDomainRotationSpeed = f);
gas.GravityWaves.transform.localScale = gasGiant.GravityWavesRadius * Vector3.one;
gas.GravityWaves.material.SetFloat("_Depth", gasGiant.GravityWavesDepth);
gas.GravityWaves.material.SetFloat("_Frequency", Settings.PlanetSettings.WaveFrequency.Evaluate(planetData.Mass));
//gas.WaveScroll.Speed = Properties.GravitySettings.WaveSpeed.Evaluate(f);
}
else
{
@ -584,8 +578,6 @@ public class ZoneRenderer : MonoBehaviour
planet.Value.Body.transform.localPosition = new Vector3(0, height + planetInstance.BodyRadius * 2, 0);
if (planet.Value is GasGiantObject gasGiantObject)
{
gasGiantObject.GravityWaves.material.SetFloat("_Phase",
Zone.Time * ((GasGiant) Zone.PlanetInstances[planet.Key]).GravityWavesSpeed);
if (!(planet.Value is SunObject))
{
var toParent = normalize(Zone.GetOrbitPosition(Zone.Orbits[planetInstance.BodyData.Orbit.Key].Data.Parent.Key) - p);
@ -618,19 +610,13 @@ public class ZoneRenderer : MonoBehaviour
}
//var fogPos = FogCameraParent.position;
SectorBoundaryBrush.material.SetFloat("_Power", Settings.PlanetSettings.ZoneDepthExponent);
SectorBoundaryBrush.material.SetFloat("_Depth", Settings.PlanetSettings.ZoneDepth + Settings.PlanetSettings.ZoneBoundaryFog);
var startDepth = Zone.PowerPulse(Settings.MinimapZoneGravityRange, Settings.PlanetSettings.ZoneDepthExponent) *
Settings.PlanetSettings.ZoneDepth;
var depthRange = Settings.PlanetSettings.ZoneDepth - startDepth + maxDepth;
var depthRange = Mathf.Max(maxDepth, 1f);
foreach (var mat in MapGravityMaterials)
{
mat.SetFloat("_StartDepth", startDepth);
mat.SetFloat("_StartDepth", 0f);
mat.SetFloat("_DepthRange", depthRange);
}
//Shader.SetGlobalFloat("_GridOffset", Settings.PlanetSettings.ZoneBoundaryFog);
// var gravPos = MinimapGravityQuad.transform.position;
// gravPos.y = -Settings.PlanetSettings.ZoneDepth - _maxDepth;
// MinimapGravityQuad.transform.position = gravPos;
// MinimapTintQuad.transform.position = gravPos - Vector3.up*10;
}