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.
code
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.
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...
/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')
Re: Map editor instant deconstruction should raise events
Posted: Mon Feb 05, 2024 10:58 am
by Bilka
DaveMcW wrote:
2. Enter map editor
3. Make sure Settings -> Instant deconstruction is on.
4. Select Tools -> None.
5. Pick up a deconstruction planner and deconstruct something.
Just to make this clear for anyone coming across this thread: The script_raised_destroy event was only added for the case of instant deconstruction via using a deconstruction planner in the map editor, quoted above.
Destroying an entity by using the "entity" tab in the map editor and "mining" it does NOT raise an event by default (as of writing this post). If you want to be notified of an entity being destroyed via the map editor entity tab, register it for the on_entity_destroyed and listen to the event. This event is raised for any kind of entity destruction (once registered for the entity), including but not limited to using the entity tab in the map editor, chunks or surfaces being removed, or just plain old things like a player mining the entity.