1
\$\begingroup\$

I've been reading this article by Factorio about optimisation (please read it to understand the context of this question): https://www.factorio.com/blog/post/fff-176

I have implemented this optimisation and it works very well. But if i have different speeds for the belts connected together, now i don't know how to deal with passing the item on to the next belt that has a different speed without having to iterate each item to check the distances between them.

The article doesn't really go into detail how they pass items across to the next belt especially if the speeds differ.

Does any one know how they did it, or have some ideas how to do it?

Note: items are not singular points they have a radius to them so theres a couple of complex problems:

The first item on the first belt might partially overlap the next belt The last item on the second belt might partially overlap the previous belt

Given this it gets kinda confusing how to actually implement this optimisation when belts have different speeds (and they do support different speeds).

\$\endgroup\$
1
  • \$\begingroup\$ Regardless of the object's "size", presumably it only ever has one belt that "owns" it at a given time? Eg it's either at the very end of belt A or the very start of belt B, never both (even if it appears that way graphically)? \$\endgroup\$
    – Basic
    Commented May 2, 2023 at 8:55

1 Answer 1

5
\$\begingroup\$

Apply the optimization to sequences of belts of the same speed only. When items reach a belt of a different speed, they leave that belt section and enter a different belt section, just like if they pass through a splitter or junction — you'd need to handle the interactions of items moving between different belts (that may or may not be blocked) in those cases, even if you have no speed differences.

I believe this is what Factorio itself does, based on the show-transport-lines debug setting — arrow markers appear at each speed transition.

Screenshot of belt loops in Factorio

Of course, this means that players can defeat the optimization, but that's true of just about anything.

You could treat fast belts as if they were a visual effect that stretches out a segment of slow belt — changing the ratio of "distance on screen" to "distance on belt" but still calculating the belt the same way — but that would not work for fast-to-slow transitions since items may collide with each other at that point. I wouldn't bother.

\$\endgroup\$
2
  • \$\begingroup\$ Hmm i am struggling with the items being transferred to the next belt because the items end up overlapping in some cases - factorio seems to allow them to overlap but i was hoping to prevent that. \$\endgroup\$
    – WDUK
    Commented May 4, 2023 at 0:11
  • \$\begingroup\$ @WDUK The fast belt ends where the speed changes, and then it's a new belt, and you have to transfer items from one belt onto the other belt the slow way, but only when the speed changes and not on every single belt tile so it's still fast \$\endgroup\$ Commented May 5, 2023 at 19:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .