In my 2d block-based game I'm trying to implement a data structure that would store entities entities in a way that's capable of:
Direct selection based on coordinate.
Iteration limited to an area
I thought of these solutions:
For 1,3 I thought that a 2 dimensional array of entities' coordinates would be suitable but I already have a 2 dimensional array of blocks' coordinates and don't want to have another one too. And this solution is not suitable with 2, there will be too many gaps when iterating the array and this is a performance loss.
The next solution I thought was simply using an array and adding new entitys simply by arr[length], this is performance wise for 2 but it is hard to perform 1 and 3 (use a for loop everytime to check if I'm colliding with an entity (duh)).
The last solution is simply adding entity data to my (already exists) blockList 2 dimensional array, this one has nearly the same pros and cons with first solution.
And there is always the alternative of using first and second solutions together by making them refer to the same object.
Which one of these solutions should I use, cause all of them have their pros and cons and I have to something uses less space, cause the game map is not fixed.