Merge cut vapour-cloud-presenter (Soul verdict cut-vapour-cloud-presenter.s2)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-12 06:39:33 +02:00
commit faa05eec83
7 changed files with 127 additions and 3 deletions

View file

@ -19,6 +19,10 @@ public static class DrawAhead
? entity.Position
: entity.Position + float3(entity.Velocity.x, 0, entity.Velocity.y) * lead;
// A free body (a vapour cloud) drawn where the frame falls lead sim seconds after the last step, by the velocity
// that step moved it with: the launch velocity and the drift together.
public static float2 Position(KinematicBody body, float lead) => body.Position + body.TotalVelocity * lead;
// The ship's rotation turned about its own up axis by the rate its last step turned, for lead seconds.
public static quaternion Rotation(Ship ship, float lead) =>
ship.WormholeAnimationInProgress ? ship.Rotation : Turned(ship.Rotation, ship.TurnRate * lead);

View file

@ -0,0 +1,44 @@
using CultMath;
using CultMath.UnityBridge;
using UnityEngine;
// How one vented vapour cloud looks: a fog-bank brush painted into the Patch layer, which the volumetric pass reads as
// patch thickness. Zone owns every cloud fact (existence, body, radius, opacity); this reads them and draws, and writes
// nothing back (rulings vapour-cloud-obscuration, unity-presents-only-r3). The brush's depth scales with the sim's OpacityAt, so the bank fades to nothing at the cloud's lifetime.
public class VapourCloudInstance : MonoBehaviour
{
// The world height the scene's patch brushes sit at (Depth Micro), inside the Patch camera's clip range.
public float PatchHeight = -5f;
private static readonly int Depth = Shader.PropertyToID("_Depth");
private Zone _zone;
private VapourCloud _cloud;
private MeshRenderer _renderer;
private MaterialPropertyBlock _block;
private float _authoredDepth;
public void Bind(Zone zone, VapourCloud cloud)
{
_zone = zone;
_cloud = cloud;
_renderer = GetComponent<MeshRenderer>();
_block = new MaterialPropertyBlock();
_authoredDepth = _renderer.sharedMaterial.GetFloat(Depth);
Place();
}
private void Update() => Place();
private void Place()
{
var p = DrawAhead.Position(_cloud.Body, ActionGameManager.Clock.Lead);
transform.position = new Vector3(p.x, PatchHeight, p.y);
transform.localScale = Vector3.one * (2f * _cloud.Radius);
// The sim's own opacity, already saturated to 0..1 (VapourCloud.OpacityAt); the presenter adds no rule of its own.
_renderer.GetPropertyBlock(_block);
_block.SetFloat(Depth, _authoredDepth * _cloud.OpacityAt(_zone.Time));
_renderer.SetPropertyBlock(_block);
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: a792b8f456004d04997a26557b338d1c

View file

@ -45,6 +45,7 @@ public class ZoneRenderer : MonoBehaviour
public GridObject GearPickup;
public GridObject WeaponPickup;
public MineInstance MinePrefab;
public VapourCloudInstance CloudPrefab;
public Material[] MapGravityMaterials;
[Header("Tour")] public bool Tour;
@ -95,6 +96,7 @@ public class ZoneRenderer : MonoBehaviour
public Dictionary<Wormhole, (GameObject gravity, CompassIcon icon)> WormholeInstances = new Dictionary<Wormhole, (GameObject, CompassIcon)>();
private List<ItemPickup> _loot = new List<ItemPickup>();
private Dictionary<Mine, MineInstance> _mines = new Dictionary<Mine, MineInstance>();
private Dictionary<VapourCloud, VapourCloudInstance> _clouds = new Dictionary<VapourCloud, VapourCloudInstance>();
public Zone Zone { get; private set; }
public ItemManager ItemManager { get; set; }
@ -234,6 +236,15 @@ public class ZoneRenderer : MonoBehaviour
instance.Blast();
}));
// Every vapour cloud, whoever vented it, is drawn through this one subscription. A cloud leaves Zone.Clouds
// when its opacity has reached nothing, so a removal destroys its fog bank with nothing left to show.
foreach (var cloud in zone.Clouds) LoadCloud(zone, cloud);
_zoneSubscriptions.Add(zone.Clouds.ObserveAdd().Subscribe(e => LoadCloud(zone, e.Value)));
_zoneSubscriptions.Add(zone.Clouds.ObserveRemove().Subscribe(e =>
{
if (_clouds.Remove(e.Value, out var instance)) Destroy(instance.gameObject);
}));
if (zone.GalaxyZone != null)
{
foreach (var adjacentZone in zone.GalaxyZone.AdjacentZones)
@ -263,6 +274,13 @@ public class ZoneRenderer : MonoBehaviour
_mines.Add(mine, instance);
}
private void LoadCloud(Zone zone, VapourCloud cloud)
{
var instance = Instantiate(CloudPrefab);
instance.Bind(zone, cloud);
_clouds.Add(cloud, instance);
}
public void AddWormhole(Wormhole wormhole)
{
var instance = Instantiate(WormholePrefab);
@ -290,6 +308,10 @@ public class ZoneRenderer : MonoBehaviour
if (instance) Destroy(instance.gameObject);
_mines.Clear();
foreach (var instance in _clouds.Values)
if (instance) Destroy(instance.gameObject);
_clouds.Clear();
foreach(var gridObject in _loot)
if(gridObject) Destroy(gridObject.gameObject);
_loot.Clear();