- RailNetwork: nodi, archi con profilo campionato, divisione degli archi agli agganci (anche in cantiere), indice spaziale, cavalcavia sui binari altrui - Comandi: binari, stazioni, depositi, segnali, demolizioni, rinnovi, ammodernamenti, veicoli, composizioni, linee, assegnazioni, rientro - ConstructionSystem: squadre per livello, avanzamento, usura dei binari e invecchiamento delle strutture; costi d'esercizio e valore contabile - TrainSystem: A* con vincolo di svolta, prenotazione a blocchi con catena fino a un punto sicuro sul binario semplice, fisica 8.4, stallo in salita - StationSystem e StationWork: bacini, merci con destinazione sul grafo delle linee, carico sui carri, consegne con tariffa, trasbordi - Salvataggi estesi a tutto lo stato ferroviario; 11 nuovi test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0191R7vXgtbAvSV4V8tj8uzL
57 lines
1.9 KiB
C#
57 lines
1.9 KiB
C#
using System.Diagnostics;
|
|
using ViaFerrea.Core.Simulation.Systems;
|
|
|
|
namespace ViaFerrea.Core.Simulation;
|
|
|
|
/// <summary>
|
|
/// Sistemi nell'ordine fisso della guida (sezione 4). I sistemi delle fasi successive si
|
|
/// inseriscono nella loro posizione quando vengono implementati:
|
|
/// Clock → Commands → Construction → Trains → Signals → Stations (+ trasporto locale)
|
|
/// → Maintenance → Demand → Commuting → Industries → IndustryMaintenance → Towns → Market
|
|
/// → Finance → StockMarket → AiAgents → Events → Contracts → Hash.
|
|
/// </summary>
|
|
public sealed class SystemPipeline(IReadOnlyList<ISimSystem> systems)
|
|
{
|
|
public IReadOnlyList<ISimSystem> Systems { get; } = systems;
|
|
|
|
/// <summary>Se attivo, misura il tempo di ogni sistema (diagnostica e bench).</summary>
|
|
public bool Profile { get; set; }
|
|
|
|
/// <summary>Tick totali (Stopwatch) spesi per sistema quando Profile è attivo.</summary>
|
|
public long[] ElapsedTicks { get; } = new long[systems.Count];
|
|
|
|
public static SystemPipeline CreateDefault() => new(
|
|
[
|
|
new ClockSystem(),
|
|
new CommandSystem(),
|
|
new ConstructionSystem(),
|
|
new TrainSystem(),
|
|
new StationSystem(),
|
|
new LocalTransportSystem(),
|
|
new DemandSystem(),
|
|
new EmploymentSystem(),
|
|
new IndustrySystem(),
|
|
new TownSystem(),
|
|
new MarketSystem(),
|
|
new FinanceSystem(),
|
|
new HashSystem(),
|
|
]);
|
|
|
|
public void Run(WorldContext ctx)
|
|
{
|
|
if (!Profile)
|
|
{
|
|
for (int i = 0; i < Systems.Count; i++) Systems[i].Step(ctx);
|
|
return;
|
|
}
|
|
for (int i = 0; i < Systems.Count; i++)
|
|
{
|
|
long start = Stopwatch.GetTimestamp();
|
|
Systems[i].Step(ctx);
|
|
ElapsedTicks[i] += Stopwatch.GetTimestamp() - start;
|
|
}
|
|
}
|
|
|
|
public T Get<T>() where T : ISimSystem => Systems.OfType<T>().First();
|
|
}
|