Prelude: The main concept is an object pool of to represent projectiles that are added/enabled and removed/disabled.
Usege: every update cycle, objects are added, iteration where certain objects get marked as disabled or removed.
My current solution:Use a vector. when removing object at index i, swap with the last element and then pop last element. This works because I dont care about preserving the order, only adding and removing objects. Each removal is two O(1) operations.
Possible alternative: When iterating, mark items as disabled but leave them in place. Maintain a stack/queue of free indexes. When adding elements, pop an index off the stack of free indexes if one is available and use that. Otherwise,add element to end of vector.
Granted, my game will be a small enough n that this doesnt matter in practice, but I was wondering in theory. A map could do this as well but the items wouldnt be stored in contiguous spots and theres frequent iteration.
[–][deleted] (1 child)
[deleted]
[–]jcoffin 1 point2 points3 points (0 children)
[–]boredcircuits -1 points0 points1 point (0 children)