Discussion
Larst Of Us
lefty2: > The same trick can also be used for the other direction to save a division:> NewValue = OldValue >> 3;You need to be careful, because this doesn't work if the value is negative. A
applfanboysbgon: > Imagine a programmer asking a game designer if they could change their formula to use an 8 instead of a 9.5 because it is a number that the CPU prefers to calculate with. There is a very good argument to be made that a game designer should never have to worry about the runtime performance characteristics of binary arithmetic in their life, that’s a fate reserved for programmersNumeric characteristics are absolutely still a consideration for game designers even in 2026, one that influences what numbers they use in their game designs. The good ones, anyways. There are, of course, also countless bad developers/designers who ignore these things these days, but not because it is free to do so; rather, because they don't know better, and in many cases it is one of many silent contributing factors to a noticeable decrease in the quality of their game.
fweimer: What language is this article talking where compilers don't optimize multiplication and division by powers of two? Even for division of signed integers, current compilers emit inline code that handles positive and negative values separately, still avoiding the division instruction (unless when optimizing for size, of course).
cjbgkagh: It was written in assembly so goes through an assembler instead of a compiler.
edflsafoiewq: Examples?
andai: https://en.wikipedia.org/wiki/Nuclear_GandhiFrom what I heard, there was a Civilization game which suffered from an unsigned integer underflow error where Gandhi, whose aggression was set to 0, would become "less aggressive" due to some event in the game, but due to integer underflow, this would cause his aggression to go to 255, causing him to nuke the entire map.The article says this was just an urban legend though. Well, real or not, it's a perfect example of the principle!
Waterluvian: Not really an example that proves any point, but one that comes to mind from a 20-year-old game:World of Warcraft (at least originally) encoded every item as an ID. To keep the database simple and small (given millions of players with many characters with lots of items): if you wanted to permanently enchant your item with an upgrade, that was represented essentially as a whole new item. The item was replaced with a different item (your item + enchant). Represented by a different ID. The ID was essentially a bitmask type thing.This meant that it was baked into the underlying data structures and deep into the core game engine that you could never have more than one enchant at a time. It wasn't like there was a relational table linking what enchants an item in your character's inventory had.The first expansion introduced "gems" which you could socket into items. This was basically 0-4 more enchants per item. The way they handled this was to just lengthen item Ids by a whole bunch to make all that bitmask room.I might have gotten some of this wrong. It's been forever since I read all about these details. For a while I was obsessed with how they implemented WoW given the sheer scale of the game's player base 20 years ago.
luaKmua: Indeed an urban legend. Sid Meier himself debunked in his memoir, which is a pretty great read.
sroerick: I had always heard about how RCT was built in Assembly, and thought it was very impressive.The more I actually started digging into assembly, the more this task seems monumental and impossible.I didn't know there was a fork and I'm excited to look into it
mikkupikku: Macros. Lots of macros.
timschmidt: And presumably generous use of code comments
hcs: [delayed]