Starting with noob one
In simple tutorials in zay-es github wiki (written by @ia97lies [Christian thanks for tutorial ]) , I can see there is no setter method for components to change fields value, instead new component was created and overwrote the existing component. Which can impact on GC. Any reason for this ?
next one Systems contacting with each others
ex: System A wants to tell system B (position system) to change position of an entity
Can system A call method from B directly ? (Seems very bad also will couple systems to each other and also will prevent multi threading)
Does system A need to update position component on entity and system B will detect this change by checking position components on all entities in it’s infinite loop (It is not event driven but polling pattern)
Or I need to have an event driven messaging system so systems can register there and contact with sending messages and each system can listen to specific message types. So systems without knowing each other can contact with each other (Like using Gdx-AI Telegraph library)
But problem with this approach is, after system B updated position then System A needs to know that position is updated then decides to move spatial to new position. So problem is how A will know that position for that specific entity is updated ?
System A should continuously check position on all entities to see if position is changed or not and continuously checking is an overload and not Event Driven approach.
There are several fundamental misunderstandings here.
One system sets a new component on an entity. Other systems detect that the component has changed. This is one of the reasons components are immutable… you swap them out and then the ES knows that it is new… and your other systems can see that, too. (It also makes it all thread safe, by the way.)
You can set things on a component directly if you want to but then you have to manage your own polling, your own multithreading, etc… might as well just go back to crappy non-ES-code. (There are some extremely narrow use-cases where this sort of thing may be necessary but mostly just use the ES like it was meant to be used.)
The rest of your post I’m not sure about… generally one system sets a component and the rest use it. If you have multiple systems setting a component then something is wrong with the design, either the systems or the components.
Okaaaaaaay got that , thanks for making it clear
one question, if instead of creating new component i just modify current one and reset it on entity, will ES yet know that it is changed ?
(the reason i want to modify instead on create new one is to prevent from garbage creation )
I have pathfinding system and cinematic motion control (group control) system which both can set position component on my entity (but not in same time) is this really wrong ???
One more question came to me and it is how should i use JME’s built in controls in my ES.
So for example i have an AnimationSystem which is very simple for now and it plays animation on entities. It needs to access to AnimControl of each entity to be able to play animation on it.
So what is the best way to access it in AnimationSystem.
Approach one : Give a HashMap<EntityId,AnimControl> animControls to system’s constructor so it has access to all AnimControls or maybe give it HashMap<EntityId,Spatial> spatials; so system can access to any built in controls it needs.
Approach two : Make those controls available to system in form of Components. So for example i create a AnimationControlComponent which implements EntityComponent and make a field references to AnimControl then add this component to entity so my AnimationSystem can access to it. (This one seems to be a bad practice)
Approach three : Please suggest if you have better one
Components should not contain things that “DO” stuff. That’s absolutely totally wrong. Components are data only. Just data. No doers.
Most of your view level systems will already have some kind of map to track the view objects that they are creating. You can see this even in SiO2’s EntityContainer utility class. (which by the way is a super convenient way to manage this sort of thing).
Your code is really clean and good documented and easy to understand and a good place to learn. I do like how you are managing stuffs.
Just wanted to thank you for sharing them.
I am having good times with Zay-ES.
A noob question
Can i have empty components (have no fields) ? Is it OK with ES design ?
example : Adding empty Keyboard component to any entities which want to be notified when a key is pressed. Notification is done by adding KeyAction component which has info of pressed key to all entities which have Keyboard component .