A video that's a bit different: instead of adding to nanoMMO, we read Ryzom Core's code next to ours. Ryzom launched in 2004 and has been open source since 2010, and its servers split each world over about ten kinds of process, where ours runs a world in one. We go through the tick and the mirror service, who sees whom and the frontend's bandwidth budget, who decides where a player is, saving a character and what happens when a save fails, content as data and behaviour as script, and the ideas I'd take from them. Not a review: each project made its choices for its own reasons. Ryzom Core is AGPLv3 code with CC BY-SA 3.0 art, by Nevrax, Winch Gate and the Ryzom Core community; its screenshots here are from wiki.ryzom.dev.
Transcript
Intro
0:00 Our game runs a world in a single process, while Ryzom, which launched in 2004, splits each of its worlds over about ten kinds of process. Today we're going to read their code next to ours, and see what led their team to each of those choices.
0:16 Hello and welcome to a video that's a bit different, where we read Ryzom Core's code next to ours, instead of adding to our game. For my own benefit, I wanted to see how a studio that shipped an MMO answered the questions we've been answering for a hundred episodes. A disclaimer before we start, this isn't a review, and I want to understand each project's reasons for its choices, not score them.
0:38 The game's website has more about the project, and a link to its code on GitHub, where it's all open source. Each episode gets a page there, and Ryzom's code is open source too, which is what makes a video like this possible.
Where Ryzom comes from
0:52 Ryzom Core is the open source version of Ryzom, on GitHub, with its code under the AGPL and its art under Creative Commons. It's still very much alive, with five commits on the day I pinned the version we're reading. And Ryzom Forge develops the live game on a fork of it, on GitLab.
1:11 The story starts in 2000, when a French studio called Nevrax began making Ryzom in Paris, on a 3D and network engine of its own, called NeL. It launched in September 2004 as The Saga of Ryzom, an MMO set on a planet called Atys. Two years later, in 2006, the studio went into receivership. Players and the Free Software Foundation pledged money to buy the game and free its code, which didn't work out at the time. It passed through a couple of owners, and in 2008 a company called Winch Gate bought it. In May 2010, Winch Gate released the client, the server and the tools as open source, along with over twenty thousand textures and thousands of 3D models under Creative Commons. And the game still runs today, with a patch in November 2026. Their wiki has this screenshot of the Ryzom Core client, out in the Burning Desert. I think it's quite remarkable for a game to outlive its studio by twenty years and still get patches.
2:09 I was glad to find Nevrax's research dossiers from 2001 and 2002 on their wiki, translated from French, along with the constraints they designed for. Their servers were meant to be PCs running Linux, with two processors at 2 gigahertz, linked to each other at a hundred megabits a second. And one server had to run at least seventy-five thousand creatures with some intelligence in real time, up from ten thousand in an earlier plan. Keep these numbers in mind, as most of what we see today follows from them.
2:39 Their code is about 2.7 million lines of C++, some forty-four times our sixty-three thousand. A lot of that is because in 2001 there was little to pull in. They wrote their own network layers, service discovery, shared memory between processes, a save format, a schema system for game data, an AI script language, a 3D engine and a GUI toolkit. For those jobs, we use Asio, Consul, Redis, MySQL, protobuf, raylib and Dear ImGui, most of which came out years later.
A world in ten processes
3:12 Now, let's look at the architecture, and their wiki has a page that lists each service. A world in Ryzom is called a shard, and a shard runs about ten kinds of process, cut up by job. The entities game service holds the players and the rules, and the global position manager keeps track of where everything is and who sees whom. And the AI service runs the creatures and the NPCs, split by continent on a big shard. Around them, a tick service keeps time, a mirror service shares data between them and a frontend talks to the clients. Others handle chat and the registry, while logins and saves are services shared by all the shards.
3:50 Drawn side by side, our world is one process with the login server, Redis and the saver around it, and a second world is another copy of that process. A Ryzom shard splits one world by job, with the pieces sharing data through the mirror, and the AI split again by continent, eight AI processes on a big shard.
4:08 That dossier also says why they split a shard by job. Most online games of the time gave each server a fixed part of the world, which falls over when lots of players crowd into one place. And on those servers, players in different zones couldn't talk to each other. Splitting by job let one shard spread over several machines, and this screenshot of their admin tool from 2007 shows a shard's services over four of them. A page on their wiki from 2012 says that a shard that ran on eight servers in 2004 could run on a single server by then. And a world on one core is where our game starts from.
The tick
4:46 Let's start with time, and with the tick that keeps it. Our tick is one function on an Asio timer, twenty times a second, and it does a whole round in order. It applies the players' inputs, steps the world, saves and sends, and then sets the timer for the next one. In Ryzom, time is a whole process, the tick service, written by Stephane Coutelas at Nevrax, which ticks ten times a second. It counts the game cycle, sends a tick message to each service that registered with it, and marks that it's waiting for that service's answer, which they call a tock.
5:21 The tick service sends the next tick once each service has answered, or hasn't missed more tocks than it's allowed. That means the slowest service sets the pace for the whole shard. One of my favourite bits of their code is this ASCII diagram at the top of the mirror service, drawn by hand in a comment. Each machine runs a mirror service, which passes the tick on to the services on that machine, and waits for their tocks. It sends what changed to the mirror services on the other machines, and writes what came back into shared memory, where the services read each entity's position and hit points.
5:55 Our world needs none of this, as the acceptor, the datagrams and the tick are all handlers on one Asio context, and nothing else touches the world. In Ryzom, the split has a cost, which a warning under that diagram spells out. A value in shared memory can change between two reads, as another process on the machine may write it. I think our world gets away without locks because we haven't split it, and the day we split one, we'll want something like their mirror.
What each player is sent
6:21 Next, who sees whom, which decides what each client gets. We cut the land into cells of thirty-two metres, and a player gets everyone in the five by five block of cells around theirs, at least sixty-four metres each way. Ryzom's position manager uses cells of sixteen metres, out to a circle of two hundred and fifty metres, sorted nearest first, with a mask that thins out the far rings. A player sees two hundred and fifty-five others at most.
6:46 At each tick, we send a player all the pieces in that block that changed, however many datagrams that comes to. Ryzom's frontend works to a budget instead, three hundred and thirty-two bytes a tick for each client. It raises the priority of the things a player can see at each tick, by ten thousand divided by their distance in millimetres. Then it fills the client's datagram in order of priority until the budget runs out, and what got sent goes back to zero. That means things near you update nearly each tick, and things far away go once they've waited long enough. Olivier Cado wrote this part of the frontend at Nevrax in 2002, and I really like it. It's a line of maths and a byte budget, and a crowd makes the far things slower without flooding anyone's link. With players on modems back then, they needed it, and I think it holds up very well today.
Where a player is
7:38 Our client sends a direction and no position, and the server walks the player. It scales a direction longer than one back down, which means a modified client can't ask for more speed. The client predicts its own movement and the server corrects it, as we built in the netcode episodes. Ryzom's client does the walking, with collision on the client, and sends the server its position in millimetres each tick.
8:03 The position manager then works out how far the player could have gone since the last update, at one and a half times their speed. When the client claims a longer move, it gets cut down to that length. It also plays the move against the world as it was at the client's tick, from thirty-one images of the past it keeps. This gave players instant movement on the connections of the time, without a line of prediction code on the client. We went the other way, and pay for it with prediction and corrections on our client, as the server decides where each player is.
Saving a character
8:36 Saving is where we differ most, and where I learned the most. After each tick, we write each player who changed into Redis, in one round trip, and our saver takes them to MySQL in batches, five seconds apart. Ryzom serialises the whole character into one tagged file, and sends it to a backup service that writes it to disk. It saves a character once eight minutes of play have passed since the last save, and again when the player logs out. A file per character kept a database out of the game's way, and its tagged fields let old saves load into new code.
9:08 I was most curious about what each game does when a save fails. When our saver can't write, it logs the error and carries on, the players wait in Redis, and an alert tells us when it's been too long since the last good flush. When Ryzom's backup service can't write a file, the shard stalls. Players get a message that Customer Support is already working on it, and the tick service is told to halt. I think both answers make sense, given where each game keeps a character. Their file is the one copy of a character, and playing on would pile up progress that a crash then loses. Ours has Redis's append-only file behind the tick, which is why we keep the game up.
What we share
9:47 Now for some of the answers we share, starting with game data. Our monsters are data, one block each in a protobuf text file with a schema beside it, which the world server and the bots read. Ryzom's are Georges sheets, XML forms checked against a schema, where a creature inherits from parent sheets, here a desert kazoar's, with how far it notices players depending on how hungry it is. They have over two thousand fauna sheets and an editor for designers, where we have four monster kinds in one file. Still, in both, a monster's numbers sit in a data file with a schema, and you can change one without touching the code.
10:23 In both games, logging in ends with a one-time ticket that the login side hands to the game. Our login server hands the world a random token in Redis, which works once within thirty seconds. In Ryzom, the frontend gets a cookie, made of the client's address, a random key and the account's id, and it accepts the cookie once and removes it. Either way, the game server doesn't see a password, as the login side checks it and hands over a ticket instead.
Behaviour
10:50 We part ways again on behaviour, which Ryzom keeps in scripts. Their level designers attach scripts to groups of NPCs and creatures, in an AI language of their own that the AI service compiles and runs. With the Ring editor, even players could build scenarios, which become that script too. Our monsters' behaviour is C++ in the server, next to the rules it uses, and the content files hold numbers. A big world built by a team of designers couldn't wait for a programmer and a server build, while we have four monster kinds and one person writing code.
What I'd take from them
11:24 Before we wrap up, here are a few of their ideas I'd happily take for our game. Their AI service updates a group of creatures on alternate ticks when players are near, and once in thirty-two ticks when nobody is around, staggered by its place in the list. I love that whoever wrote it noted it was late and they were tired, which I can very much relate to. Our monsters all step each tick, and I'd like to try this in ours, with the monsters far from players stepping less often.
11:53 The frontend's priority under a budget is the one I'd copy first, the day bandwidth matters for us. NeL also has a message recorder from 2001, by Olivier Cado, which records what a service receives and replays it under a debugger. And I'd love something like it for bug reports, to replay what a server got from a player. Each of their services also has variables and commands you can change while it runs, from their admin tool. It's also nice to see how much we agree on, from the one-time ticket between login and game to content as data. And in both, a process runs its game logic on one thread, one update after another.
Recap
12:33 Ryzom split each world by job to spread it over several of the two-processor PCs of its day. And with little to pull in, its team wrote nearly everything themselves, from the network layers to the 3D engine. We fit a world on one core and lean on libraries that came later. With their constraints, I think I'd have made a lot of their choices too. Funnily enough, they're heading to the browser like us, with their engine's samples running in WebGL since February.
Playing it
13:52 Have you played Ryzom, or worked on a codebase this old? Tell me in the comments, along with what you think of reading other projects' code like this, and subscribe if you'd like to follow along. I hope you find this useful, and thanks for watching.