Re:A Simple Entity Component System (2019)
by samatman on Wednesday August 31, 2022 @07:31PM
(#32669695)
If the system starts ordered and is iterated frequently, and things move (due to deletion) rather less than they are iterated, you can use... bubble sort.
It's basically free to do one stripe of bubble sort while iterating, and for games, you'll iterate everything once or more per frame, but introduce and delete things less.
Re:A Simple Entity Component System (2019)
by contravariant on Thursday September 01, 2022 @06:48AM
(#32674567)
The trick there is to ensure things work nicely if different subsets are iterated one after the other.
Note that merely ordering isn't quite enough, let's say a particular system needs components ABC and component C is rare, then the ideal situation would be to sort A and B such that those entities with component C are close together.
Not that I know an easy way to keep a lists of components that ensure that iterating over them is anywhere close to cache-efficient. Perhaps some kind of self-ordering system would work? (you could for instance move components to consecutive positions as a system uses them, ideally in way that's stable so you don't mess up the ordering of other systems)