nanoMMO

nanoMMO

A software engineering perspective

In this series, we're going to build an MMORPG from scratch, both the client and the server. The focus is on the engineering around the game: Docker, CI, benchmarking, Prometheus and Grafana, MySQL, Redis, and profiling.

nanoMMO is the working title. It takes after nanochat, a repository by Andrej Karpathy, with code that's kept minimal and easy to hack on. That's what I'm going for here as well: a codebase that covers an MMO from one end to the other, which you can read, run yourself, and play with.

The episodes are on YouTube. The game's code is on GitHub, tagged at each step of each episode, so you can follow along. Its API docs are here.

Watch the seriesStart at episode 1Read the code

Episodes

  1. nanoMMO, an MMORPG built from scratch in C++ (trailer)

    The game we're building from scratch in C++, filmed by itself, every skill slowed at its hit.

    2 min

  2. MMORPG drag and drop in C++ for the inventory and the hotbar

    Our C++ MMORPG's hotbar, chat, bag and login screens get the new look, and items and skills drag for real, checked by the server's own rules.

    65 min

  3. MMORPG game UI in C++ with a compass and a round minimap

    Our C++ MMORPG's interface gets a look of its own, which scales with the screen, a menu on Escape, a portrait, a compass along the top and a round minimap.

    78 min

  4. MMORPG sword skills in C++ that dash, launch and juggle

    Five sword skills for our C++ MMORPG, with dashes the server walks the player along, blows that throw monsters into the air and keep them there, copies left behind, a flash, and a camera that goes in.

    52 min

  5. MMORPG combat feel in C++ with hit-stop, knockback and a sword combo

    Blows that push monsters back, a moment's hold as each one lands, monsters that flash and rock back, a lit blade and cuts in the air, and a chain of three swings on Space, in our C++ MMORPG.

    46 min

  6. Procedural walk and run cycles with two-bone IK in a C++ MMORPG

    Our C++ MMORPG's people get a skeleton of their own, in its content, and the client works out their idle, walk, run and death from it, so a fresh clone needs nothing from Mixamo.

    55 min

  7. Versioning a C++ MMO and updating its libraries

    Our C++ MMORPG gets a version, which the client shows and the login server checks, and its libraries get pinned by hash and updated each week.

    27 min

  8. MMO character selection in C++ with a 3D preview

    An account gets up to four characters in each world, with names of their own, picked on a screen that draws each one in 3D, after a login that comes first, in our C++ MMORPG.

    47 min

  9. MMORPG trailer from code in C++ with slow motion, a sky and clouds

    Our C++ MMORPG films its own trailer, frame by frame, in slow motion, under a new sky with clouds.

    64 min

  10. MMORPG skill and gate sounds made from code in C++

    Each skill in our C++ MMORPG gets a sound made from the fx it already lists, from a whoosh of the blade to thunder, and each land a chord for when we arrive.

    37 min

  11. MMORPG footstep sounds made from code in C++

    Footsteps for our C++ MMORPG, which the client makes from numbers with a small synthesizer of our own, for each kind of ground, timed to the frames where the walk puts each foot down.

    63 min

  12. MMORPG skill effects in C++ for stone, ice, lightning and fire

    Four new skills in our C++ MMORPG, with shards and spikes that are lit like the world, lightning that strikes again and again, a crescent of fire, and a slice in front of the player for the server to hit.

    24 min

  13. MMORPG skill animation and VFX in C++ with keyframes, trails and sparks

    Skill animations of our own, as keyframes of joint turns in a text file, with sword trails, glows, shockwaves, sparks and a camera shake, in the raylib client of our C++ MMORPG, and the swing on Space as a skill too.

    55 min

  14. MMORPG pathfinding in C++ with A*, a map and a minimap

    A* pathfinding over the island's walkable squares on the C++ server, click to walk there, a map and a minimap drawn from the land, and monster camps spread over it, in our MMORPG.

    44 min

  15. MMORPG click targeting in C++ to pick a monster, run up and attack

    Swings and skills that go for the monster you clicked, with a ring at its feet and a frame of its own, a run up to it when it's out of reach, and cursors over what a click would do, in our C++ MMORPG.

    29 min

  16. MMORPG loading screen and death screen in C++

    A loading screen that covers the world until its land is built, with the fog lifting off it, a death screen that counts down to a Respawn button, and round gates, in the C++ client and server of our MMORPG.

    32 min

  17. MMORPG game events with an event queue in C++

    An event queue for what happens in the world, from the C++ server's tick through the interest management to each player near it, over TCP, shown in the raylib client as combat text.

    33 min

  18. Recap and what's next

    A check-in after forty-seven episodes, on what we've built, the practices around it, and where the game goes next.

    7 min

  19. MMORPG game analytics with ClickHouse and Grafana

    What players do, as events, from the C++ server through a Redis stream into ClickHouse, a column-oriented database, and onto a Grafana dashboard of the game.

    36 min

  20. MMORPG server load test, with flame graphs from Pyroscope

    Bots that take quests, hunt for them and turn them in, two thousand of them against our server, with its CPU profiled all the time by Pyroscope, through eBPF, in Grafana.

    22 min

  21. MMORPG quest system in C++, with NPCs that give quests

    Quests in the content, given by NPCs that are people now, which ask you to kill a number of monsters, counted on the server, turned in for experience and prizes, and saved.

    53 min

  22. Low poly characters for an MMORPG in C++

    The players become low poly people, made of parts the content describes and posed by the bots' bones, each with their own skin and hair, a hull for the outline, and clothes that are items.

    54 min

  23. Low poly water shader for an MMORPG in C++

    Three ways to make the sea move, ripples in the light, smooth waves and flat triangles, the facets picked to match the world, then a shore with foam and a liquid for each land, with lava that glows at the tops of its waves.

    29 min

  24. MMORPG loot tables and drops on a C++ server

    Monsters drop loot from tables in the content, each item with its chance, into the killer's bag, the chat says what dropped, and the bots drink and dress.

    23 min

  25. Drag and drop MMORPG inventory with Dear ImGui

    The server sends each player their bag and takes what they do with it, and the client draws it, with icons, tooltips, drag and drop, and the slots that are worn.

    31 min

  26. Saving MMO inventories with Redis and MySQL

    Each player carries a bag and fights with what they wear, drinks potions with a cooldown, and has their bag saved, through Redis to MySQL, when it changes.

    41 min

  27. A data-driven item system for an MMO game server

    Items made of parts instead of types, with stacks, equipment slots, stats, potions and rolls, and a bag to carry them in, which a property test plays with twenty thousand times.

    41 min

  28. Instanced dungeons for an MMORPG game server

    The Crypt, a dungeon that gives each player who goes in a copy of it of their own, with copies that go once they're empty, and players saved outside it.

    34 min

  29. Deploy on push with a self-hosted GitHub Actions runner

    A GitHub Actions runner on our server, in Docker, deploys each push to main once CI passes, with the worlds handing their players over, and refuses any other job.

    24 min

  30. Zero downtime deploys for an MMORPG game server

    A world that hands its players over to its next instance before it stops, through Consul, with a token for each move, so a deploy no longer throws anyone out.

    27 min

  31. Game server logs with Grafana Loki and Alloy

    The servers' logs in Loki, collected by Alloy from Docker, labelled by service and stream, on the dashboard next to the metrics, and an alert from the logs.

    16 min

  32. MMORPG skill trainer NPC with MySQL and Redis

    A trainer that teaches the skills, from their levels on, checked on the server, asked for in a window of its own, and saved through Redis to a table in MySQL.

    35 min

  33. Bloom and cel shading in C++ with raylib

    Bloom from raylib's post-processing example, done the way games do it, with a frame of floats and lava that gives off light, then cel shading from raylib's example, FXAA, and settings for them.

    44 min

  34. Game music in C++ with raylib audio

    Music in the world with raylib's audio, streamed and refilled each frame, faded in and out by a jukebox, with volume sliders in decibels and settings that the client keeps.

    25 min

  35. MMORPG skills, cooldowns and a hotbar in C++

    Four skills as content, used on the server with a level and a cooldown each, a hotbar on the number keys, animations from Mixamo, and a camera that tilts.

    39 min

  36. Prometheus Alertmanager alert rules and email

    Prometheus alerts when a world falls behind or goes down, Alertmanager emails each alert to a mail server in Docker, and promtool tests the rules.

    18 min

  37. Integration testing a C++ game server

    A test starts the world server on port zero and plays it over TLS, UBSan catches the test's own bug, and the coverage report sees the game loop run.

    21 min

  38. C++ sanitizers, fuzzing and coverage in Docker

    Sanitizers under the bots, fuzzing, clang-tidy and a coverage report find what the tests don't, and we fix it.

    38 min

  39. Data-driven MMO content in C++ with protobuf

    Monsters and NPCs join the items as data both sides read, go out by kind, and a content hash keeps clients and worlds in step.

    50 min

  40. MMO items in C++ with protobuf text format

    Our sword moves out of code into one items file, in protobuf's text format, which both the server and the client read, each taking the part it needs.

    31 min

  41. An LLM-powered NPC in a C++ MMO server

    A storyteller NPC writes players a story from a few words, with a small language model served next to the game, asked from threads off the tick.

    44 min

  42. Data-driven MMO NPCs in C++ on low bandwidth

    Our first NPCs, as tables of kinds and spawns, sent once a second and drawn as coloured balls until they have models.

    30 min

  43. MMO chat in C++ with TCP, ImGui and rate limits

    Players talk to everyone in their world, over TCP, with each line cleaned on the server and a token bucket against floods.

    28 min

  44. MMO zones and portals in C++ with raylib

    Each world gets a second land, the Ashlands, with a gate from the Meadows, and each land a look of its own, as data.

    45 min

  45. Consul service discovery for a C++ game server

    Each game server is a world that registers with Consul, the client lists the worlds through the login server, and each world keeps its own players.

    49 min

  46. MMO interest management to send each player less

    Each player gets the players near them, in cells of the island, and names and levels once a second, measured change by change, on my machine and on the VPS.

    33 min

  47. Deploy a C++ game server to a VPS with Docker

    Our game goes onto a VPS, deployed over SSH with Docker Compose, with the database kept private and certificates for the server's address.

    20 min

  48. MySQL schema migrations with Flyway in Docker

    Flyway keeps our MySQL tables in versions, so a change to them keeps the players' accounts, starting with saving their health.

    19 min

  49. Game character screen in C++ with raylib, ImGui

    A character screen with our player's details next to an idle 3D preview, which a camera of its own draws into a render texture for Dear ImGui to show.

    17 min

  50. Trees and frustum culling in C++ with raylib

    Trees grow on the island where the seed says, the server makes their trunks solid, and chunks with culling make the client a lot faster.

    32 min

  51. Procedural terrain in C++ with noise and raylib

    Our board of tiles becomes an island 512 metres across, from noise and a seed that the server and the client share, with a camera that follows you.

    52 min

  52. TLS for a C++ game server with OpenSSL and Asio

    Our client sends the password, and gets its token back, as plain bytes, so we put TLS 1.3 on all our TCP connections, with OpenSSL, Asio and a certificate authority of our own.

    45 min

  53. Redis cache in C++ with write-behind to MySQL

    Saving each change to MySQL slows our server down with a few dozen players, so we put Redis in between, with a pipeline, an append-only file and a saver that writes to MySQL in batches.

    41 min

  54. Laravel game website in Docker, with login and rankings

    A Laravel website next to the game, in Docker, with rankings, and accounts that log into the game, on the game's own MySQL tables, with no CSS of our own.

    47 min

  55. C++ MMO combat with swords, hits and respawns

    A public-domain sword in each hand, swings the server decides, and monsters that fight back, with a death animation for both.

    33 min

  56. C++ MMO monsters with AI, health and levels

    A public-domain skeleton, monsters with an AI on the server, and health, levels and experience for everyone.

    49 min

  57. TCP vs UDP for a game server, under packet loss

    We make the network drop packets, measure how old the world on a player's screen gets over TCP and then over UDP, and let the numbers decide.

    52 min

  58. Profiling a C++ game server with perf and Tracy

    We step the bots up until the server falls behind, find out where its time goes with perf, flame graphs and Tracy, fix the broadcast, and measure it again.

    42 min

  59. raylib 3D animation in C++ with Mixamo and glTF

    Mixamo characters converted to glTF, merged into files raylib can load, synced through the server and skinned on the GPU.

    52 min

  60. C++ login server with Redis tokens

    A login server checks passwords away from the game server's tick, and hands each login over through Redis as a one-time token.

    69 min

  61. C++ game accounts with MySQL and Argon2id

    Players get accounts, kept in MySQL through its C API, with their passwords hashed with Argon2id.

    47 min

  62. Prometheus and Grafana for a C++ game server

    Our server reports metrics, Prometheus collects them, Grafana draws them, Docker Compose starts it all, and three hundred bots give it something to show.

    50 min

  63. C++ multiplayer with protobuf and Asio

    A C++ server keeps several clients in sync, over TCP, with a protobuf contract between them.

    69 min

  64. C++ game client with raylib, ImGui and shaders

    The client's first window, drawn with raylib, with Dear ImGui on top, tests that run in Docker without a screen or a GPU, and a cube that the keyboard moves.

    67 min

  65. How to build an MMORPG from scratch in C++

    Where the series is going, and a C++ project that is built, tested and documented on each push.

    48 min