Cut 1: belts are evaluated when asked, not simulated every tick
Zone.Update no longer threads a per-belt Task.Run over a double-buffered Transforms/OrbitPosition pair. AsteroidBelt.Pose/Size are the one place a chunk pose is computed, a pure function of zone time; Zone.ChunkPose and Zone.EvaluateBelt read them at the zone's own time. MiningTool, ResourceScanner and ZoneRenderer (belt matrices and AsteroidBeltUI) all read through Zone instead of the deleted per-tick buffers; the renderer owns its own float4[] buffer, filled fresh every frame. Deleted: System.Threading/.Tasks usings, BeltUpdates, the wait loop, the per-belt copy+Task.Run, NearestAsteroid (dead/broken reader), the private UpdateAsteroidTransforms, and AsteroidBelt's four pose fields plus their allocations. ~65 lines, matching the cut map's estimate. miningprobe, densest zone of the operator's save (EAC-2265, 809 asteroids, 8 belts), rebuilt against this cut and rerun 10x each side: before (branch point, 8bd25f6f/e729e6d6): Zone.Update wall 541-3654 us/tick, CPU 120-391 us/tick (7 clean runs) 3/10 runs crashed: InvalidOperationException from Zone.GetOrbitPosition, the documented _updatedOrbits/Orbits data race between the main thread's Clear() and a belt Task.Run after (this commit): Zone.Update wall 95-185 us/tick, CPU 99-152 us/tick, in line with the 31-39 us "no belt work" baseline the map recorded -- belts are free per tick 0/10 races ChunkPose has no buffer to go stale: ~0.12 u of parent+asteroid motion is visible across one 17 ms tick instead of being one tick behind tests/Aetheria.Shared.Tests/MiningCut1Tests.cs (new, 260/260 suite green): ChunkPoseIsTheOrbitAtZoneTime, ChunkPoseDoesNotDependOnUpdateCadence, DamagedChunkShrinksAndABrokenOneHasNoSize -- each expected value is the closed-form orbit/size rule reimplemented in the test, never a call to AsteroidBelt.Pose/Size. Negative grep (Zone.cs, "Zone Display", ServerShared/Behaviors) for Task\.Run|System\.Threading|NewTransforms|\.Transforms\b|BeltUpdates| NearestAsteroid|\.OrbitPosition\b|NewOrbitPosition: one hit, the commented line in MineAsteroid that Cut 2 deletes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e729e6d6d5
commit
22a54ccbaf
5 changed files with 266 additions and 77 deletions
|
|
@ -72,6 +72,9 @@ public class ZoneRenderer : MonoBehaviour
|
|||
private Dictionary<CultRecordKey, AsteroidBeltUI> _beltObjects = new Dictionary<CultRecordKey, AsteroidBeltUI>();
|
||||
private Dictionary<CultRecordKey, InstancedMesh[]> _beltMeshes = new Dictionary<CultRecordKey, InstancedMesh[]>();
|
||||
private Dictionary<CultRecordKey, Matrix4x4[][]> _beltMatrices = new Dictionary<CultRecordKey, Matrix4x4[][]>();
|
||||
// Cut 1 (docs/mining-cut.md): the renderer's own buffer, filled from Zone.EvaluateBelt each frame. No pose
|
||||
// is stored on AsteroidBelt any more.
|
||||
private Dictionary<CultRecordKey, float4[]> _beltTransforms = new Dictionary<CultRecordKey, float4[]>();
|
||||
private float _viewDistance;
|
||||
//private float _maxDepth;
|
||||
private float _minimapDistance;
|
||||
|
|
@ -282,6 +285,7 @@ public class ZoneRenderer : MonoBehaviour
|
|||
_beltObjects.Clear();
|
||||
_beltMeshes.Clear();
|
||||
_beltMatrices.Clear();
|
||||
_beltTransforms.Clear();
|
||||
_tourPlanets.Clear();
|
||||
}
|
||||
}
|
||||
|
|
@ -343,6 +347,7 @@ public class ZoneRenderer : MonoBehaviour
|
|||
meshes.RemoveAt(Random.Range(0, meshes.Count));
|
||||
_beltMeshes[key] = meshes.ToArray();
|
||||
_beltMatrices[key] = new Matrix4x4[meshes.Count][];
|
||||
_beltTransforms[key] = new float4[beltData.Asteroids.Length];
|
||||
var count = beltData.Asteroids.Length / meshes.Count;
|
||||
var remainder = beltData.Asteroids.Length - count * meshes.Count;
|
||||
for (int i = 0; i < meshes.Count; i++)
|
||||
|
|
@ -446,25 +451,30 @@ public class ZoneRenderer : MonoBehaviour
|
|||
|
||||
foreach (var (key, belt) in Zone.AsteroidBelts)
|
||||
{
|
||||
var height = Zone.GetHeight(belt.OrbitPosition);
|
||||
// Cut 1 (docs/mining-cut.md): belts have no stored pose any more. The renderer fills its own buffer
|
||||
// from Zone.EvaluateBelt, at the current zone time, every frame.
|
||||
var orbitPosition = Zone.GetOrbitPosition(Zone.Orbits[belt.Data.Orbit.Key].Data.Parent.Key);
|
||||
var height = Zone.GetHeight(orbitPosition);
|
||||
var transforms = _beltTransforms[key];
|
||||
Zone.EvaluateBelt(key, transforms);
|
||||
if(isVisible(new Bounds(
|
||||
new Vector3(belt.OrbitPosition.x,height,belt.OrbitPosition.y),
|
||||
new Vector3(orbitPosition.x,height,orbitPosition.y),
|
||||
new Vector3(belt.Radius * 2,100,belt.Radius * 2))))
|
||||
{
|
||||
var meshes = _beltMeshes[key];
|
||||
var matrices = _beltMatrices[key];
|
||||
var count = belt.Transforms.Length / meshes.Length;
|
||||
var count = transforms.Length / meshes.Length;
|
||||
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];
|
||||
var transform = transforms[tx];
|
||||
matrices[i][t] = Matrix4x4.TRS(new Vector3(transform.x,0,transform.y),
|
||||
Quaternion.Euler(
|
||||
cos(transform.z + (float)i / meshes.Length) * 100,
|
||||
sin(transform.z + (float)i / meshes.Length) * 100,
|
||||
(float)tx / belt.Transforms.Length * 360),
|
||||
(float)tx / transforms.Length * 360),
|
||||
Vector3.one * transform.w);
|
||||
}
|
||||
|
||||
|
|
@ -473,7 +483,7 @@ public class ZoneRenderer : MonoBehaviour
|
|||
}
|
||||
|
||||
if(_showAsteroidUI)
|
||||
_beltObjects[key].Update(belt.Transforms, height);
|
||||
_beltObjects[key].Update(transforms, height);
|
||||
}
|
||||
|
||||
foreach (var planet in Planets)
|
||||
|
|
@ -659,7 +669,7 @@ public class AsteroidBeltUI
|
|||
|
||||
public void Update(float4[] transforms, float height)
|
||||
{
|
||||
var parentPosition = _belt.OrbitPosition;
|
||||
var parentPosition = _zone.GetOrbitPosition(_orbitParent);
|
||||
for (var i = 0; i < transforms.Length; i++)
|
||||
{
|
||||
var transform = transforms[i];
|
||||
|
|
|
|||
Loading…
Reference in a new issue