MoreBiters


Adds more variety to biters.

Content
5 years ago
0.16
28
Enemies

b Leech Spitter onDamage performance cost and suggested gameplay change

6 years ago

Hi,

This mod has been amazing. Combined with Rampant AI, I've had one of the most intense MP games of factorio ever. It's the first time I've fully lost an outpost in literally hundreds of hours of playing.

However, late game we started noticing some pretty hefty slowdown when facing bigger waves. At first we figured it was just something that would be unavoidable with so many biters about, but eventually noticed it only occurs when Leech Spitters take damage.

I took a look at the code and noticed that moveLeechDrain() is called every time a leech spitter takes damage. The for loop that runs in it totally kills performance. For a big attack wave, it can go from 60UPS to < 10UPS.

Removing the moveLeechDrain() function call in onDamage totally removes the slowdown.

We also noticed that after the very early game, we never really noticed the spitter leech effects. It was only after taking a look at the code I realised why - the drain entity is always placed on the spitter position - which will almost always be outside of the electricity grid of the factory once you have a wall and turrets up.

So, I made a custom change in an attempt to fix both of these issues:

  • The leech entity is now spawned using the getTunnelPos() function. This will spawn the entity somewhere inside the factory walls, and hopefully somewhere it can do the leeching intended. I think of it more like the leech spitter is using a ranged electrical drain attack.

  • Since we aren't moving the entity to be on the same position as the spitter anymore, deleting and moving it every frame isn't necessary. So I've moved the for loop to destroy the entity into the onDie() function. So now the drain entities created by the spitter will die when it does.

This saves an absolute ton of performance. Most of the time the UPS doesn't budge much from 60, and the lowest we have seen it drop is 45 UPS. And the changes are stable so far, no apparent bugs have arisen from the change.
And, as a bonus, the leech effects are working a lot more regularly - and are pretty potent!

A further small tweak was to roughly double the range on getTunnelPos(), just to make sure drain entities reached inside the walls.

If you're interested I'll upload the changes somewhere.

5 years ago
(updated 5 years ago)

Sure, upload a pastebin and I'd be happy to merge the fix for other players.

Glad to hear you've enjoyed the mod.

5 years ago

Hi, sure here's the control.lua with the change:
https://pastebin.com/TfHAB3bk

It's been awhile since I looked at it, but if I remember rightly I removed the for loop to destroy the drain entities with each hit in moveLeechDrain, and instead just set it to move the position using getTunnelPos. So now you get ranged "drain attacks" which are pretty cool. They use a separate timer (shiftTick2) to the tunnel biters' timer.

When the leech biter dies, the deletion for loop still runs since I couldn't see a better way to do it. This means performance still takes a bit of a hit at times, but far reduced since it isn't happening every time onDamage is called like it was before.

Thanks!

5 years ago

Looks great! I've integrated your changes into the new release. Thanks for this!

5 years ago

No worries, happy to do it. You should know that your changes to the global table cause it to break on loading an older version though. (New games on this version work, but older saves break as soon as a biter tunnels or a leech spitter takes damage. I also imagine the mimic changes might cause it to break too)

I fixed it by adding a small on_configuration_change call like this in control.lua:

script.on_configuration_changed(
function()
game.print("Checking More Biters global vars...")
if (global[PREFIX .. "shiftTick"]==nil) then
global[PREFIX .. "shiftTick"] = 0
end
if (global[PREFIX .. "shiftTick2"]==nil) then
global[PREFIX .. "shiftTick2"] = 0
end
if (global[PREFIX .. "-mimic-counter"]==nil) then
global[PREFIX .. "-mimic-counter"] = 1
end
end
)

New response