So I was thinking about how to store the game state for all entities. Let's say we have two properties, position and velocity. If each entity has the same properties we can just store those in flat arrays (I hope my pseudo-code is understandable)
and then if we integrate the positions we can simply do
for ix = 1 to lenth(pos) do
pos[ix] = pos[ix] + vel[ix]
which is also very fast. Now what if not every entity has the velocity property? We only have to update entities that have a velocity, but we also need to know the position of the entity. One straightforward solution would be to assign unique identifiers to the entities and store every property in a map or dictionary,
Map<EntId, Vec3> pos
Map<EntId, Vec3> vel
which could be iterated over similarly,
for each (id, v) in vel do
pos[id] = pos[id] + v
however this is kind of slow (about 100 times slower in my benchmark with 1000 entities). And I think I remember reading something here on the forum where someone gave the advice not to store everything in maps like this.
So I know about these entity component systems, and what I am doing here is actually very similar, but I do not really want to use some kind of framework. I am totally happy with storing the whole game state in global variables. I already have some ideas on how to approach this, but none of them seem really elegant. I would be happy to hear some opinions.