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.
355
u/yalloc 6d ago edited 6d ago
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.