Page 1 of 1

Internal implementation of surface.find_entities_filtered

Posted: Wed Aug 30, 2017 6:03 pm
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

Re: Internal implementation of surface.find_entities_filtered

Posted: Thu Aug 31, 2017 2:28 pm
by DaveMcW
Have you considered trying not to generate 75000 particles?

Re: Internal implementation of surface.find_entities_filtered

Posted: Thu Aug 31, 2017 5:57 pm
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.

Re: Internal implementation of surface.find_entities_filtered

Posted: Thu Aug 31, 2017 9:19 pm
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

Re: Internal implementation of surface.find_entities_filtered

Posted: Thu Aug 31, 2017 10:48 pm
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. :)

Re: Internal implementation of surface.find_entities_filtered

Posted: Thu Aug 31, 2017 10:54 pm
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.