F3: client Godot minimo, replay dei comandi e collaudi automatici
- Client Godot 4.7 .NET (Godot.NET.Sdk 4.7.2): menu, collegamento, partita locale con server figlio; mappa con terreno (fasce, ombreggiatura, rive curve con shader, curve di livello), opere, entità, alberi, treni interpolati con fumo; strumenti binari con profilo, stazione, deposito, segnali, demolizione; pannelli treni, linee, mercato, finanze, schede; barra superiore, minimappa, notiziario; italiano e inglese. - Pilota automatico del client e scripts/client-autopilot.sh: partita locale, linea con ponte, treni in moto e schermate (docs/screenshots). - Registro dei comandi del server (--record) e viaferrea-tools replay. - PROTOCOL.md normativo, ADR 0009, ARCHITECTURE, STATE e README aggiornati. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0191R7vXgtbAvSV4V8tj8uzL
This commit is contained in:
97 files changed
+5151
-96
No files matched your search
@@ -0,0 +1,49 @@
|
||||
using ViaFerrea.Core.Commands;
|
||||
using ViaFerrea.Core.Common;
|
||||
using ViaFerrea.Core.Map;
|
||||
using ViaFerrea.Core.Rail;
|
||||
|
||||
namespace ViaFerrea.Protocol.Client;
|
||||
|
||||
/// <summary>
|
||||
/// Collaudi (viaferrea-tools smoke, pilota automatico del client): cerca sulla copia locale del
|
||||
/// terreno un attraversamento di fiume rettilineo di 1,5–2,5 km con estremità e deposito su
|
||||
/// terreno libero e un'anteprima valida con ponte.
|
||||
/// </summary>
|
||||
public static class BridgeSiteFinder
|
||||
{
|
||||
public readonly record struct Site(Vec2 A, Vec2 B, Vec2 Depot, Vec2 River);
|
||||
|
||||
public static Site? Find(ClientWorld w, ulong seed = 7, int attempts = 400, int maxDays = 120)
|
||||
{
|
||||
var t = w.Terrain ?? throw new InvalidOperationException("Terreno non ricevuto");
|
||||
var rng = new Rng(seed);
|
||||
bool Free(Vec2 p)
|
||||
{
|
||||
if (p.X < 2000 || p.Y < 2000 || p.X > t.WidthM - 2000 || p.Y > t.HeightM - 2000) return false;
|
||||
var (x, y) = t.CellAt(p);
|
||||
return (CellType)t.Types[y * t.Width + x] is CellType.Plain or CellType.Field or CellType.Forest or CellType.Hill;
|
||||
}
|
||||
var rivers = new List<int>();
|
||||
for (int i = 0; i < t.RiverWidth.Length; i++)
|
||||
{
|
||||
if (t.RiverWidth[i] > 0) rivers.Add(i);
|
||||
}
|
||||
if (rivers.Count == 0) return null;
|
||||
for (int attempt = 0; attempt < attempts; attempt++)
|
||||
{
|
||||
int cell = rivers[rng.NextInt(rivers.Count)];
|
||||
var center = t.CellCenter(cell % t.Width, cell / t.Width);
|
||||
double angle = rng.NextDouble(0, Math.PI);
|
||||
var dir = new Vec2(Math.Cos(angle), Math.Sin(angle));
|
||||
double half = rng.NextDouble(750, 1250);
|
||||
var a = center - dir * half;
|
||||
var b = center + dir * half;
|
||||
var depot = a - dir * 600;
|
||||
if (!Free(a) || !Free(b) || !Free(depot)) continue;
|
||||
var plan = w.PreviewTrack(new BuildTrackCommand([a, b]));
|
||||
if (plan.Valid && plan.LengthOf(WorkKind.Bridge) > 0 && plan.Days <= maxDays) return new Site(a, b, depot, center);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,9 @@ public sealed class ProtocolClient : IAsyncDisposable
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Riserva un numero di sequenza (per registrare l'attesa dell'esito prima dell'invio).</summary>
|
||||
public uint ReserveSeq() => Interlocked.Increment(ref _seq);
|
||||
|
||||
/// <summary>Invia un comando con un nuovo numero di sequenza e lo restituisce.</summary>
|
||||
public async Task<uint> SendCommandAsync(GameCommand command, CancellationToken ct = default)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
using System.Buffers.Binary;
|
||||
using ViaFerrea.Core.Commands;
|
||||
using ViaFerrea.Core.Common;
|
||||
|
||||
namespace ViaFerrea.Protocol;
|
||||
|
||||
/// <summary>
|
||||
/// Registro dei comandi per il replay: intestazione «VFCL» + versione, poi record
|
||||
/// <c>[u32 lunghezza][i64 tick][i32 emittente][u32 seq][u16 tipo][payload]</c> con il payload
|
||||
/// del protocollo. Il server lo scrive con <c>--record</c>, <c>viaferrea-tools replay</c> lo rilegge.
|
||||
/// </summary>
|
||||
public static class CommandLogFile
|
||||
{
|
||||
private static ReadOnlySpan<byte> Magic => "VFCL"u8;
|
||||
public const ushort Version = 1;
|
||||
|
||||
public static void WriteHeader(Stream s)
|
||||
{
|
||||
s.Write(Magic);
|
||||
Span<byte> v = stackalloc byte[2];
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(v, Version);
|
||||
s.Write(v);
|
||||
}
|
||||
|
||||
public static void Append(Stream s, long tick, GameCommand command)
|
||||
{
|
||||
var w = new SpanWriter(128);
|
||||
w.U32(0);
|
||||
w.I64(tick);
|
||||
w.I32(command.Issuer.Value);
|
||||
w.U32(command.Seq);
|
||||
w.U16((ushort)command.Type);
|
||||
CommandCodec.Write(ref w, command);
|
||||
w.PatchU32(0, (uint)(w.Length - 4));
|
||||
s.Write(w.Written);
|
||||
}
|
||||
|
||||
public static List<(long Tick, GameCommand Command)> ReadAll(byte[] file)
|
||||
{
|
||||
if (file.Length < 6 || !file.AsSpan(0, 4).SequenceEqual(Magic)) throw new ProtocolException("non è un registro di comandi di Via Ferrea");
|
||||
ushort version = BinaryPrimitives.ReadUInt16LittleEndian(file.AsSpan(4));
|
||||
if (version > Version) throw new ProtocolException($"registro di versione più recente ({version})");
|
||||
var list = new List<(long, GameCommand)>();
|
||||
int pos = 6;
|
||||
while (pos + 4 <= file.Length)
|
||||
{
|
||||
int length = (int)BinaryPrimitives.ReadUInt32LittleEndian(file.AsSpan(pos));
|
||||
if (length < 18 || pos + 4 + length > file.Length) throw new ProtocolException("registro troncato");
|
||||
var r = new SpanReader(file.AsSpan(pos + 4, length));
|
||||
long tick = r.I64();
|
||||
var issuer = new CompanyId(r.I32());
|
||||
uint seq = r.U32();
|
||||
var type = (CommandType)r.U16();
|
||||
var command = CommandCodec.Read(type, ref r) with { Issuer = issuer, Seq = seq };
|
||||
list.Add((tick, command));
|
||||
pos += 4 + length;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user