Add efficient method for damaging (or killing) LuaEntities from the lua API
Posted: Wed Dec 16, 2020 9:50 pm
TL;DR
Adding a method to the LuaEntity lua API, which can do damage to (or just kill) the entity, without spawning particles/nice graphical effects, for performance reasons.What ?
The current die(),and damage() methods in LuaEntity trigger all the particles and effects associated with the death of that entity. The destroy() method is not intended for standard damage effects, it doesn't create ghosts or leave corpses, and doesn't behave uniformly (destroy the character, and you end up in god mode).I really want an in-between, something which applies normal damage calculations and long-term effects (such as corpses/script triggers), without the short-term overhead of the normal method (e.g. particles). Something like damage_without_particles().
An alternative would be some kind of more aggressive option for particles in the game settings, which means they don't get created at all.
Why ?
I have a mod which adds really huge nuclear weapons with realistic damage calculations, and it runs reasonably well, but the damage scripts slow the game to a crawl, because they kill so many entities, resulting in huge numbers of particles - most of them from trees and enemies. These are spawned miles away from the player, and can't possibly be seen or have any effect on gameplay - most of them are on bits of the map which haven't been charted yet. There are so many of these particles that they can out-of-memory crash the game, and the whole computer (this happened on a computer with 16GB of RAM).To solve this, I made it so that the script calls destroy() on any tree it is going to kill, and spawns a corpse manually. This reduced the performance impact significantly, so the cause of the slowdown is definitely either particles, or something similar.
The current particle options only allow the player to stop the rendering of particles - they are still spawned in, and have CPU and memory costs associated.
This would also allow other wide-area scripts to run faster, when killing large numbers of entities.
The relevant mod is https://mods.factorio.com/mod/True-Nukes.