Falling Trees
If a tree falls in a forest and no one is around to hear it, does it make a sound?
Ultima Online is a big world, containing a myriad of virtual objects of every type and description. Animals, monsters, people, plants, and yes, trees too, all abound over nearly seventy million square meters of territory that exists merely as a figment of data in some server's RAM, dutifully backed up on a daily basis.
If UO is a persistent world, does everything keep going, even when players aren't there?
The short answer is: no, unfortunately not. A somewhat commonly known thing amongst our playerbase, for instance, is that mobiles (any dynamic object that can move: animals, monsters, NPCs) don't move when players aren't nearby. This "sleep" behavior was implemented some time ago in order to combat wasted CPU time that bogged down performance for the rest of the game.
The behavior itself is very simple to understand. Every mobile has its own basic AI loop that executes, sets a short delay, and starts over again. This allows every mobile to evaluate its current situation and respond to it, and then turn control of the CPU back over to the rest of the game.
In fact, these loops are very short, and we call them ticks or heartbeats. Rather than give every single object in the game its own individual share of the CPU, we have a main thread that runs as a loop as well, which gives short amounts of time to each object on an as needed basis.
Now, imagine a normal server, like Atlantic. There are over sixty thousand mobiles up and running, all potentially handling their AI loops at any given time. If every mobile tried to execute all the conditions and possibilities available to it, the game would take a gigantic hit in performance. Even worse, imagine if every mobile wanted to actually move.
And so, instead, if players aren’t within a certain distance, those mobiles just go to sleep, waiting for their time to shine.
This became a problem, though, while we were working on the Stygian Abyss expansion.
We wanted to do something we thought would be relatively simple. One of the newer dungeon levels has a series of tombs, each blocked by a gate, hooked to a lever in another room. When the lever is pulled, it should open the gate, releasing the monsters inside.
Now, normally, that means we just send a message to each monster saying "move down the corridor and get ready to meet the player in the main hallway."
So we pulled all the levers, eager to see the suddenly full hallway, and to our surprise, found the hallway quite empty. At least, for a moment! Suddenly the monsters came streaming from left and right, coming out of the tombs, now that someone was there to see them.
Even though we knew about the "sleep" mode for mobiles, we thought we could override it just by directly sending commands to them. This had worked in many other game systems added for live events, such as Sherry the Mouse, an NPC who had a full daily schedule of running around the castle, eating lunch in the kitchen, popping through mouseholes, and generally being cute.
It turns out, we were wrong! The only reason Sherry worked at all when players weren't around was because she could teleport when her movement checks failed, a failsafe originally designed to deal with griefers trying to trap her in the corner.
Ultimately, our resolution is a simple one: we've designed a flag that allows some mobiles to avoid the sleep system, which will be implemented in the new expansion. From here on out, parts of the world will come to life more than ever before, existing and evolving apart from the comings and goings of the average observer.
And while we may not be able to hear a tree chopped down in the woods, and least we know a horde of undead Gargoyles won't be standing idly by when you raid their tombs!
This was from Draconi's facebook essay