api changes: ImmutableBag to rename ReadOnlyBag
Closed this issue · 5 comments
or another name but not Immutable. Immutable means it can not change. But In your implementation it can change and it can lead to bug for user. eg :
manager.entities.forEach((e) => manager.remove(e));
with something like :
MyManager {
var _b = new Bag();
ImmutableBag get entities => _b;
remove(E e) => _b.remove(e);
}
(use case : clean stage, ...)
I'm with you on this one but I've got to think about it a bit. Maybe Dart offers something similar by now.
But in case it's not just an example:
- There is a clear()-method in Bag to remove everything from it.
- Removing elements like in you example won't clear the whole bag because the removed Item will be replaced by the last item and the size will decrease by one. Thus only half of the items in the bag will be removed. (EDIT: I just realized, that's probably the bug you were referencing)
Fixed with ceb31c1
I've also thought about making your example possible but I left it as is and added a hint in the documentation that forEach should not be used to modify the structure of the bag.
Bag now offers a method readOnly
which returns a read-only view for the Bag
. ImmutableBag
has been removed and Bag
does not inherit from ReadOnlyBag
. The documentation of ReadOnlyBag
now clearly states that it's only a view of an underlying bag, so now it should be clear that changing the bag will also change the view.
BTW are you currently doing a game with dartemis?
Fine.
I saw the clear() method, but I can't used it. My example was a simplication of the case where I whish to removeAll entities from the world (a reset between each game level). So I planned to iterate over entities and called world.remove, who by side effect remove into Managers,... I currently work around the issue by create new World each time, another workaround was to first collect entities in a List and then remove all.
I currently experiment a rewrite of http://vdrones.appspot.com with dartemis. I hope to be able to add content quicker.
The rewrite is hosted at https://github.com/davidB/vdrones/tree/exp_entitysystem if you wish to take a look.
And may be use dartemis for April's LD (my first try).
Hmm, it should be possible to add some kind of reset functionality to the world to remove all entities. I'll look into it tomorrow.
Added a deleteAllEntities
function to World
(8e1badd). This should do what you want to achieve.
Good luck for the LD, I'll try do a game for it too.