Drain spans run RegionClock.AdvanceFacilities; EconomyDrain.Span and its Production.Advance loop are deleted
The drain's off-screen step is the game's: Spans advances the copy by RegionClock.Span through RegionClock.AdvanceFacilities and reads each Facility behaviour's Stall, and Copy goes through EntitySerializer.Copy. Follow-up drain-spans-on-region-clock. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e221776ed5
commit
dd3cc1b75d
1 changed files with 14 additions and 27 deletions
|
|
@ -4,13 +4,11 @@ using System.Globalization;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using GameCult.Caching;
|
||||
using GameCult.Caching.MessagePack;
|
||||
using MessagePack;
|
||||
|
||||
// What a station's intake and drain look like in the demo run of one seed (ruling station-intake-few-sorties: a station takes ore
|
||||
// for a few sorties, then fills, and installed facilities work it down). Measurement only: it reads a booted copy of the catalog,
|
||||
// fills the two demo stations with the holds the base loop's sorties mined (a faulted sortie is reported and left out) through the shipped sale (StationServices.TrySellOre), then reads
|
||||
// the drain twice. On screen for a bounded window, stepping the arena; and by Production.Advance spans on inactive copies for the
|
||||
// the drain twice. On screen for a bounded window, stepping the arena; and by RegionClock spans on inactive copies for the
|
||||
// window (which must agree with the steps: H-drain-sim) and for the long horizon (the same rule, FacilityProductionTests.
|
||||
// OneSpanEqualsManySteps). Writes no catalog, changes no setting: every record it touches is in the booted scratch.
|
||||
|
||||
|
|
@ -101,9 +99,7 @@ public static class EconomyDrain
|
|||
{
|
||||
public const string HStall = "H-drain-stall", HSim = "H-drain-sim", HSortie = "H-drain-sortie", HSaturated = "H-drain-saturated";
|
||||
public const double DefaultWindowSeconds = 1200, DefaultHorizonHours = 24;
|
||||
// One span of the off-screen path, in sim seconds: the resolution of every time the horizon reports.
|
||||
public const double Span = 60;
|
||||
// How often the supplied horizon brings the wanted ores again, in sim seconds (a multiple of Span): the resolution of the first-saturated time.
|
||||
// How often the supplied horizon brings the wanted ores again, in sim seconds (a multiple of RegionClock.Span): the resolution of the first-saturated time.
|
||||
private const double SupplySpan = 600;
|
||||
private const int MaxSorties = 500;
|
||||
// Stepped and spanned run progress differ by float rounding only; a skew of one step (0.02 s) is far outside this. A cycle that ends on a
|
||||
|
|
@ -194,7 +190,7 @@ public static class EconomyDrain
|
|||
if (liveRecipe != copyRecipe || Math.Abs(liveProgress - copyProgress) > ProgressTolerance)
|
||||
run.Drain.WindowDisagreements.Add($"{name} run {liveRecipe ?? "idle"} at {liveProgress:0.###} s by steps against {copyRecipe ?? "idle"} at {copyProgress:0.###} s by spans");
|
||||
var (steppedRoom, spannedRoom) = (run.LiveRoom[i], spanRoom[i]);
|
||||
if (steppedRoom.HasValue != spannedRoom.HasValue || (steppedRoom.HasValue && !(steppedRoom.Value > spannedRoom.Value - Span - ProgressTolerance && steppedRoom.Value <= spannedRoom.Value + 2 * EconomyLoop.Step)))
|
||||
if (steppedRoom.HasValue != spannedRoom.HasValue || (steppedRoom.HasValue && !(steppedRoom.Value > spannedRoom.Value - RegionClock.Span - ProgressTolerance && steppedRoom.Value <= spannedRoom.Value + 2 * EconomyLoop.Step)))
|
||||
run.Drain.WindowDisagreements.Add($"{name} first Room at {(steppedRoom.HasValue ? steppedRoom.Value.ToString("0.##", CultureInfo.InvariantCulture) : "never")} s by steps against {(spannedRoom.HasValue ? spannedRoom.Value.ToString("0.##", CultureInfo.InvariantCulture) : "never")} s by spans");
|
||||
}
|
||||
}
|
||||
|
|
@ -230,7 +226,7 @@ public static class EconomyDrain
|
|||
public static void Print(DrainSample sample, TextWriter output)
|
||||
{
|
||||
var inv = CultureInfo.InvariantCulture;
|
||||
output.WriteLine(string.Format(inv, "\nStation drain, seed {0} (window {1:0.##} s on screen and by spans; horizon {2:0.##} h by spans of {3:0} s{4})", sample.Seed, sample.WindowSeconds, sample.HorizonHours, Span, sample.Supplied ? ", wanted ores topped up every 600 s" : ""));
|
||||
output.WriteLine(string.Format(inv, "\nStation drain, seed {0} (window {1:0.##} s on screen and by spans; horizon {2:0.##} h by spans of {3:0} s{4})", sample.Seed, sample.WindowSeconds, sample.HorizonHours, RegionClock.Span, sample.Supplied ? ", wanted ores topped up every 600 s" : ""));
|
||||
output.WriteLine($" haulers parked: {sample.Parked} (no haul moves on screen or in the spans: this block measures facilities; haul throughput is follow-up drain-haul-throughput, off-screen hauling region-haul-legs)"); output.WriteLine(" window compares units held, run progress and first-Room time; a Room-stalled facility holds at its cycle whatever the time, so a skew there shows only as first-Room time within one span");
|
||||
output.WriteLine(" window compares units held, run progress and first-Room time; a Room-stalled facility holds at its cycle whatever the time, so a skew there shows only as first-Room time within one span");
|
||||
output.WriteLine($" sorties usable {sample.Usable} of {sample.Usable + sample.Excluded.Count}" + string.Concat(sample.Excluded.Select(x => $"; excluded belt {x.Belt + 1}/{x.Belts} {x.BeltKind} {x.Outcome} at {x.SimSeconds:0.#} s")));
|
||||
|
|
@ -337,12 +333,8 @@ public static class EconomyDrain
|
|||
|
||||
// An inactive copy of a station as it stands, through the bytes a save would hold: Pack alone shares the stack objects with the
|
||||
// live station, so a copy's sale or take would move the original's units.
|
||||
public static Entity Copy(DemoArena demo, Entity station)
|
||||
{
|
||||
var options = CultDocumentMessagePackSerialization.OptionsFor(typeof(HullData).Assembly);
|
||||
var bytes = MessagePackSerializer.Serialize(EntitySerializer.Pack(station), options);
|
||||
return EntitySerializer.Unpack(demo.Items, demo.Arena, MessagePackSerializer.Deserialize<EntityPack>(bytes, options));
|
||||
}
|
||||
public static Entity Copy(DemoArena demo, Entity station) =>
|
||||
EntitySerializer.Unpack(demo.Items, demo.Arena, EntitySerializer.Copy(EntitySerializer.Pack(station)));
|
||||
|
||||
private static Dictionary<string, int> Held(Entity entity)
|
||||
{
|
||||
|
|
@ -397,23 +389,18 @@ public static class EconomyDrain
|
|||
private static IEnumerable<(EquippedItem unit, Facility facility)> Facilities(Entity entity) =>
|
||||
entity.Equipment.SelectMany(unit => unit.Behaviors.OfType<Facility>().Select(facility => (unit, facility)));
|
||||
|
||||
// The copy's facilities, each advanced through `seconds` of sim time in spans of Span, in equipment order. Returns the Stall
|
||||
// each ended in; each sees the sim time and the stalls after every span.
|
||||
// The copy's facilities, each advanced through `seconds` of sim time in spans of RegionClock.Span by the off-screen step the
|
||||
// game ships (RegionClock.AdvanceFacilities), in equipment order. Returns the Stall each ended in; each sees the sim time and
|
||||
// the stalls after every span.
|
||||
public Stall[] Spans(Entity copy, double seconds, Action<double, Stall[]> each = null)
|
||||
{
|
||||
var catalog = Demo.Cache;
|
||||
var hold = new EntityHold(copy);
|
||||
var units = Units(copy);
|
||||
var last = new Stall[units.Length];
|
||||
var facilities = Facilities(copy).Select(f => f.facility).ToArray();
|
||||
var last = new Stall[facilities.Length];
|
||||
for (var at = 0.0; at < seconds - 1e-9;)
|
||||
{
|
||||
var span = Math.Min(Span, seconds - at);
|
||||
for (var i = 0; i < units.Length; i++)
|
||||
{
|
||||
var (run, stall) = Production.Advance(catalog, Production.RunList(catalog, units[i].Data.Key), units[i].Run, span, hold);
|
||||
units[i].Run = run;
|
||||
last[i] = stall;
|
||||
}
|
||||
var span = Math.Min(RegionClock.Span, seconds - at);
|
||||
RegionClock.AdvanceFacilities(copy, span);
|
||||
for (var i = 0; i < facilities.Length; i++) last[i] = facilities[i].Stall;
|
||||
at += span;
|
||||
each?.Invoke(at, last);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue