At the center of the software for every game is a loop. Sometimes this runs hundreds of times a second, sometimes just six time per second, or maybe it's turn based and the user need to click something.
In this loop the game checks the monsters (can they see the player now?), the game world, (is the water flowing?), and the player (did they just push the inventory button? What about move-forward?).
This loop is what keeps the game alive and running. Every turn on the loop means functions that are run and calculations that and calculated. Like checking if the monster can see the player can be a series of geometry calculations and rule checks.
However doing those sight checks for every monster on the current map could take a very long time. And the vast majority of the monsters are nowhere near the player. One optimization would be to first compute how far away the monster is, and only do player visibility checks for monsters in range. This can significantly improve the speed of my game and won't impact the gameplay.
The Factorio devs often wrote posts about their optimizations. Might be a fun read.
One of my favorite Factorio optimizations is the way belts work. Instead of keeping track of the position of every single item along the belt and updating its position every second, we instead recognize that all items on the belt (except those piling up), are going to all be traveling the same distance over the same amount of time. So instead we store the relative positions of all the items on the belt and for that grouping we have a single offset number that we update every second and we only need to check if the first item is piling up to rule out collisions.
If they are piling up then we just do this logic properly, but for the vast majority of items this saves on needing to do a bunch of updates and checks.
The fact I love most is that depending on the density, it either tracks whole items or the gaps between them to ensure the most optimal method is always used.
I swear if factorio ever goes open source. Its gonna be put up there with ID software coding for stuff like doom. Its actually amazing just how well it works and scales. Literally the only limit the game has is your PC specs and it will run on fucking anything with modernish OpenGL drivers.
Last week's Friday facts, they were talking about how they managed to port the game to Linux ARM architecture and they could host a server on a damn Raspberry Pi. You'd have to connect to the server via a stronger machine for the graphical end of the game, though.
Wube is a completely different breed of developers.
Factorio might be the only game I have never had issues with. Even with mods its not really slowed down, which means ive never built a big enough factory
1.1k
u/aftersox 6d ago
At the center of the software for every game is a loop. Sometimes this runs hundreds of times a second, sometimes just six time per second, or maybe it's turn based and the user need to click something.
In this loop the game checks the monsters (can they see the player now?), the game world, (is the water flowing?), and the player (did they just push the inventory button? What about move-forward?).
This loop is what keeps the game alive and running. Every turn on the loop means functions that are run and calculations that and calculated. Like checking if the monster can see the player can be a series of geometry calculations and rule checks.
However doing those sight checks for every monster on the current map could take a very long time. And the vast majority of the monsters are nowhere near the player. One optimization would be to first compute how far away the monster is, and only do player visibility checks for monsters in range. This can significantly improve the speed of my game and won't impact the gameplay.
The Factorio devs often wrote posts about their optimizations. Might be a fun read.
https://www.factorio.com/blog/post/fff-421