Quillraven / Fleks

Fast, lightweight, multi-platform entity component system in Kotlin
MIT License
174 stars 19 forks source link

I Need a SortedMutableEntityBag #156

Open AnderWoche opened 2 weeks ago

AnderWoche commented 2 weeks ago

Lets make MutableEntityBag open so i can override it and make my SortedMutableEntityBag

Important is how entities are delete: i need this way:

i want to override minusAssign

operator fun minusAssign(entity: Entity) {
        for (i in 0 until size) {
            if (values[i] == entity) {
                size--
                System.arraycopy(values, i + 1, values, i, size - i)
                values[size] = Entity.NONE
                return
            }
        }
    }
Quillraven commented 2 weeks ago

Hi, I don't have time for this at the moment but feel free to open a PR for it. Making the bag open will not do any harm 😉

What exactly is your entity removal doing? Doing an array copy every time you remove an entity feels highly inefficient?

AnderWoche commented 2 weeks ago

I implemented it this way because I needed the same behavior as with an arrayList.

I didn't use a normal ArrayList because I wanted to use the EntityBag interface so that I could use the entities from the families without having to do any conversions beforehand.

I will sit down and try to make a pull request.

AnderWoche commented 2 weeks ago

I have a small question, Why is everything in just one file? Is it more performant?

would it be bad if I put MutableEntityBag in an extra file?

Ohh .wait....

Quillraven commented 2 weeks ago

I don't think that this has anything to do with performance. It is just my personal preference that I group things that belong together in one file. However, if a file gets to big I split it up like I did it recently with world and world configuration if I remember correctly.

But feel free to extract the interface into a separate file. It has a lot of methods and might be better to move it into a separate file.

Btw, if you have time, can you also add the single() method please? I just discovered that method a few days ago and it is a cleaner version of first in some scenarios.