Circuit Map Pinger


Adds an item that allows you to ping the map using Circuit Networks

Content
4 years ago
0.17
10
Circuit network

b [Fixed] Ridiculous CPU usage without even placing any Map Pingers

5 years ago

It uses 16ms per tick! This mod alone brings me down to 38 UPS. If you didn't notice this then you must have a supercomputer :o
And I haven't even made any map pinger entities...

So I checked the code.
script.on_event({defines.events.on_tick}
for k,v in pairs(game.surfaces) do
entitiesMPing = game.surfaces[k].find_entities_filtered{name = "Map-Pinger"}

Apparently you are running find_entities_filtered every tick! Over the entire surface! (For every surface!)
It's a notoriously slow function, and you are using it in the worst way possible D: sorry...

You should listen for events when map pingers are constructed/deconstructed on the map and save those entities in a list that you loop through instead. Possibly there could be some events for changes in circuit signals so that you don't even have to do it every tick either.

Check the code of some other circuit entity mods.

5 years ago

good idea, thank you for the suggestion, i already checked for events about the circuit network but i found none, i'm gonna implement these changes that you suggested

and i did not notice this problem myself, i must have a supercomputer then i guess

btw this was also why it ran every 80 seconds in the earlier version, it was to save on performance

5 years ago
(updated 5 years ago)

Btw Creative Mod instant construction/deconstruction doesn't send any events (construction might?) so before you use an entity that you have in a list, check that it is ".valid" and delete it from your list if it isn't. Not making sure an entity is valid has troubled many mod authors before q:

I Ctrl+F:ed in the new source, can't find any checks so I'm assuming it's going to crash for me very soon q:

5 years ago

fml. will update mod now because that is a pretty serous issue.

5 years ago

Oh and you forgot to unlock map pinger if circuit network is already researched when the mod is installed. "Pushbutton" mod did the same thing if you want to check how he fixed it.

5 years ago

working on it, version 17.1.3 should soon be out

4 years ago

(1) Place a map pinger.
(2) /c for k, v in pairs(game.player.surface.find_entities_filtered{name = 'Map-Pinger'}) do v.destroy() end
(3) unit_number isn't accessible when an entity is invalid so you get this:

The mod Circuit Map Pinger caused a non-recoverable error.
Please report this error to the mod author.

Error while running event Circuit-Map-Pinger::on_tick (ID 0)
LuaEntity API call when LuaEntity was invalid.
stack traceback:
Circuit-Map-Pinger/control.lua:27: in function <Circuit-Map-Pinger/control.lua:23>
stack traceback:
[C]: in function 'index'
__Circuit-Map-Pinger
/control.lua:27: in function <Circuit-Map-Pinger/control.lua:23>

I obviously had the same bug in my mod "Artillery Combinator". That's where I found it first. AC 1.0.1 fixes the bug so you can see there how I fixed it. control.lua and the migration files are the relevant parts.

4 years ago

i fixed it now, you can look at line 27 of control.lua to see how i did it (hint i changed entity.unit_number to k)

4 years ago
(updated 4 years ago)

I'm a bit ill atm and my mind is spinning. Apparently, I went loops around the simple fix. At least I have my health to blame for this mistake to reduce my shame.

But you still aren't clearing EntityActivity and continue to leak save file memory.

4 years ago
(updated 4 years ago)

oh, OH NO
quick fix time

Edit: Finished Quick Fix

4 years ago
(updated 4 years ago)

Why do you have the same migration file copy-pasted over and over with different names?

https://lua-api.factorio.com/latest/Migrations.html

4 years ago
(updated 4 years ago)

probably because i'm stupid and didn't read the migration documentation thus making me think migrations work one way when the really don't

4 years ago

Hey I've avoided migration files as much as possible too :)

I checked them just because you said you fixed the save file memory leaks. But you just stopped the leaks. You never pumped the memory that had already leaked before. You should have set global.EntityActivity[x] = nil for all x where the entity that has unit number = x does not exist. And same for EntityList. I don't save EntityActivity in my fork (in part because having less data means easy peasy migrations lol) so I just deleted the whole global.EntityList and rebuilt it with the surface.find_entities_filtered. If you care about each entity retaining their activity then you will have to copy EntityActivity data for every item that you find with find_entities_filtered to a new table and then replace EntityActivity with the new one. Should be easier than explicitly nil:ing individual entries as this paragraph started saying...

Have fun xD

4 years ago

Fixed, why can't i just do things correctly first/second/third time?

4 years ago

Because like this you get 4 times the fun and 4 times as much EXP :D

New response