Add MrGameEng.Net: WebSocket transport + delta component replication
CI / build-test (push) Successful in 1m16s

Browsers can't speak UDP, so WebSocket is the engine's one transport.
The server side is a dependency-free RFC 6455 implementation over
TcpListener (handshake, frame codec with masking and fragmentation,
ping/pong — unit-tested against the RFC example vectors); the client
wraps ClientWebSocket, which works on desktop and maps to the browser
WebSocket in Blazor WASM. Both sit behind the poll-based INetConnection
so simulation systems drain messages from their own thread; client
sends are chained fire-and-forget (no blocking — wasm-safe).

Replication is server-authoritative: games register unmanaged component
types in a ReplicationSchema (same order both sides, up to 32 types),
ReplicationServer snapshots entities carrying NetId once per send and
ships each connection only the components that changed since its last
snapshot — a reliable ordered transport needs no acks for deltas. New
connections receive the full state through the same path; despawns are
tracked by set difference. ReplicationClient applies snapshots to a
local EntityStore and raises EntitySpawned so the game can decorate
replicated entities with presentation components.

Covered by 16 tests including a real loopback exchange between
WebSocketClient and WebSocketServer.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Leonid Pershin
2026-06-12 23:35:57 +03:00
co-authored by Claude Fable 5
parent 10898b08a0
commit 3438ed77f6
16 changed files with 1492 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
using Friflo.Engine.ECS;
namespace MrGameEng.Net;
/// <summary>
/// Marks an entity as replicated and identifies it across the network. The server assigns
/// values (see <see cref="ReplicationServer.NextNetId"/>); the client creates a local
/// entity with the same <see cref="Value"/> when the first snapshot arrives.
/// </summary>
public struct NetId : IComponent
{
/// <summary>Network-wide entity id, unique per server world.</summary>
public int Value;
}