System on a set of components in 5.4

#1
Hi,

I am thinking about the best way to add a new pure system to cryengine without touching the core. Say I want to implement my own AI system. I create a Vision Component and an Intelligence Component. Now before every physics update I want my system to get called for update. And in that update function I want to grab a set of entities having either the vision or the intelligence component or both and perform AI logic on only those entities. I do not want to iterate over potentially millions of entities to find this subset.

I was reading through the source code and could not find anything containing a map of component types.

I did find IEntitySystemSink which will notify me when entities are spawned, but there's no guarantee an entity will have all its final components already added at spawn.

Any suggestions how this would be done in CryENGINE?

Re: System on a set of components in 5.4

#3
I want to keep the logic separate from the components, typical of the Entity-Component-System methodology.

Entities will be spawned dynamically and possibly have components being added and removed dynamically.

So the question is how I can make a separate system that operates on all entities of interest. Maybe AI was a bad example. Say I want to add support for a third party physics engine and I create a NewRigidBody component. I want to send all entities having this component to be processed every frame in the physics engine system

Like I said separating the logic into a "system" is typical and has great advantages in terms of performance. Having all my entities listen for the update event and pass that on to their child components involves much overhead including just the function call overhead which is often a hidden bottleneck in high performance games. By doing the logic in a system instead, on a defined subset of components, it is also possible to do batch processing on GPU:s and much more that isn't reasonable with a basic system iterating and calling update on all entities.

After a little more digging I guess I could use the component's Initialize function to register them in my own System, and then use the IEntitySystemSink to check and unregister entities that get removed. Also I will need to make sure to get notified if the component is being removed from the entity. A bit cumbersome so I am still wondering if there's an easier way to just hook a system into cryengine and work with component subsets.

Re: System on a set of components in 5.4

#4
you could just reference the system in component using singleton patern. you can enable or disable it. remove or add component is tedious.

create a singlton with c++ vector member.
write some initialisation about singlton in your component.
write update in your component.
write deinitialisation in your component.

some code such as add self to singlton vector.
remove self from singleton .
active self from singleton.

Re: System on a set of components in 5.4

#5
I'm sorry but I don't think you understand the depth of my question as your answer is very general. I am not asking how to write a singleton registry to solve my problem, that is a trivial issue. I am asking if there's another recommended pattern or engine features I should be using. I think it is best if someone at crytek answers my question since 5.4 and the entity component system is very new.

Does CryENGINE provide a "plugin"-kind of way of integrating new systems and working with groups of components?

If not, is there a recommended pattern when it comes to keeping track of components so that I can work on them in batches?

Ideally, I would like to easily register my system with the engine and let the engine know which components or other features I am interested in. The engine would keep track of when entities/components of interest are added to the world and merely provide me with a set every time my system's update method is called.

Alternatively, I would like an easy way of hooking up to the component add/remove globally and keep track of entities of interest myself. Please note here that the primary "issue" is the relationship between components and entities in 5.4, as keeping track of entities would be very easy using IEntitySystemSink, but components is another issue.

Re: System on a set of components in 5.4

#9
sdac wrote:Like I said separating the logic into a "system" is typical and has great advantages in terms of performance. Having all my entities listen for the update event and pass that on to their child components involves much overhead including just the function call overhead which is often a hidden bottleneck in high performance games. By doing the logic in a system instead, on a defined subset of components, it is also possible to do batch processing on GPU:s and much more that isn't reasonable with a basic system iterating and calling update on all entities.

From what I understand you want some way to get all entities that have a specific component type and update those components in some efficient (GPU? Parallelized execution?) manner.

Generally for batch processing, you need agnostic data, data that doesn't rely on other data that exists within itself.
If you batch process AI data for example, how would you layout that data to be batch processed? How would one AI entity know about the other AI entity during a batched operation using all the entities?
Same for physics, or any system that an "entity" uses. You can't use some generic processing on each entity without completely ignoring all other entities.

If you check the cryphysics interface you see it is all dynamic, just an entity should be, something that can change over time, individual of other entities. you will see the physical entity types all have some "Step()" method, These need to be aware of each other, usually operated in an iterative fashion so the results of the change of one entity can affect other entities.

I think you need to determine exactly what data you need to deal with, then you can decide the most efficient manipulation of that data and how to properly handle state propagation to desired entities (if entities are even an appropriate solution to your problem).

hope this helps,

Maybe if you an give a concrete idea someone can give some concrete solutions :)
Uniflare
CRYENGINE Community Coordinator
Here to help the community and social channels grow and thrive.

My personal belongings;
Beginner Guides | My GitHub | Splash Plugin

Re: System on a set of components in 5.4

#10
Well now I regret that I even asked this question because none of you seem to understand what a system in an entity component system is nor understand the various advantages of efficiently performing updates on large amounts of data without computational overhead.

Questioning if batch processing even has any advantages, getting hung up on AI and physics hypothetical examples, and even getting hung up on cryengine's entity limits is on a ridiculously off topic level. I am not interested in your opinions on these matters and have clearly restated my questions several times.

It doesn't matter now because I have found a pattern that works for doing this and unless someone has any suggestions I will stuck to it.

Who is online

Users browsing this forum: No registered users and 2 guests