Hello,
What is the proper way to find a single entity based on component values within a view ? At the moment I iterate through the whole view, compare the component values with the values I am looking for and break once I find the entity, is there a better way to do this ?
Thanks,
Max
If you want to find an entity based on a value, there is no other way than to look for it explicitly.
However, this smells of XY-problem 90% of the times. What are you trying to do exactly?
Over the network the server will tell clients that a player with a specific id (and the server and client entities have different ids) is changing to another world location, so I have to look for the player with the specific id to change the world location component of this entity.
Do you have a map to store remote/local ids or do you store the remote one in a component attached to the local entity?
I store the remote one in a component, I assumed it would be pattern breaking to have a map associating remote ids to local ids, wouldn't it ?
ECS is good at code organization but not because you've a hammer then everything is a nail. :)
It's common to have external data structures when needed. Imagine a proximity search, you cannot beat something like a quad- or oct-tree with whatever you invent in terms of components.
Your case is another one where a side data structure just helps to get the job done in an easy way and no, it doesn't break any pattern.
I personally use this approach to bind remote/local ids, it's better than searching through the components for a runtime value, because you cannot optimize much in the latter case. Unless you've less than 50 entities or so with a remote counterpart, the performance of a look up in a map will beat a linear search no matter what. :+1:
Thanks for the clarification and keep up the good work we are loving your library !
@yamashi define _we_. :)
I mean, are you using it in real world projects?
I'm always interested in knowing new users and new projects based on EnTT.
Also, if you love it, do not forget to star it! This will help to let other users know that it's worth giving a try. :wink:
We as "Tilted Phoques" a company that makes mods for existing single player games to make them multiplayer, you may know our mod Skyrim Together that we are currently rewriting and are using entt this time and we are also working on other games that we haven't announced yet :)
@yamashi this is... unexpected but really appreciated!! :heart_eyes:
Count on me if you've any question, it would be great if you get it up and running!!
Thank you very much for choosing EnTT!
May I ask you to ping me if you'll ever release something based on this library?
There is a section in the wiki that is dedicated to this kind of things and I use to put some of the examples in the README file too.
It goes without saying that I'd love to put there something from Tilted Phoques, if it's fine for you.
As far as I can see, you don't make a secret of using EnTT. :wink:
Also, I was discussing the issue in the gitter channel (I also invite you to join if you have other questions).
As @vblanco20-1 commented, in your specific case probably a brute force approach is the fastest anyway because the number or players is low. This way you also avoid allocating a map. :+1:
Most helpful comment
ECS is good at code organization but not because you've a hammer then everything is a nail. :)
It's common to have external data structures when needed. Imagine a proximity search, you cannot beat something like a quad- or oct-tree with whatever you invent in terms of components.
Your case is another one where a side data structure just helps to get the job done in an easy way and no, it doesn't break any pattern.
I personally use this approach to bind remote/local ids, it's better than searching through the components for a runtime value, because you cannot optimize much in the latter case. Unless you've less than 50 entities or so with a remote counterpart, the performance of a look up in a map will beat a linear search no matter what. :+1: