Query asteroid render poses from daemon state
This commit is contained in:
parent
ff02979056
commit
b353652316
6 changed files with 246 additions and 35 deletions
|
|
@ -2693,7 +2693,6 @@ public class ActionGameManager : MonoBehaviour
|
|||
if (!_authoritativeDaemonEntities.TryGetValue(entitySnapshot.RecordKey, out var entity))
|
||||
continue;
|
||||
|
||||
entity.DaemonRecordKey = entitySnapshot.RecordKey ?? "";
|
||||
entity.DaemonEntityIndex = EntityIndexFromRecordKey(entitySnapshot.RecordKey);
|
||||
entity.Name = entitySnapshot.Name ?? "";
|
||||
entity.CultPosition = new CultMath.float3((float)entitySnapshot.PositionX, (float)entitySnapshot.PositionY, (float)entitySnapshot.PositionZ);
|
||||
|
|
@ -2768,7 +2767,6 @@ public class ActionGameManager : MonoBehaviour
|
|||
entity.OverrideShutdown = entitySnapshot.OverrideShutdown;
|
||||
entity.TractorPower = (float)entitySnapshot.TractorPower;
|
||||
entity.RestoreActiveState(entitySnapshot.IsActive);
|
||||
entity.DaemonRecordKey = entitySnapshot.RecordKey ?? "";
|
||||
entity.DaemonEntityIndex = EntityIndexFromRecordKey(entitySnapshot.RecordKey);
|
||||
entity.Zone = Zone;
|
||||
Zone.Entities.Add(entity);
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ public abstract class Entity
|
|||
public Faction Faction;
|
||||
public EquippableItem Hull;
|
||||
public EquippedItem EquippedHull;
|
||||
public string DaemonRecordKey = "";
|
||||
public int DaemonEntityIndex = -1;
|
||||
|
||||
public float3 Position;
|
||||
|
|
|
|||
|
|
@ -795,9 +795,15 @@ public class DaemonRuntimeDocumentTests
|
|||
{
|
||||
new AetheriaRuntimeOrbitSnapshotCommit
|
||||
{
|
||||
OrbitKey = "orbit:belt",
|
||||
OrbitKey = "orbit:parent",
|
||||
FixedPositionX = 11,
|
||||
FixedPositionY = -4
|
||||
},
|
||||
new AetheriaRuntimeOrbitSnapshotCommit
|
||||
{
|
||||
OrbitKey = "orbit:belt",
|
||||
ParentOrbitKey = "orbit:parent",
|
||||
Distance = 30
|
||||
}
|
||||
},
|
||||
Bodies = new[]
|
||||
|
|
@ -834,6 +840,84 @@ public class DaemonRuntimeDocumentTests
|
|||
Assert.AreEqual(3, poses[0].AsteroidCount);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DaemonRenderQueriesPublishAsteroidInstancePosesForVisibleBelt()
|
||||
{
|
||||
var zone = new AetheriaRuntimeZoneSnapshotCommit
|
||||
{
|
||||
Orbits = new[]
|
||||
{
|
||||
new AetheriaRuntimeOrbitSnapshotCommit
|
||||
{
|
||||
OrbitKey = "orbit:parent",
|
||||
FixedPositionX = 10,
|
||||
FixedPositionY = 20
|
||||
},
|
||||
new AetheriaRuntimeOrbitSnapshotCommit
|
||||
{
|
||||
OrbitKey = "orbit:belt",
|
||||
ParentOrbitKey = "orbit:parent",
|
||||
Distance = 100
|
||||
}
|
||||
},
|
||||
Bodies = new[]
|
||||
{
|
||||
new AetheriaRuntimeBodySnapshotCommit
|
||||
{
|
||||
BodyKey = "body:belt",
|
||||
OrbitKey = "orbit:belt",
|
||||
Kind = "asteroid_belt",
|
||||
Asteroids = new[]
|
||||
{
|
||||
new AetheriaRuntimeAsteroidCommit
|
||||
{
|
||||
Distance = 5,
|
||||
Phase = 0,
|
||||
Size = 2,
|
||||
RotationSpeed = 3
|
||||
},
|
||||
new AetheriaRuntimeAsteroidCommit
|
||||
{
|
||||
Distance = 7,
|
||||
Phase = 0.25,
|
||||
Size = 4,
|
||||
Damage = 1,
|
||||
RotationSpeed = 2
|
||||
},
|
||||
new AetheriaRuntimeAsteroidCommit
|
||||
{
|
||||
Distance = 11,
|
||||
Phase = 0.5,
|
||||
Size = 9,
|
||||
RespawnTimer = 12
|
||||
}
|
||||
}
|
||||
},
|
||||
new AetheriaRuntimeBodySnapshotCommit
|
||||
{
|
||||
BodyKey = "body:other",
|
||||
OrbitKey = "orbit:belt",
|
||||
Kind = "asteroid_belt",
|
||||
Asteroids = new[] { new AetheriaRuntimeAsteroidCommit { Distance = 99, Size = 99 } }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var poses = AetheriaRuntimeDaemonRenderQueries.QueryAsteroidInstancePoses(zone, "body:belt", 4);
|
||||
|
||||
Assert.AreEqual(3, poses.Length);
|
||||
Assert.AreEqual("body:belt", poses[0].BodyKey);
|
||||
Assert.AreEqual(0, poses[0].AsteroidIndex);
|
||||
Assert.AreEqual(15, poses[0].PositionX, 0.0001);
|
||||
Assert.AreEqual(20, poses[0].PositionZ, 0.0001);
|
||||
Assert.AreEqual(12, poses[0].Rotation, 0.0001);
|
||||
Assert.AreEqual(2, poses[0].Size, 0.0001);
|
||||
Assert.AreEqual(10, poses[1].PositionX, 0.0001);
|
||||
Assert.AreEqual(27, poses[1].PositionZ, 0.0001);
|
||||
Assert.AreEqual(3, poses[1].Size, 0.0001);
|
||||
Assert.AreEqual(0, poses[2].Size, 0.0001);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SoaViewIndexRejectsInvalidRenderGroups()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -68,8 +68,6 @@ public class ZoneRenderer : MonoBehaviour
|
|||
[HideInInspector] public Dictionary<Entity, EntityInstance> EntityInstances = new Dictionary<Entity, EntityInstance>();
|
||||
[HideInInspector] public Dictionary<string, PlanetObject> Planets = new Dictionary<string, PlanetObject>(StringComparer.Ordinal);
|
||||
|
||||
private readonly Dictionary<string, EntityInstance> _entityInstancesByDaemonKey =
|
||||
new Dictionary<string, EntityInstance>(StringComparer.Ordinal);
|
||||
private Dictionary<string, AsteroidBeltUI> _beltObjects = new Dictionary<string, AsteroidBeltUI>(StringComparer.Ordinal);
|
||||
private Dictionary<string, InstancedMesh[]> _beltMeshes = new Dictionary<string, InstancedMesh[]>(StringComparer.Ordinal);
|
||||
private Dictionary<string, Matrix4x4[][]> _beltMatrices = new Dictionary<string, Matrix4x4[][]>(StringComparer.Ordinal);
|
||||
|
|
@ -94,6 +92,8 @@ public class ZoneRenderer : MonoBehaviour
|
|||
new List<AetheriaRuntimeDaemonAsteroidBeltPose>();
|
||||
private readonly Dictionary<string, AetheriaRuntimeDaemonAsteroidBeltPose> _daemonAsteroidBeltPosesByBodyKey =
|
||||
new Dictionary<string, AetheriaRuntimeDaemonAsteroidBeltPose>(StringComparer.Ordinal);
|
||||
private readonly List<AetheriaRuntimeDaemonAsteroidInstancePose> _visibleAsteroidInstancePoses =
|
||||
new List<AetheriaRuntimeDaemonAsteroidInstancePose>();
|
||||
|
||||
public Dictionary<Wormhole, (GameObject gravity, CompassIcon icon)> WormholeInstances = new Dictionary<Wormhole, (GameObject, CompassIcon)>();
|
||||
private List<ItemPickup> _loot = new List<ItemPickup>();
|
||||
|
|
@ -329,8 +329,6 @@ public class ZoneRenderer : MonoBehaviour
|
|||
instance.SetEntity(this, entity);
|
||||
|
||||
EntityInstances.Add(entity, instance);
|
||||
if (!string.IsNullOrWhiteSpace(entity.DaemonRecordKey))
|
||||
_entityInstancesByDaemonKey[entity.DaemonRecordKey] = instance;
|
||||
}
|
||||
|
||||
public void UnloadEntity(Entity entity)
|
||||
|
|
@ -349,8 +347,6 @@ public class ZoneRenderer : MonoBehaviour
|
|||
|
||||
Destroy(instance.gameObject);
|
||||
EntityInstances.Remove(entity);
|
||||
if (!string.IsNullOrWhiteSpace(entity.DaemonRecordKey))
|
||||
_entityInstancesByDaemonKey.Remove(entity.DaemonRecordKey);
|
||||
}
|
||||
|
||||
void LoadAsteroidBelt(AsteroidBelt runtimeBelt)
|
||||
|
|
@ -486,25 +482,41 @@ public class ZoneRenderer : MonoBehaviour
|
|||
|
||||
var center = new float2((float)beltPose.CenterX, (float)beltPose.CenterZ);
|
||||
var height = GetTerrainHeight(center);
|
||||
if(isVisible(new Bounds(
|
||||
var beltIsVisible = isVisible(new Bounds(
|
||||
new Vector3(center.x,height,center.y),
|
||||
new Vector3((float)beltPose.Radius * 2,100,(float)beltPose.Radius * 2))))
|
||||
new Vector3((float)beltPose.Radius * 2,100,(float)beltPose.Radius * 2)));
|
||||
if (beltIsVisible || _showAsteroidUI)
|
||||
{
|
||||
AetheriaRuntimeDaemonRenderQueries.QueryAsteroidInstancePoses(
|
||||
_daemonZoneSnapshot,
|
||||
key,
|
||||
Zone?.Time ?? 0,
|
||||
_visibleAsteroidInstancePoses);
|
||||
}
|
||||
|
||||
if(beltIsVisible)
|
||||
{
|
||||
var meshes = _beltMeshes[key];
|
||||
var matrices = _beltMatrices[key];
|
||||
var count = belt.Transforms.Length / meshes.Length;
|
||||
var tx = 0;
|
||||
for (int i = 0; i < meshes.Length; i++)
|
||||
{
|
||||
for (int t = 0; t < matrices[i].Length; t++)
|
||||
{
|
||||
var tx = t + i * count;
|
||||
var transform = belt.Transforms[tx];
|
||||
matrices[i][t] = Matrix4x4.TRS(new Vector3(transform.x,0,transform.y),
|
||||
if (tx >= _visibleAsteroidInstancePoses.Count)
|
||||
{
|
||||
matrices[i][t] = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.zero);
|
||||
continue;
|
||||
}
|
||||
|
||||
var asteroidPose = _visibleAsteroidInstancePoses[tx];
|
||||
matrices[i][t] = Matrix4x4.TRS(new Vector3((float)asteroidPose.PositionX,0,(float)asteroidPose.PositionZ),
|
||||
Quaternion.Euler(
|
||||
cos(transform.z + (float)i / meshes.Length) * 100,
|
||||
sin(transform.z + (float)i / meshes.Length) * 100,
|
||||
(float)tx / belt.Transforms.Length * 360),
|
||||
Vector3.one * transform.w);
|
||||
cos((float)asteroidPose.Rotation + (float)i / meshes.Length) * 100,
|
||||
sin((float)asteroidPose.Rotation + (float)i / meshes.Length) * 100,
|
||||
(float)tx / Math.Max(1, _visibleAsteroidInstancePoses.Count) * 360),
|
||||
Vector3.one * (float)asteroidPose.Size);
|
||||
tx++;
|
||||
}
|
||||
|
||||
Graphics.DrawMeshInstanced(meshes[i].Mesh, 0, meshes[i].Material, matrices[i]);
|
||||
|
|
@ -512,7 +524,7 @@ public class ZoneRenderer : MonoBehaviour
|
|||
}
|
||||
|
||||
if(_showAsteroidUI)
|
||||
_beltObjects[key].Update(belt.Transforms, center, height, (float)beltPose.Radius);
|
||||
_beltObjects[key].Update(_visibleAsteroidInstancePoses, center, height, (float)beltPose.Radius);
|
||||
}
|
||||
|
||||
foreach (var planet in Planets)
|
||||
|
|
@ -736,17 +748,24 @@ public class AsteroidBeltUI
|
|||
//_collider.sharedMesh = _mesh;
|
||||
}
|
||||
|
||||
public void Update(float4[] transforms, float2 center, float height, float radius)
|
||||
public void Update(IReadOnlyList<AetheriaRuntimeDaemonAsteroidInstancePose> poses, float2 center, float height, float radius)
|
||||
{
|
||||
for (var i = 0; i < transforms.Length; i++)
|
||||
var count = Math.Min(poses.Count, _vertices.Length / 4);
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var transform = transforms[i];
|
||||
var rotation = Quaternion.Euler(90, transform.z, 0);
|
||||
var position = new Vector3(transform.x, height, transform.y);
|
||||
_vertices[i * 4] = rotation * new Vector3(-transform.w * _scale, -transform.w * _scale, 0) + position;
|
||||
_vertices[i * 4 + 1] = rotation * new Vector3(-transform.w * _scale, transform.w * _scale, 0) + position;
|
||||
_vertices[i * 4 + 2] = rotation * new Vector3(transform.w * _scale, transform.w * _scale, 0) + position;
|
||||
_vertices[i * 4 + 3] = rotation * new Vector3(transform.w * _scale, -transform.w * _scale, 0) + position;
|
||||
var pose = poses[i];
|
||||
var size = (float)pose.Size;
|
||||
var rotation = Quaternion.Euler(90, (float)pose.Rotation, 0);
|
||||
var position = new Vector3((float)pose.PositionX, height, (float)pose.PositionZ);
|
||||
_vertices[i * 4] = rotation * new Vector3(-size * _scale, -size * _scale, 0) + position;
|
||||
_vertices[i * 4 + 1] = rotation * new Vector3(-size * _scale, size * _scale, 0) + position;
|
||||
_vertices[i * 4 + 2] = rotation * new Vector3(size * _scale, size * _scale, 0) + position;
|
||||
_vertices[i * 4 + 3] = rotation * new Vector3(size * _scale, -size * _scale, 0) + position;
|
||||
}
|
||||
|
||||
for (var i = count * 4; i < _vertices.Length; i++)
|
||||
{
|
||||
_vertices[i] = Vector3.zero;
|
||||
}
|
||||
|
||||
var boundsRadius = Math.Max(_size, radius);
|
||||
|
|
|
|||
Loading…
Reference in a new issue