← All entries

Entry 21 of 40

How the world runs

Every entry says the server decides, and this one says what the server is: one loop, one queue, a beat every half second, and a screen that works out everything it can.

TechWorld

This is the first entry about how the game works instead of what it does. When I’ve written “the server decides”, this is the server.

One world, one loop

A city is one running program, and inside it the world is one loop. Nothing changes the world except that loop. Your tap becomes a small note, “walk here”, “shoot that”, and the note joins a queue. Timers and zombies are run by the loop itself, on its beat. The loop works through the queue in order. Two players tapping the same door at the same instant are two notes in the queue, and one of them was first.

Three players, one queue, one loop. Every tap is a note. The loop reads them in order, beats, and sends each player their own picture

It’s built this narrow on purpose. A world that only one thing can touch cannot be in two states at once: no zombie both at a door and through it, no item both on a shelf and in a pack.

The beat

The loop wakes up twice a second. That is the beat everything else is counted in. A running step is one beat. A walking step is two. A sneaking step is three. The cooldown on a weapon is a number of beats, and so is a reload, and so is the time a zombie chews on a plank. Zombies don’t act on the beat at all. Each one has its own slow timer, as the Zombies entry said, and the beat just checks whose timer has run out.

The world does not look at the wall clock. It keeps its own count of time since it started, and that count only moves when the loop moves. It has its own dice too, seeded once. So the same notes in the same order always produce the same world, down to which zombie turned left. That sounds academic and it’s the most useful thing in the project: every mechanic ships with a scripted playthrough on the real loop, and if a change to barricades breaks the way a night goes, the playthrough breaks, on the same beat, every time.

What travels

The rule for the wire is simple: send only what the screen can’t work out for itself, and send the things that never change as rarely as it can.

Left, what the world sends. Right, what your screen works out on its own. The right column is bigger, and it is never trusted back

What goes over the wire each beat is a small list of facts: where the people and zombies you can see are standing, your own meters, any door that changed, what you heard and from where, and which tiles your eyes reached. A building’s name and icon come with the patch of map it stands on. The rulebook, every cost and every noise level, travels once when you join.

Everything else your screen works out. The shape of the dark comes from the tiles your eyes reached. The cost on a menu comes from the rulebook and your stance. The odds on a long shot are the same formula the world uses, run on your side so you see the number before you tap. The screen does most of the arithmetic, and none of it is believed. A modified screen cannot draw what’s behind a wall, because it was never told, and a claim of a hit or a free reload is a claim the loop ignores.

The loop sleeps

The last piece landed this week. Until now the loop rebuilt every player’s picture on every beat whether anything had changed or not. Now the world keeps a note of what changed, a step, a door, a sound, and on the next beat only the players whose view touches a change get a new picture, and only the parts that moved. A player standing still in an empty street costs the world almost nothing, which is exactly the player the check-in design produces most of. The beat still comes twice a second, but a beat where nothing near you changed skips you.

The world also saves itself and comes back as it was: every zombie, every door, every item on every floor, every player’s character standing where they left it. That is what makes the offline rule from the first entry real.