bsimser / artemis-framework

Artemis is a high performance Entity System framework for games.
MIT License
2 stars 0 forks source link

Bug in Bag size with set and remove #6

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
If gaps are left in a Bag when setting items, the size method stops being 
reliable. For example:

Bag b = new Bag();
b.set(5,new Object());
b.remove(5);
assert b.isEmpty();

will throw an AssersionException because the size of the bag is considered to 
be 6 after setting an item at index 5, and 5 after removing that item.

Original issue reported on code.google.com by pirh.bad...@gmail.com on 8 Nov 2012 at 9:43

GoogleCodeExporter commented 8 years ago
I don't think the Bag is for general use. It appears that the index is heavily 
tied to Entity#getId() and ComponentType#getIndex().
Or in other words, if you do want to use Bag you will have to keep track of 
your own indices.

Original comment by seraphim...@gmail.com on 12 Nov 2012 at 9:06

GoogleCodeExporter commented 8 years ago
If you really want to discourage the use of Bag as anything other than a 
read-only container you could move it from com.artemis.utils to com.artemis and 
make #set a package private method (either 'protected' or the default modifier).

Original comment by seraphim...@gmail.com on 12 Nov 2012 at 9:13