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>
77 lines
No EOL
2.2 KiB
C#
77 lines
No EOL
2.2 KiB
C#
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
using GameCult.Caching;
|
|
using System;
|
|
using System.Linq;
|
|
using MessagePack;
|
|
using Newtonsoft.Json;
|
|
using CultMath;
|
|
using static CultMath.math;
|
|
|
|
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
|
public class MiningToolData : BehaviorData
|
|
{
|
|
[Inspectable, JsonProperty("dps"), Key(1)]
|
|
public PerformanceStat DamagePerSecond = new PerformanceStat();
|
|
|
|
[Inspectable, JsonProperty("efficiency"), Key(2)]
|
|
public PerformanceStat Efficiency = new PerformanceStat();
|
|
|
|
[Inspectable, JsonProperty("penetration"), Key(3)]
|
|
public PerformanceStat Penetration = new PerformanceStat();
|
|
|
|
[Inspectable, JsonProperty("range"), Key(4)]
|
|
public PerformanceStat Range = new PerformanceStat();
|
|
|
|
public override Behavior CreateInstance(EquippedItem item)
|
|
{
|
|
return new MiningTool(this, item);
|
|
}
|
|
public override Behavior CreateInstance(ConsumableItemEffect item)
|
|
{
|
|
return new MiningTool(this, item);
|
|
}
|
|
}
|
|
|
|
public class MiningTool : Behavior
|
|
{
|
|
public CultRecordKey AsteroidBelt;
|
|
public int Asteroid;
|
|
|
|
private MiningToolData _data;
|
|
public float Range { get; private set; }
|
|
|
|
public MiningTool(MiningToolData data, EquippedItem item) : base(data, item)
|
|
{
|
|
_data = data;
|
|
}
|
|
|
|
public MiningTool(MiningToolData data, ConsumableItemEffect item) : base(data, item)
|
|
{
|
|
_data = data;
|
|
}
|
|
|
|
public override bool Execute(float dt)
|
|
{
|
|
Range = Evaluate(_data.Range);
|
|
if (!AsteroidBelt.IsSet() || !Entity.Zone.AsteroidExists(AsteroidBelt, Asteroid))
|
|
return false;
|
|
|
|
var pose = Entity.Zone.ChunkPose(AsteroidBelt, Asteroid);
|
|
if (length(Entity.Position.xz - pose.xy) - pose.w < Range)
|
|
{
|
|
Entity.Zone.MineAsteroid(
|
|
Entity,
|
|
AsteroidBelt,
|
|
Asteroid,
|
|
Evaluate(_data.DamagePerSecond) * dt,
|
|
Evaluate(_data.Efficiency),
|
|
Evaluate(_data.Penetration));
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} |