Not to mention, storing them in a map is a HORRIBLE HORRIBL 1000 times over approach.
You may have MILLIONS of entity IDs in the course of a game. You definitely DO NOT want to save them around like that. Just really bad. Don’t do. Can’t stress this enough.
It’s a sign that you misunderstand something about ES somewhere.
I don’t know that it’s the intention but I was giving the benefit of the doubt as to why it would feel necessary to keep the instances around.
It’s not. Just a bad idea.
I use EntityIds in hashmap all the time. I compare them if I’m writing .equals() for components that have EntityIds. That’s probably it. I use .equals() in all cases, though.
I want to attach an entity “effect” to a Spatial, so that when the Spatial collides with another Spatial, I can retrieve the original effect from it and attach a “touching” component; so that I can later retrieve all the “effect”+“touching” entities and process them…
However… I don’t understand why/how is entity retrieved with “new”… it looks like I’m creating a new entity, while I’m actually accessing an “old” one.
But this open a new question: if entities are basically stored forever, there should be some garbage collecting of sort… where is it and how does it work?
garbage collection would be a system which look out for entities marked as garbage with a component. as well here I would have a look at @pspeed s decay system in asteriod panic It is one of my absolut favorit ES like design pattern. No game without a decay system. Bullets? Use decay component to give them a max life time. Explosion? decay after 2-3 seconds.
Since I’ve basically decoupled the Entity creation with the Spatial creation (the spatial gets created after that an Entity has been created), so I create an Entity with a Spatial type (example: a cat), but I also want that particular cat to have a certain behavior, so I need to pass it somehow to the Spatial creation. So my idea was to have a Entity component that encapsulated that behavior… a sort of message passing.
For the same reason, I have a Position component that is useful for spatial creation. But then it is discarded, as the position is then managed by the control (yes, I keep a Position entitity that is totally useless after creation)
I think you give too much responsabilities to your spatials. Remember :
spatial = visual
component = data
system = logic
Imagine that your entity has a component for the model to use, a component for the position, a component for the behavior you described… These components are managed by your systems.
The spatials? They are blind and stupid, updated by systems :
PositionSystem will update the transformation
ModelSystem will update the model, scale, material