Sry for bringing back an old topic, but I am redoing my game engine and I am facing the same problem… Last time I just created a copy as an actual array and iterated through that but that isn’t really efficient…
This is the criteria (kind of):
- looping through all elements only once (no more, no less)
- be able to remove any element at random without knowing about it (not just the current one, an entity might remove another entity)
- hopefully not memory or CPU intensive and any objects are reusable…
Is this possible? I guess if needed, I can kind of find out when an element is removed and which one… I do have a method the developer uses to remove an entity (as they dont have access to the actual arraylist)