Skip to content

Latest commit

 

History

History
74 lines (55 loc) · 3.22 KB

File metadata and controls

74 lines (55 loc) · 3.22 KB

magnet

A generic, zero-allocation UDP game-networking stack in Zig. Reliable channels, real congestion control, optional encryption, a derived bit-level serializer, and a complete client-prediction / rollback replication layer - all monomorphized from one comptime Config, and all sans-IO (the protocol never touches a socket, clock, or allocator).

const magnet = @import("magnet");

const Schema = magnet.proto.channels(.{
    .chat = .{ .mode = .reliable_ordered, .Message = []const u8 },
});
const Server = magnet.Endpoint(.{ .channels = Schema, .protocol_id = 0x1234 });

Where do you stop?

magnet is six layers, and you take only what you need:

Stop at You get Add
L3 secure-optional reliable UDP with typed channels -
L4 …plus a comptime, bit-level serializer .Message types
L5 …plus prediction, rollback, interpolation, interest, lag-comp magnet.replication

Unused machinery is compiled out, not skipped - an unreliable channel carries no retransmit state and security.mode = .none links no crypto. Zig's lazy declaration analysis likewise omits unused replication and runtime subsystems without a configuration sentinel.

Start here

Guides (one per layer)

Recipes (genre = config)

fps · rts / lockstep · mmo · p2p rollback · co-op

Concepts

sans-io · comptime · type safety · layering · wire format · security model

Reference

config fields · errors · API docs: zig build docszig-out/docs/.

Examples

Every guide links a runnable example in ../examples/. Build them all with zig build examples, run one with zig build run-<name> (e.g. zig build run-fps).