Many of you wrote in to describe the first part of this Lister Panel series as, and I quote, “A lot like the first book of Lord of the Rings: there’s a hobbit and a wizard, which is cool, but mostly everyone just walks around talking about stuff instead of actually fighting.” And many of you added, “I hope the next installment is more like The Two Towers, where there’s tons of armies and shit.”
Well, I never read Lord of the Rings. Frankly, as soon as a book starts putting apostrophes in the middle of proper names, I’m out. But in the interest of pleasing all the people all the time, I will absolutely do my best to make sure this article has all the epic battle scenes that you have come to expect from my Witness Wednesday series while still retaining the hobbit/wizard dynamic that made the previous article so approachable for young audiences.
So, Karl the Hobbit looked out across the battlefield of… D’ar-gar’ith, let’s say… which had a lot of important historical significance which I won’t go into it right now but trust me it’s wicked intricate, and anyway he saw lots of clashing armies that were totally doing all these badass moves and it was amazing and everyone was casting spells but the good army was losing so Karl said to his wizard friend Gary, “I must implement the update function for The Lister Panel, or the battle will be lost!”
And lo did he then open upeth his Emacs window and starteth typing.
The Update Function
The Lister Panel lists entities. That’s what it does. So naturally, since I generally try to work from basic implementation upwards as much as possible, the first thing I actually started typing was the function that picks the entities shown in the list.
I wasn’t sure how many entities would be involved in The Witness by the time it shipped, so it seemed plausible to me that, in an extreme scenario, just filtering the entities might take some time — probably not on the order of seconds, but possibly on the order of hundreds of milliseconds, which would drag down the framerate if it was done every frame. So I wanted to make sure that updating the list of entities wasn’t something that had to be done every frame. At the same time, I had some features I wanted to implement that would actually be much cooler if they did update every frame, so I also wanted to make sure that it could update every frame if you wanted it to and it wasn’t too much of a performance hog.
So I started off by writing a very simple update function: