Internal implementation of surface.find_entities_filtered

Anything that prevents you from playing the game properly. Do you have issues playing for the game, downloading it or successfully running it on your computer? Let us know here.
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 584
Joined: Tue May 19, 2015 1:56 am
Contact:

Internal implementation of surface.find_entities_filtered

Post by Reika »

Basically, I had assumed that no matter the type or name arguments, the game engine iterated through all entities in the area, and when you supply an entity name or type, each one is compared to that requirement and only added to the list if it matches (similar to how Minecraft does it, code sample below). The salient point being that the number of iterations is always equal to the number of candidate entities. In some cases - such as the case that has caused me to ask this question (~20 biters surrounded by >75k particles) - you may have 90000 entities in an area but only three you care about, yet still need to iterate through all 90000 to find those three.

Is this above assumption correct? And if so, do I have an alternative for finding some select entity types in a very dense field of irrelevant ones (example below)?


Sample (and pseudo-ified) code of the sort of implementation I assumed:

Code: Select all

public void getEntitiesOfTypeWithinAAAB(AxisAlignedBB area, List list, IEntitySelector condition) {
	for (Entity e : this.entityList) { //<-- note the iteration across all entities, not just ones matching the condition
 		if (e.boundingBox.intersectsWith(area) && (condition == null || condition.isEntityApplicable(e))) { // <-- here a null condition is basically no name or type specified
                	list.add(e);
		}
	}
}
Sample entity list in an area. How to efficiently find only the "interactable" (not ghost, particle, etc) ones?

Code: Select all

blood-particle 71597 neutral
item-on-ground 151 neutral
behemoth-biter-corpse 17 neutral
blood-fountain 8 neutral
medium-biter-corpse 26 neutral
big-biter-corpse 85 neutral
big-worm-corpse 5 neutral
small-biter-corpse 25 neutral
small-spitter-corpse 2 neutral
smoke-explosion-particle 4630 neutral
explosion-remnants-particle 160 neutral
orbital-bombardment-crater 8 neutral
biter-spawner-corpse 9 neutral
huge-worm-corpse 4 neutral
spitter-spawner-corpse 2 neutral
big-spitter-corpse 14 neutral
orbital-bombardment-shockwave 3 neutral
orbital-bombardment-explosion 8 neutral
orbital-bombardment-firing-sound 2 neutral
orbital-manual-target-secondary 2 player
dead-grey-trunk 4 neutral
orbital-manual-target-effect 1 neutral
medium-spitter-corpse 3 neutral
Image
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3731
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Internal implementation of surface.find_entities_filtered

Post by DaveMcW »

Have you considered trying not to generate 75000 particles?
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 584
Joined: Tue May 19, 2015 1:56 am
Contact:

Re: Internal implementation of surface.find_entities_filtered

Post by Reika »

DaveMcW wrote:Have you considered trying not to generate 75000 particles?
Most of them are being generated by the game engine, not me. This is not a constructive response.
Image
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5316
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Internal implementation of surface.find_entities_filtered

Post by Klonan »

I couldn't find the exact lines of code,
But sorting through the 75,000 entities in C++ is orders of magnitude quicker than doing it with Lua,

So doing repeated filtered calls for only the entity name or type you want is better than doing a single call and checking the entity name/type in Lua
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 584
Joined: Tue May 19, 2015 1:56 am
Contact:

Re: Internal implementation of surface.find_entities_filtered

Post by Reika »

Klonan wrote:I couldn't find the exact lines of code,
But sorting through the 75,000 entities in C++ is orders of magnitude quicker than doing it with Lua,

So doing repeated filtered calls for only the entity name or type you want is better than doing a single call and checking the entity name/type in Lua
That was the sort of answer I was looking for. Thank you. :)
Image
Rseding91
Factorio Staff
Factorio Staff
Posts: 14824
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Internal implementation of surface.find_entities_filtered

Post by Rseding91 »

Reika wrote:... Is this above assumption correct? ...
Yes. Also what Klonan said.

We have plans to change particles so they aren't entities to fix these exact kinds of scenarios.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Technical Help”