-
Notifications
You must be signed in to change notification settings - Fork 20
EntityBag
A bag is a common data structure in ECS world which is, in simple terms, a dynamic array. In Fleks an entity bag is an array that automatically resizes and has no gaps. If you remove an entity then the last entity of the bag gets moved to its location. Therefore, ordering is not granted unless you explicitly call sort
.
Fleks provides an EntityBag
interface and a MutableEntityBag
implementation. A family stores its entities internally also in a MutableEntityBag
which can be accessed via family.entities
.
The EntityBag
provides a lot of common Kotlin collection functionality like iteration, filtering, mapping, association, etc..
Since Fleks 2.11 there is also an EntityBagIterator
class that provides more convenience for iterating (back and forth and also in a loop) over a bag. It can be created via bag.iterator()
. Here is a list of the iterator's functions:
hasNext
-
next
which has aloop
parameter which is set to false per default. If set to true, then the iteration will start from the beginning again, if you are at the end. hasPrevious
-
previous
which also has aloop
parameter similar tonext
reset
-
goToFirst
which will go to the first entity matching the givenpredicate
-
goToLast
which is similar togoToFirst