Alright, So I am now programming the entity and components. I know what the general Idea of it is.
A number of entities in an array.
And components are stored in some form of way.
The entities are just simply structs with set data in them, as in...
BaseID: Assuming the engine wants to instance from a database. Or in the case that this would matter some way.
UID: The instanced ID.
And that's pretty much it for entity.
The part that confuses me... are components.
Confusion 1:
Lets say some arbitrary component had been defined some form... some way. It has a system that processes it when the time comes. I got that much.
What confuses me though is how do you store the component in an efficient way? My understanding of the entity-component system is that it simplify things, and reduces cache misses, right?
So far... from what I can gather from studying Artemis is that the components are stored in maps. Aren't hash tables less efficient for the cache? Given that it's normally scattered around the memory?
For simplicity sake, I can see it working in a loop. You simply pass the entity's ID into the map, and the managers will process information.
I guess the next one is an array for storing components... but I see problems here.
Confusion 2:
Say components are stored in arrays... like I have been noticing on every other forum I searched. Don't these positions change frequently as your code updates things?
I.E. When a player shoots a ship, and the ship is now dead. It should be removed. So it's flagged as such, and at the end of the loop, it gets removed from the list, and everything gets shifted down to keep data clustered tightly.
For a game with everything having every single component. I can see this being ok, unless threading says no. But what about every entity having only components it needs? Static geometry only containing physics, position, model, and material. While an AI Agent would need, update, position, model, and material?
That would mean that everything in the array suddenly gets whack. And you got a wall that is able to shoot for some reason. (Yes... that happened)
Right? But what about storing them with the Entity?
Confusion 3:
An array will not conform very well with this. As the array will only hold a predictable amount of data. So that's out of the bag. Lets say we do use std::list<> then.
If memory serves correctly, that is actually a linked list. Which would be entirely counter productive when you are trying to keep the amount of needed pointers down in the code. Not to mention memory is still scattered around.
Does anyone have any advice?