LittleSim.Web (Blazor WASM + KNI/WebGL) is a real network client now: it connects to the dedicated server over WebSocket (ClientWebSocket maps to the browser socket), applies MrGameEng.Net delta snapshots into its EntityStore and draws pawns through SpriteBatch — fatigue dims them just like on desktop. The server address comes from ?server=ws://host:port in the page URL, defaulting to the page's host on port 9050. The net contract is mirrored in NetContract.cs (KNI and DesktopGL assemblies can't mix until the graphics libraries build per platform) with loud keep-in-sync comments on both sides. Both clients now smooth replicated positions between 10 Hz snapshots: NetLerp + NetSmoothingSystem lerp the visual position toward the latest server position every frame (exponential, ~0.25 s to converge). Verified against a live LittleSim.Server --listen: the browser client connects (server log), draws ~3.3k lit pixels of pawns whose layout changes between samples, and survives 400+ ticks without errors. Found along the way: requestAnimationFrame freezes in hidden windows — the game loop only runs while the tab is visible. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
43 lines
2.0 KiB
C#
43 lines
2.0 KiB
C#
using Friflo.Engine.ECS;
|
||
using Microsoft.Xna.Framework;
|
||
using MrGameEng.Net;
|
||
|
||
namespace LittleSim.Web;
|
||
|
||
// ВНИМАНИЕ: бинарное зеркало сетевого контракта десктопа (src/LittleSim/Net/NetSchema.cs).
|
||
// Веб-клиент не может ссылаться на LittleSim/MrGameEng.Graphics (они собраны против
|
||
// MonoGame DesktopGL, а тут KNI), поэтому реплицируемые компоненты продублированы
|
||
// со СТРОГО тем же лейаутом и порядком регистрации. Меняешь схему там — меняй здесь.
|
||
// Уйдёт после пер-платформенной сборки графических библиотек (см. docs/web-client.md).
|
||
|
||
/// <summary>Зеркало MrGameEng.Graphics.Transform2D: Position(8) + Rotation(4) + Scale(8).</summary>
|
||
public struct NetTransform : IComponent
|
||
{
|
||
/// <summary>Позиция в мировых координатах.</summary>
|
||
public Vector2 Position;
|
||
|
||
/// <summary>Поворот в радианах.</summary>
|
||
public float Rotation;
|
||
|
||
/// <summary>Масштаб (у жителей — размер квада в пикселях).</summary>
|
||
public Vector2 Scale;
|
||
}
|
||
|
||
/// <summary>Зеркало LittleSim.Sim.PawnNeeds: Energy(4).</summary>
|
||
public struct NetPawnNeeds : IComponent
|
||
{
|
||
/// <summary>Запас сил жителя в [0, 1] — затемняет спрайт.</summary>
|
||
public float Energy;
|
||
}
|
||
|
||
/// <summary>Схема репликации веб-клиента — порядок тот же, что в NetSchema десктопа.</summary>
|
||
public static class WebNetSchema
|
||
{
|
||
/// <summary>Порт сервера по умолчанию (NetSchema.DefaultPort).</summary>
|
||
public const int DefaultPort = 9050;
|
||
|
||
/// <summary>Transform2D → NetTransform, PawnNeeds → NetPawnNeeds.</summary>
|
||
public static ReplicationSchema Create() =>
|
||
new ReplicationSchema().Register<NetTransform>().Register<NetPawnNeeds>();
|
||
}
|