I am trying to create an array of pointers that can point to another array that stores addresses to array indexes where the arrays in question are many different types.
I am trying to create entities that can have components added to them. These components are nothing more than indices in an array which are stored in structures. I want to be able to allocate these component structure of arrays dynamically, and so, I can't just use the entity ID to lookup the entry I want... perhaps I making this more difficult than it needs to be. :/
I would appreciate any useful suggestions to make this simpler than the complicated mess I have thought up. :)
This is what I have so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | typedef struct { uint32* x; uint32* y; uint32* z; } Positions; Positions* allocate_positions_array(uint32 amount) { Positions* positions = malloc(amount * sizeof(Positions)); return positions; } void free_positions_array(Positions* table) { free(&table); table = NULL; } void add_position_component(uint32 entity_id, Positions* positions, uint32 px, uint32 py, uint32 pz) { uint32 array_size = sizeof(*positions) / sizeof(positions); for(uint32 iter = 0; iter < array_size; iter++) { if(positions->x[iter] == 0) { positions->x[iter] = px; positions->y[iter] = py; positions->z[iter] = pz; } } } |