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:
commit
faa05eec83
7 changed files with 127 additions and 3 deletions
|
|
@ -11,6 +11,7 @@ GameObject:
|
|||
- component: {fileID: 3040023561780424834}
|
||||
- component: {fileID: 8539532519029615782}
|
||||
- component: {fileID: 4655154266675363797}
|
||||
- component: {fileID: 2914522964471179774}
|
||||
m_Layer: 11
|
||||
m_Name: Fog Patch
|
||||
m_TagString: Untagged
|
||||
|
|
@ -25,13 +26,13 @@ Transform:
|
|||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 791530951415938407}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0.7071068, y: -0, z: -0, w: 0.7071068}
|
||||
m_LocalPosition: {x: -3148.4, y: -253.6, z: -1108.1}
|
||||
m_LocalScale: {x: 1513.8295, y: 1513.8295, z: 1513.8295}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
|
||||
--- !u!33 &8539532519029615782
|
||||
MeshFilter:
|
||||
|
|
@ -58,6 +59,11 @@ MeshRenderer:
|
|||
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:
|
||||
|
|
@ -79,7 +85,22 @@ MeshRenderer:
|
|||
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}
|
||||
--- !u!114 &2914522964471179774
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 791530951415938407}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: a792b8f456004d04997a26557b338d1c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::VapourCloudInstance
|
||||
PatchHeight: -5
|
||||
|
|
|
|||
|
|
@ -16227,6 +16227,8 @@ MonoBehaviour:
|
|||
type: 3}
|
||||
MinePrefab: {fileID: 7283754118921506074, guid: b04728b2b65e057429eb6e8529299c8a,
|
||||
type: 3}
|
||||
CloudPrefab: {fileID: 2914522964471179774, guid: 4084aa3d08e52e04f880ad13daa409b4,
|
||||
type: 3}
|
||||
MapGravityMaterials:
|
||||
- {fileID: 2100000, guid: 841e4091d19548347bd59115047b4e49, type: 2}
|
||||
- {fileID: 2100000, guid: a92fc6d958edb9f46b6e58134f609cc0, type: 2}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
44
Assets/Scripts/Zone Display/VapourCloudInstance.cs
Normal file
44
Assets/Scripts/Zone Display/VapourCloudInstance.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Zone Display/VapourCloudInstance.cs.meta
Normal file
2
Assets/Scripts/Zone Display/VapourCloudInstance.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a792b8f456004d04997a26557b338d1c
|
||||
|
|
@ -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();
|
||||
|
|
|
|||
29
tests/Aetheria.Shared.Tests/DrawAheadTests.cs
Normal file
29
tests/Aetheria.Shared.Tests/DrawAheadTests.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using Xunit;
|
||||
using float2 = CultMath.float2;
|
||||
|
||||
// DrawAhead draws a free body where the frame falls lead sim seconds after the last step, by the velocity that step
|
||||
// moved it with. Expected values are worked from first principles: position plus launch velocity and drift, times lead.
|
||||
public sealed class DrawAheadTests
|
||||
{
|
||||
[Fact]
|
||||
public void ABodyIsDrawnAheadByItsTotalVelocity()
|
||||
{
|
||||
var body = new KinematicBody { Position = new float2(10f, 20f), Velocity = new float2(3f, -1f), Drift = new float2(.5f, 2f) };
|
||||
|
||||
var drawn = DrawAhead.Position(body, .5f);
|
||||
|
||||
Assert.Equal(10f + (3f + .5f) * .5f, drawn.x, 4);
|
||||
Assert.Equal(20f + (-1f + 2f) * .5f, drawn.y, 4);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ABodyDrawnWithNoLeadIsWhereTheSimPutIt()
|
||||
{
|
||||
var body = new KinematicBody { Position = new float2(10f, 20f), Velocity = new float2(3f, -1f), Drift = new float2(.5f, 2f) };
|
||||
|
||||
var drawn = DrawAhead.Position(body, 0f);
|
||||
|
||||
Assert.Equal(10f, drawn.x, 4);
|
||||
Assert.Equal(20f, drawn.y, 4);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue