I was reading Game Engine Architecture by Jason Gregory
So according to him, I should use an array of entities, and arrays for each property, such as an array
gameObjectsPosition
,gameObjectsHealth
... But in my case, the world is divided in a chunk grid. Each chunk have its own array (or for the moment vector but I plane to change that) of entities (game objects). Then, what should I do? Create a single array containing all entities positions wherever there are (and so one for health, level, orientations, dimensions...), or create the property specific arrays in each chunk?Then how to process these property arrays? I mean, for each dynamic entity, I could update dimensions, sizes and health or I could for each property update each entity. Example:
UpdateWorld() { for each entity in dynamicEntities entity.updatePosition() entity.updateHealth() entity.updateDimensions() entity.updateMesh() } UpdateWorld() { for each entity in dynamicEntities entity.updatePosition() for each entity in dynamicEntities entity.updateHealth() for each entity in dynamicEntities entity.updateDimensions() for each entity in dynamicEntities entity.updateMesh() }
How to handle sizes for each chunk? That'd mean each chunk have an array with
MAX_ENT_PER_CHUNK
(say in my example 1024), and then if a chunk have 24 entities there would be 1000 entities useless. Also, I can't use more than 1024 entities. I could use pointers, but then the CPU cache would hit a lot of misses.How to handle IDs? If I have an array of entities I need to use IDs. I can use macro SID has specified in the book, but the IDs are not ordinals (they may not begin at 0)