Write the game. Aether moves the bytes.
Plain structs go in. Replication, interest management, client prediction, lag compensation and saving come out, over WebSocket or reliable UDP. A complete multiplayer world fits in about a hundred lines.
Measured on a desktop i5-11400F, Release build.
A contract, a rule, a world
The same step runs on the server and on the client. That is how prediction stays honest.
#pragma once #include <aether/server.h> #include "meadow/Shared.h" using namespace aether; using meadow::Chat; using meadow::Purse; using meadow::Said; class World : public server::Game { public: explicit World(ecs::Store& store) : Game({.store = &store, .contract = meadow::contract}) {} void onStart() override { persist<Purse>().key(&Purse::owner); // saved, filed under its owner view<Walker>().spatial("x", "y"); // seen by players nearby view<Purse>().ownerOnly(); // seen by its owner only inputs().apply<Move>(step); // what a held Move does on<Chat>([this](Player& p, const Chat& c) { // a message from a client broadcast(Said{String<16>(p.query("name", "anon")), c.text}); }); } void onJoin(Player& p) override { const std::string name = p.query("name", "anon"); p.entity = spawn(Walker{0, 0, 60}, load<Purse>(name).value_or(Purse{String<16>(name), 0})); } void update(float) override { for (Player& p : players()) get<Purse>(p.entity).gold += 1; // a coin a tick } };
#include <chrono> #include <cstdio> #include <aether/client.h> #include "meadow/Shared.h" using namespace aether; static double lerp(double a, double b, double t) { return a + (b - a) * t; } int main(int argc, char** argv) { client::Session session(argc > 1 ? argv[1] : "ws://localhost:9000/?name=Ayla", {.contract = meadow::contract}); session.onClose([](std::uint16_t code, std::string_view why) { std::printf("closed %u: %.*s\n", code, int(why.size()), why.data()); }); session.onError([](std::string_view what) { std::printf("error: %.*s\n", int(what.size()), what.data()); }); auto players = session.view<Walker>(); auto purses = session.view<meadow::Purse>(); auto me = session.predict<Walker>(); me.apply<Move>(step); session.on<meadow::Said>([](const meadow::Said& s) { std::printf("%s: %s\n", s.who.str().c_str(), s.text.str().c_str()); }); session.connect(); using Clock = std::chrono::steady_clock; const auto start = Clock::now(); auto lastPrint = start; bool said = false; while (Clock::now() - start < std::chrono::seconds(4)) { session.poll(5); me.input(Move{1, 0}); if (session.ready() && !said) { session.send(meadow::Chat{String<80>("hello")}); said = true; } if (Clock::now() - lastPrint > std::chrono::milliseconds(500)) { lastPrint = Clock::now(); const double a = me.alpha(); const auto purse = purses.find(session.me()); std::printf("x=%.1f gold=%u\n", lerp(me.before().x, me.now().x, a), purse ? purse->gold : 0); } } }
Five files in all, 114 lines, and every one compiles and runs: the Start page has the contract file, the shared header and server.cpp, and builds them step by step.
WebSocket or reliable UDP. One line decides.
Ship to browsers over WebSocket and to native clients over GameNetworkingSockets, Valve's reliable UDP. The game code is the same for both.
// server app.listen(9000); // client client::Session session("ws://play.example.com:9000/");
// server app.listen(server::GameSocket{27015}); // client client::Session session("gns://play.example.com:27015/");
- Nothing else changesViews, inputs, messages, prediction and saving behave the same on either transport.
- Encrypted by defaultGameNetworkingSockets encrypts every connection. There is no switch to forget.
- One link report
p.link()gives loss, capacity, backlog and queue time on both. - Pay for what you linkThe UDP transport is its own library. A WebSocket-only game never pulls it in.
Every piece of netcode, already built
Data model
Plain structs
No macros, no ids, no base class. Aether reads the members itself.
One contract file
A .aether file generates C++ and JavaScript. A mismatched client is refused at connect.
Entity component system
Queries with none, any and optional, groups, tags and singletons.
Lists and nesting
Bounded lists, fixed arrays, strings and structs inside structs.
Hooks and events
React when a component is added or removed. Pass events between systems.
Schedule
Phases, systems at their own rate, and timing for each one.
Server-only components
Any C++ type, from a std::map to a nav mesh. Never sent, never saved.
Deferred changes
Add and remove safely while a query is running.
Text dump
Print the whole world, or one entity, when something looks wrong.
Replication
Views
Say which struct clients see. Aether sends only the fields that changed.
Interest management
A 2D or 3D grid. A player receives what is near them and nothing else.
Owner-only and global
A purse only its owner sees. A scoreboard everybody sees.
Encoded once
A change is packed once per tick and shared by every player who sees it.
Byte budget
A cap per player per tick. The most urgent rows go first, the rest catch up.
Field tiers and rates
Position every tick, cosmetics every fifth. One call: every(5).
Crowd blocks
A packed city square is sent as shared blocks, not player by player.
Function views
Show clients a computed slice of server-only state.
Messages
send, broadcast and on<T> for everything that is not a row.
Client
Prediction and replay
Your own character moves at once and is replayed when the server corrects it.
Held inputs and moves
input() for the stick, act() for a jump. Both arrive in order.
Smooth remote players
Two rows and an alpha for each one. Blend them however you draw.
Lag compensation
The server keeps history and judges a shot where the shooter saw the target.
Server time
One clock every client agrees on, for cooldowns and timers.
Reconnect
A dropped connection resumes with one call.
Saving and running
Declare it, it is saved
persist<Purse>().key(&Purse::owner). There is no save call.
Two transports
WebSocket for browsers, GameNetworkingSockets for native clients. ws:// or gns://.
Three stores
Memory for tests, a file for one server, Rune for a cluster. One line to switch.
Schema check
A changed struct is refused at start, before it can misread old rows.
Many games, one process
A lobby and an arena behind one port, each at its own tick rate.
Tests in one include
A real server and real clients inside a unit test, on a free port.
One CMake line
aether_game(mygame) builds the server, the client and the test.
An ECS as fast as the fastest
Nanoseconds per entity, against EnTT 3.15. Shorter is better.
Query two components
Read one entity at random
Destroy an entity
Iterate one component
Aether's slowest run against EnTT's fastest. Same machine, same build flags.
14 example games in the box
walker
Movement with prediction. The four-line world above.
arena · raid · arpg
Combat, bosses, loot and lag-compensated hits.
kart · driving
Fast vehicles, laps and tight corrections.
duel
A turn-based card game with no prediction at all, in 20 lines.
farm · chests
Worlds that survive a restart: crops, gold, inventories.
portals · tag · assemble
Zones, server-only state and crowds in one place.
Your first multiplayer world, today
The API fits on one page, with code you can paste.