HawYeah
If I understand this correctly, you have (in my case) the positions stored in special entity and whenever i want to do a update, i loop over these special entities, update the positions, and then write it out to the entities
When you update positions, I guess you update ALL livinig and moveable entitys positions. For that, lets make a moveable entity.
struct entity
{
//Stuff ALL entitys use. Like pos.
};
struct moveable
{
entity* e;
//Things like speed, acceleration, turning speed, breaks
};
struct special_entity_that_can_move_and_other_stuff
{
//Special stuff
moveable* move;
};
entity e[maxNumberOfEntitys];
moveable* moveAbleUnits = malloc/realloc/calloc(AS_MANY_AS_NEEDED);
special_entity_that_can_move_and_other_stuff special;
special.move = &moveAvleUnits[some_free_e];
Now my unit has: special->move and special->move->e
With indices you just change pointers to ints. Like this:
struct entity
{
//Stuff ALL entitys use. Like pos.
};
struct moveable
{
int myEntity;
//Things like speed, acceleration, turning speed, breaks
};
struct special_entity_that_can_move_and_other_stuff
{
//Special stuff
int myMoveable;
};
entity e[maxNumberOfEntitys];
moveable* moveAbleUnits = malloc/realloc/calloc(AS_MANY_AS_NEEDED);
special_entity_that_can_move_and_other_stuff special;
special.myMoveable = some_free_positon_in_moveable_units;
moveable[special.myMoveable].entity = some_free_entity;
Personally I often find this system to get a bit more complex, i like my pointers :D But if you want ALOT of entitys and memory is an issue, then maybe you should concider this.
About dead entitys. Just have the system check for a specific value, you dont even need a dead-flag. Like, if positionX is -1 (impossible position) then the unit is dead. Then ignore it in for example the moveAllStuff function. When its time to make a new unit, then loop and check for a unit with -1 position, and use that.
Structure the data in ways that you use it. You probobly have a function to move ALL moveable entitys, then send in "moveable" to that, while the render function probobly need "e" instead.
Im sorry if I write confusing, this is kinda complex stuff :)