Well, then why don't you try to throw more arguments at your original thread instead of leaking into this one? If i was a moderator i'd have merged them back already :p.Raiguard wrote: Wed Aug 28, 2019 7:15 pm I already tried requesting this capability separately, Rseding shot me down quicker than a drone flying over Area 51, similar to how this thread was immediately dismissed at first.
code
I've added cases for trains/proxies and still don't see any performance problems with my implementation (<2 seconds), or yours (~3 seconds). Reviving 50k+ entities isn't free no matter how you do it. And btw, /editor mode does *not* revive trains in blueprints, so that's a bonus demand you're making (unless it gets "fixed" in base ;p). So if you're still saying things are too slow you'll need to provide an example blueprint/savegame and performance data for comparision...Raiguard wrote: Wed Aug 28, 2019 7:15 pm And the performance problems are real, your implementation doesn't take into account edge cases like trains on rails or item request proxies. Try installing Infinity Mode and place down an enormous blueprint, you'll see the lag.
Code: Select all
/c
local is_ghost = {['entity-ghost'] = true, ['tile-ghost']=true}
local is_tile = {['tile-ghost'] = true}
local is_train = {['locomotive'] = true, ['cargo-wagon'] = true, ['fluid-wagon'] = true, ['artillery-wagon'] = true}
local is_rail = {['straight-rail'] = true, ['curved-rail'] = true}
local opts = {raise_revive=true,return_item_request_proxy=true}
local trains = nil
local function revive (node)
return function (event)
local this = event[node]
if not is_ghost[this.name] then return end
local is_tile = is_tile[this.type]
local status, entity, proxy = event[node].silent_revive(opts)
if is_tile then return end
--[[delay trains]]
if not status then
if is_train[this.ghost_type] then
if (not trains) or (trains.tick ~= event.tick) then
trains = {tick = event.tick, [1] = this}
else
trains[#trains+1] = this
end
end
--[[can we spawn a wagon/loco now?]]
elseif trains then
if (trains.tick ~= event.tick) then
trains = nil
elseif is_rail[entity.type] then
for i=#trains,1,-1 do
if trains[i].valid then
status, entity, proxy = trains[i].silent_revive(opts)
if status then
table.remove(trains,i)
if #trains == 0 then trains = nil end
break --[[assmume max one train part per rail]]
end
else
error('another mod is instantly destroying ghosts')
end
end
end
end
--[[fullfill proxy]]
if proxy then
local target = entity.get_module_inventory() or entity
for item_name,count in pairs(proxy.item_requests) do
target.insert{name=item_name,count=count}
end
proxy.destroy()
end
end
end
script.on_event(
{defines.events.on_built_entity,defines.events.on_robot_built_entity},
revive'created_entity')
script.on_event(
{defines.events.on_player_built_tile,defines.events.on_robot_built_tile},
revive'tile')