Page 2 of 2
Re: FPS/UPS drop to <20
Posted: Fri Jan 20, 2017 8:52 am
by Rseding91
Adil wrote:Rseding91 wrote:Adil wrote:On a side note, setting limit=1 in the find_entities_filtered() didn't affect performance, the C++ backend apparently finds and stores all results and only then discards everything above the threshold.
Indeed. Because the filtering allowed (type, force, name) isn't applied until after all of the entities in the given area are collected.
So, this function is just equivalent of using find_entities() and filtering the results yourself? One would hope that the C++ would feature some optimizations over that.
That's exactly what it is. If I feel like it I might re-work it slightly to avoid that if possible but it won't always help.
Re: FPS/UPS drop to <20
Posted: Fri Jan 20, 2017 9:37 am
by Deadly-Bagel
Not sure if the Loot Chest mod is any better processing-wise, it hooks into events so whenever a biter, worm or spawner dies the location is stored in an array and every three seconds it iterates the array and collects any artefacts in a small radius around each death.
It's a global thing so you might feel it a bit cheaty but with Bob's Mods the dozen or so types of artefacts are a pain to collect and quickly fill your inventory so it's handy to just have them teleported to where you would be dumping them anyway. It can however take up to three seconds to pick them up so you do still end up with some in your inventory but meh.
Would it help to have loot stored (or referenced) separately so mods can more efficiently manage it? I know Bob is intending on keeping loot in his mods when he updates for 0.15.
Re: FPS/UPS drop to <20
Posted: Fri Jan 20, 2017 11:13 am
by hoho
Not exactly a fix for collecting the artifacts but how I've solved it is to build a belt outside my defensive walls that brings stuff to my artifact storage area. Sure, it'll still mean that you'll have huge fields of artifacts laying on ground but at least those fields won't expand infinitely since you keep removing items via those belts.
Re: FPS/UPS drop to <20
Posted: Fri Jan 20, 2017 6:46 pm
by SquarelyCircle
hoho wrote:Not exactly a fix for collecting the artifacts but how I've solved it is to build a belt outside my defensive walls that brings stuff to my artifact storage area. Sure, it'll still mean that you'll have huge fields of artifacts laying on ground but at least those fields won't expand infinitely since you keep removing items via those belts.
And with any difficulty mods, spitters usually get enough range that they could kill that belt easily without dying. Not an option if you want those mods.
How about the "Artifact Deconstructor" mod? It doesn't seem to cause much lag (I'll need to verify that), and it seems to be doing a very similar thing. Could we just use whatever it's doing, but instead of having the selected item mark for deconstruction, we put it in the chest?
Re: FPS/UPS drop to <20
Posted: Fri Jan 20, 2017 6:54 pm
by SquarelyCircle
Verifed: Artifact Deconstructor uses .002 -.05 ms of CPU time, which is extremely reasonable compared to the item collectors.
Here is the Entirety of the code for the Artifact Deconstructor (
https://mods.factorio.com/mods/Kane.Nex ... constuctor):
Config.lua
Code: Select all
-- seconds between artifact checks
artifact_polling_delay_secs = 5
-- square radius searched around players (larger = more area = more lag)
search_radius = 100
Control.lua
Code: Select all
require "config"
local artifact_polling_delay = math.max(artifact_polling_delay_secs,1)*60
local function find_all_entities(args)
for _, allPlayers in pairs( game.players ) do
args.area = {{game.players[allPlayers.index].position.x-search_radius, game.players[allPlayers.index].position.y-search_radius}, {game.players[allPlayers.index].position.x+search_radius, game.players[allPlayers.index].position.y+search_radius}}
for _, ent in pairs(game.surfaces[1].find_entities_filtered(args)) do
if game.players[allPlayers.index] and (ent.stack.name == "alien-artifact" or ent.stack.name == "alien-artifact-red" or ent.stack.name == "alien-artifact-orange" or ent.stack.name == "alien-artifact-yellow" or ent.stack.name == "alien-artifact-green" or ent.stack.name == "alien-artifact-blue" or ent.stack.name == "alien-artifact-purple") and not ent.to_be_deconstructed(game.players[allPlayers.index].force) then
ent.order_deconstruction(game.players[allPlayers.index].force)
end
end
end
return
end
local function onTick(event)
if event.tick%artifact_polling_delay == 0 then
-- debug("Find Artifact")
find_all_entities({name="item-on-ground"})
end
end
script.on_event(defines.events.on_tick, onTick)
It's very simple compared to the Item collectors. In part, that's because it doesn't use any sort of item, technology, recipe, or entity. But couldn't the code be shifted from the player to the items without causing too much hassle? And then just, instead of marking for deconstruction, teleport the item to the collector?
Re: FPS/UPS drop to <20
Posted: Fri Jan 20, 2017 8:12 pm
by Adil
Well, if you do that, you'll just get the ItemCollectors mod as it is.
Simply use the fixed version from previous page.
Edit:
Well and change the 8th line in the control.lua to something like:
Re: FPS/UPS drop to <20
Posted: Fri Jan 20, 2017 8:31 pm
by hoho
SquarelyCircle wrote:hoho wrote:Not exactly a fix for collecting the artifacts but how I've solved it is to build a belt outside my defensive walls that brings stuff to my artifact storage area. Sure, it'll still mean that you'll have huge fields of artifacts laying on ground but at least those fields won't expand infinitely since you keep removing items via those belts.
And with any difficulty mods, spitters usually get enough range that they could kill that belt easily without dying. Not an option if you want those mods.
When I had a system like that, I was using a ton of mods that made life harder. E.g all of natural evolution, bob's and some other enemy AI-related thingy (IIRC Misanthrope). I had Bob's sniper turrets as my defensive line with about 3-4 tile gap between them and the belt moving artifacts. Not once did the spitters even attempt to destroy the belts, they were always going straight to turrets.
Re: FPS/UPS drop to <20
Posted: Fri Jan 20, 2017 8:56 pm
by SquarelyCircle
Adil wrote:Well, if you do that, you'll just get the ItemCollectors mod as it is.
Simply use the fixed version from previous page.
Edit:
Well and change the 8th line in the control.lua to something like:
Oh, yup. That did it. Item collector is taking very little CPU time now... like 0.02-0.05. What change optimized it?
Re: FPS/UPS drop to <20
Posted: Sat Jan 21, 2017 9:48 am
by Adil
It didn't optimize, it just made it compute less frequently.
After some thought, that change wasn't as good, it makes them collect a single item in a second.
Here's the modification, that makes the slowest bit of the mod run less often while still picking up items alright.
Maybe some day I'll do a proper release of more performant mod.