Currently, all my game objects are stored in an ArrayList. Each frame, the game loop iterate over this ArrayList and do its work to move/update the entities.
I have been thinking lately... an ArrayList may be affecting performance negatively. The get(Object) and remove(Object) are not constant-time operations. In my game, these two functions are often called. HashMap solves that problem, but gives me a new problem, the order of the elements is beyond your control.
+ Fast to iterate over it
+ Control over the position(index = render priority)
- Slow remove(object) and get(object) functions
+ Constant-time remove(object) and get(object) operations
+ Allows no dublicates
- Slow to iterate through. You have to call values()(every frame, or cache it) which returns a Collection object that you can iterate through
- Unknown order. No way to control render priority.
What should I do?
Edited by P0jahn, 01 June 2013 - 05:46 PM.