Zone: every writer of what the belt tasks read settles them first
Soul's F5 and F6. The asteroid-belt tasks read the clock, the orbits and each belt's damage and respawn state. Update advanced the clock before waiting on last tick's tasks (Soul measured 242k transforms placed for the next tick in 576 of 3000 ticks), MineAsteroid wrote damage and respawn state under a running task, CreateOrbit and AddOrbit wrote the orbits, and a task that threw stayed in the list, so Wait rethrew it on every tick after. SettleBelts waits for the tasks and clears the list even when one failed; Update settles before it advances the clock, and MineAsteroid, CreateOrbit and AddOrbit settle before they write. Tests: over 3000 ticks every asteroid of a belt is placed for the time of the tick that started its task; mining every asteroid of a belt, chipping and breaking each four times a tick for 1000 ticks, never races the task; a task that fails surfaces once and later ticks run clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
74d2cf8fc4
commit
f879527158
2 changed files with 91 additions and 4 deletions
|
|
@ -166,16 +166,29 @@ public class Zone
|
|||
|
||||
public void AddOrbit(OrbitData orbit)
|
||||
{
|
||||
SettleBelts();
|
||||
Orbits.Add(_itemManager.ItemData.RefOf(orbit).Key, new Orbit(Settings, orbit));
|
||||
}
|
||||
|
||||
// The asteroid belts' tasks read the clock, the orbits and each belt's damage and respawn state. Everything that
|
||||
// writes any of those settles the running tasks first. The list is cleared even when a task failed, so a failure
|
||||
// surfaces once, here, instead of on every later tick.
|
||||
private void SettleBelts()
|
||||
{
|
||||
try
|
||||
{
|
||||
Task.WaitAll(BeltUpdates.ToArray());
|
||||
}
|
||||
finally
|
||||
{
|
||||
BeltUpdates.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
SettleBelts();
|
||||
_time += deltaTime;
|
||||
// Last tick's belt tasks read the orbit cache; they finish before it is cleared.
|
||||
foreach (var t in BeltUpdates)
|
||||
t.Wait();
|
||||
BeltUpdates.Clear();
|
||||
_updatedOrbits.Clear();
|
||||
foreach (var orbit in Orbits)
|
||||
{
|
||||
|
|
@ -308,6 +321,7 @@ public class Zone
|
|||
var currentPhase = frac(_time / period);
|
||||
var storedPhase = (float) frac(phase - currentPhase);
|
||||
|
||||
SettleBelts();
|
||||
var orbit = new OrbitData
|
||||
{
|
||||
Distance = distance,
|
||||
|
|
@ -320,6 +334,7 @@ public class Zone
|
|||
|
||||
public void MineAsteroid(Entity miner, CultRecordKey asteroidBelt, int asteroid, float damage, float efficiency, float penetration)
|
||||
{
|
||||
SettleBelts();
|
||||
var beltData = Planets[asteroidBelt] as AsteroidBeltData;
|
||||
var belt = AsteroidBelts[asteroidBelt];
|
||||
//var asteroidTransform = belt.Transforms[asteroid];
|
||||
|
|
|
|||
Loading…
Reference in a new issue