Count temp entities

Please post any questions about developing your plugin here. Please use the search function before posting!
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Count temp entities

Postby stonedegg » Sun Jun 21, 2015 7:40 pm

Is there an easy way to count all temporary entities? Basically those that are created during gameplay (player entities, weapons, props, effects, etc).
I know I could use the entity listeners OnEntityCreated and OnEntityDeleted and count manually, but I hoped there is a function in the engine, is there?
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Sun Jun 21, 2015 10:10 pm

I guess there isn't. At least I didn't see any in the API yet.
My Github repositories:

Source.Python: https://github.com/backraw
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Wed Jun 24, 2015 3:37 pm

Anyone else got an idea?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Jun 24, 2015 3:40 pm

Maybe get the entities on LevelInit and then compare that with EntityIter at a later time? I don't really know what you are trying to accomplish by the vagueness of the question. Also, "temp entities" makes it sound like temp_entities, which is not what you are talking about.
Image
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Wed Jun 24, 2015 4:04 pm

I just saw that there was a misunderstanding on my side. I actually meant "entities with associated edicts" (basically all I can create an Entity instance of ?).

Sorry, for the vagueness, I'll explain what my goal is: I'm working on a mod where I place loads of prop_dynamics(_override), along with other entities.

Those entities have a "special" limit which is only 2048, and if I exceed this limit the server just crashes with an engine error instead of preventing the creation or anything.
I also just remembered this article, which shows me the report_entities command. I tried it out, and as far as I understand it, I will only need the edict count in the report.
Is there a way I can get this via my script?


Checking the length of EntityIter() should be a solution (if it does not iterate over non-networed entities), but I'm afraid that this might be too slow as I create entities quite frequently. I hope there is a way to read out the report as that should be way faster.
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Wed Jun 24, 2015 4:29 pm

I doubt parsing the output of report_entities will be faster than using EntityIter(). You could even skip EntityIter() and use EntityGenerator() directly. As you can see it doesn't do very much if you just want to iterate over all entities.

But why do you think that it might be too slow? Did you experience any performance issues? If not I wouldn't search for another approach, because that doesn't make sense.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Jun 24, 2015 4:31 pm

I'm not sure which way would be faster. I don't think len(EntityIter()) would be too costly. Here is what report_entities does internally:
https://github.com/alliedmodders/hl2sdk/blob/sdk2013/game/server/entitylist.cpp#L1570

One issue, though, either way, is that they only account for "player" entities that are already on the server. I don't think you can utilize a possible "player" index with any other entity type. Therefore, you would need to use global_vars.max_clients to know how many client slots to account for.

*Edit: too slow.
Image
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Wed Jun 24, 2015 4:50 pm

You could simply register a OnEntityCreated listener to increase a global count and a OnEntityDeleted listener to decrease it. And reset to 0 on map change. That way you always knows how many has been allocated.
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Wed Jun 24, 2015 7:16 pm

Thanks for the responses!
I haven't tried any method yet because I'm not that far in my code yet, so I was just guessing that EntityIter() might be slower and I want the fastest possible method because in the end I will need to do a lot of stuff every second and even tick.
I think using entity listeners like L'In20Cible suggested would be the best approach then, I will need to use that for other things anyways. But I wasn't too sure if it could "detect" entities without associated edicts, could it? Because I don't want to count those.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Wed Jun 24, 2015 8:14 pm

The entity is manually linked to its edict in the listener and only those allocated at this time are iterated over
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Thu Jun 25, 2015 1:20 am

In fact, you have 2 instance when OnEntityCreated is fired. If the index == INVALID_ENTITY_INDEX and the pointer is valid, the entity is not linkable to an edict instance (the entity is non networkable) and that is the main reason why we added the pointer.
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Thu Jun 25, 2015 10:17 am

That's great, thanks!

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 140 guests